In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Building SpringCloudStream-based message-driven microservices is used to deal with the solution for third-party developers to accept a large number of pushed messages from Wechat. I believe that many inexperienced people are at a loss about this. Therefore, this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
The reason for this is that when using the Wechat official account service, as a third-party service provider, Tencent will push all kinds of business messages to the servers of third-party developers, while the previous solution is that messages go directly into the service. When using some businesses, such as issuing coupons, the Tencent server will send a large number of messages to developers, because the processing capacity of the message service is limited. Especially during peak times, the message request will be pressed directly onto the service, resulting in busy service threads. At this time, a large number of service timeouts will be reported, triggering the Wechat service alarm, and the service is unavailable or timeout. At this time, the message service in the official account will no longer be able to provide services to users. In view of this problem, we reorganize and construct Spring Cloud Stream-based message-driven microservices.
We use the Spring Cloud Finchley.SR2,Spring Boot 2.0.6.RELEASE version to develop, the preliminary design idea of the system is to use the
Message queue rabbitmq is used to decouple the service to ease the pressure on the message directly to the service. Instead of connecting mq directly to the service, we use Spring Cloud Stream. To put it simply, Spring Cloud Stream is a framework for building message-driven micro-service applications, further abstracts the processing operations of message integration, realizes more simplified message processing, and can use different proxy middleware. It abstracts some concepts of event-driven. For the further encapsulation of message middleware, it can achieve no perception of middleware at the code level, and even dynamically switch middleware and switch topic. Micro-service development is highly decoupled, and services can pay more attention to their own business processes.
Some of the basic concepts of Spring Cloud Stream can be searched on its own. I don't describe it too much here. The following is just about the specific solution and configuration method and the problems encountered.
The basic structure is a very simple message subscription and publishing model.
At this point, the basic structure of the whole message processing is described. Of course, in the actual development process, asynchronous processing and multithreading of messages should also be considered. Here, we will not describe it in detail. We need to implement the corresponding development according to our own business needs.
There are a few points to pay attention to:
The @ StreamListener (ReceiveInputChannel.MSG_RECEIVER) method can only be placed in the class started by the Application service. If you put it somewhere else, it will report an error: Disp org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers, which may have something to do with the loading order of the class. In this way, the message is accepted in the startup class, and then through the business split, the message can be transferred to other classes to achieve their own business logic development.
Org.springframework.cloud
Spring-cloud-starter-stream-rabbit
Choose different dependencies according to different message middleware.
When too many messages are received, the message producer instance can be added to increase the message acceptance ability, and when consumers deal with a large number of blocking messages, the processing capacity decreases. We can increase the consumption capacity by increasing the number of loaded consumer service instances, which needs to find a balance through the actual situation, and the message queue is used as the cache. Reduces the risk of service crashes caused by messages being pressed directly on the server.
After reading the above, have you mastered the solution of building SpringCloudStream-based message-driven microservices to handle the massive push messages received by third-party developers from Wechat? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.