头图

This article mainly introduces the application development of enterprise WeChat, how to deploy and go online with the help of cloud hosting in an efficient and low-cost way, and compares the difference between cloud hosting and traditional development methods.

WeChat cloud hosting official website

https://cloud.weixin.qq.com/cloudrun

1. Summary of cloud hosting project practice

In 2019, Enterprise WeChat 3.0 was launched. As of today, Enterprise WeChat is an indispensable enterprise information management platform for enterprises, including customer relationship, company organizational structure, enterprise management, SCRM, OA daily office, etc., the strongest The big one is the open platform of enterprise WeChat, which provides a series of API interfaces for development by enterprises and service providers.

图片

Although there are complete development documents, for enterprise access, the threshold and cost are still quite high. The traditional access method requires the purchase of a cloud server first. The parameters should consider bandwidth, CPU memory configuration, and computing. The free way... , with cloud hosting, it's made easy.

图片

1. Out of the box

As shown on the official website, it can be used out of the box, which is a great boon for enterprises and developers. It can be directly registered and opened, which is very practical. It is embodied in: the test domain name provided by the official, deploying a service online, cloud Hosting will automatically generate a domain name. With this domain name, you can access our services on the public network for development and testing. Students who have done back-end development should be very clear. This greatly facilitates the back-end testing work. No public IP, no domain name can Take a test visit.

图片

Enter the domain name generated by cloud hosting on the homepage of the enterprise WeChat application for development and testing.

图片

In addition, the back-end development languages are also widely supported, including Java, PHP, Node.js, Python, and Go. The mainstream back-end development languages are basically supported. The example in this article uses Node.js.

2. Low cost

The low cost is reflected in two aspects: one is the development side, out-of-the-box, lowering the development threshold, saving time and R&D cost investment; on the other hand, WeChat cloud hosting adopts a pay-as-you-go billing method, and there are a variety of traffic packages to choose from. Enterprises can combine their purchases with their own circumstances, which is very cost-effective.

3. Elastic expansion

This is the most worth mentioning point. Elastic scaling greatly reduces the difficulty of back-end concurrent design. If the service requires concurrent access, the back-end concurrency performance cannot be ignored. From server configuration to bandwidth, to technical architecture, any If a place is not considered carefully, it will become the bottleneck of the system. Cloud hosting elastic scaling can fundamentally solve this problem. Service instances can be scaled horizontally, and instances can be automatically increased or decreased according to resource consumption to cope with sudden access. quantity. There is no need to worry about the lack of concurrency capability, which will lead to system downtime. In this regard, you can indeed devote more energy to business implementation.

2. Case project introduction

This project is based on an enterprise WeChat application + a web application, including front-end and back-end. The front-end technology stack is react, and the back-end is nodejs. The goal of the project is to deploy the back-end to cloud hosting and conduct release testing.

1. Code Docker package

There are mainly two configuration files, one is Dockerfile and the other is container.config.json, where the latter belongs to basic configuration, such as setting trigger conditions for expansion and contraction.

图片

Dockerfile mainly specifies images, directories, startup parameters and external ports:

图片

container.config.json configures expansion trigger conditions

图片

构建目录  "buildDir": "",
最小实例数 "minNum": 0,
最大实例数 "maxNum": 50,
cpu 核数 "cpu": 0.25,
内存大小,单位:G "mem": 0.5,
扩缩容指标类型 "policyType": "cpu",
扩缩容指标阈值 "policyThreshold": 60,
环境变量 "envParams": {},
日志采集路径 "customLogs": "stdout",
启动检测延迟  "initialDelaySeconds": 2

The main parameters are explained, cpu mem represents a step unit, how much is the increase or decrease of a unit, policyThreshold represents the trigger condition, when the CPU or memory usage exceeds 60%, the expansion is started, and the expansion speed is very fast. Fast, it can achieve second-level expansion, and this delay is sufficient for general concurrent access.

After completing these two configuration files, the code Docker packaging is completed.

2. Upload the package code to cloud hosting

Execute in the code directory, and use the zip command to package the code.

zip -r -q backend.zip -x ./node_modules/*

Go to the cloud hosting console:

图片

图片

Select the local upload and compression package, configure the port, and click [New] to start creating a new version.

图片

On the right side of the console, you can view the real-time deployment log. If you see Successfully built .... in the above figure, it means the deployment is successful.

The next step is to release the online process.

图片

Select the generated version from the list. There are two ways to release it, one is full volume, and the other is grayscale. If it is a small program, you can use grayscale testing and add a whitelist to release it in grayscale. I am a web application here. It does not support the grayscale of enterprise WeChat, so I directly publish it in full. I hope that cloud hosting can support the grayscale publishing of enterprise WeChat in the future. At this point, the cloud hosting service is deployed to the release.

3. Other aspects

Cloud hosting logs and service monitoring are complete, which is very convenient for our daily operation and maintenance management work, and to check the operation of our services.

图片

The log can see the service startup status, print out our log information, (user log information is pink)

图片

In the monitoring, you can check the QPS response time of the service, etc., which saves you the trouble of building it yourself.

4. Other project experience

In actual development, our system is also applied to other services, and some modules required by the business need to be installed, such as non-mainstream databases, etc., so that part is stripped off and left on the traditional server, and the cloud is hosted on the cloud to access these services. In addition, we have also developed some small and micro modules into cloud functions and put them into cloud development, realizing the intercommunication between cloud hosting and cloud functions, which can make the architecture more flexible and take advantage of the respective advantages of cloud development and cloud hosting. These details will not be repeated one by one. All cloud development and cloud hosting do bring a lot of convenience to development. Making good use of cloud development greatly reduces the threshold and cost of research and development, and enterprises and research and development can pay more attention to business realization.

图片

The complexity of the changed architecture is reduced, and it is no longer necessary to consider the access layer (gateway and load deployment nginx). In the past, only a team with a strong technical background could do well, but today it has become much simpler. I hope Tencent Cloud development and cloud hosting teams can bring us more surprises!

Author: Song Yantao, cloud development evangelist.


CloudBase云开发
425 声望438 粉丝

云开发(Tencent CloudBase,TCB)是云端一体化的后端云服务 ,采用 serverless 架构,免去了移动应用构建中繁琐的服务器搭建和运维。同时云开发提供的静态托管、命令行工具(CLI)、Flutter SDK 等能力极大的降...