In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains why JavaWeb project needs Redis to do message queue. Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn why the JavaWeb project needs Redis as a message queue.
Summary:
Architecture, distribution, log queues, headers are all bluffing, which is actually a function of log collection, but a Redis is added in the middle to do message queues. Why do I need message queuing? When there are inconsistencies in the speed or stability of "production" and "consumption" in the system, message queues are needed as an abstraction layer to bridge the differences between the two sides.
Architecture, distribution, log queues, headers are all bluffing, which is actually a function of log collection, but a Redis is added in the middle to do message queues.
Why do I need message queuing?
When there are inconsistencies in the speed or stability of "production" and "consumption" in the system, message queues are needed as an abstraction layer to bridge the differences between the two sides.
For example, we often send emails and short messages in our system, write these functions that do not need timely response to the queue, process requests asynchronously and reduce the response time.
How to achieve it?
There are many mature JMS message queuing middleware products on the market, but based on the current project architecture and deployment, we use Redis as the message queue.
Why use Redis?
The data structure of list in Redis has the characteristic of "double-end queue", and redis has the ability of persistent data, so it is very safe and reliable for redis to realize distributed queue.
It is similar to the "Queue" in JMS, except that the functionality and reliability (transactional) are not as strict as JMS. Redis's high performance and "convenient" distributed design (replicas,sharding) provide a good foundation for the implementation of "distributed queues".
Provider side
The project uses a third-party redis plug-in spring-data-redis, do not know how to use your own Google or Baidu.
Redis.properties:
# redis configuration Center redis.host=192.168.1.180redis.port=6379redis.password=123456redis.maxIdle=100 redis.maxActive=300 redis.maxWait=1000 redis.testOnBorrow=true redis.timeout=100000
Redis configuration:
Aspect log configuration (pseudo code):
/ * Syslog, aspect processing * creator Xiaoqi 2012 * creation time January 15, 2018 * / @ Component@Scope@Aspectpublic class SysLogAspect {@ Autowired private RedisTemplate redisTemplate / / the annotation is based on swagger's API, or you can define @ Pointcut ("@ annotation (io.swagger.annotations.ApiOperation)") public void logPointCut () {} @ Around ("logPointCut ()") public Object around (ProceedingJoinPoint point) throws Throwable {Object result = point.proceed (); / / write log messages to itstyle_log channel redisTemplate.convertAndSend ("itstyle_log", "log data, self-processing"); return result;}}
Consumer side
Redis configuration:
Listening interface:
Public interface MessageDelegateListener {public void handleLog (Serializable message);}
Snooping implementation:
Public class MessageDelegateListenerImpl implements MessageDelegateListener {@ Override public void handleLog (Serializable message) {if (message = = null) {System.out.println ("null");} else {/ / deal with log data} so far, I believe you have a better understanding of "Why the JavaWeb project needs Redis as a message queue". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.