In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
In this issue, the editor will bring you about how to integrate SSM framework and xml configuration in RabbitMQ. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.
Premise: jdk1.8, this blog uses the RabbitTemplate template, uses the encapsulated method, no longer uses
There is also a key point, you must be able to use the rabbitmq server, create your own exchange, queue, etc., otherwise you will make a mistake if you use the blog.
Two methods: topic mode and the use of delay queues
1. Pom cn.hutool hutool-all 4.5.16 org.springframework.amqp spring-rabbit 1.7.11.RELEASE2, application.properties# rabbitmq message configuration rabbitmq.addresses=localhost:5672rabbitmq.virtual-host=/rabbitmq.username=guestrabbitmq.password=guestrabbitmq.channel-cache-size=50rabbitmq.concurrentConsumers=3rabbitmq.maxConcurrentConsumers=10# confirmation method MANUAL manual, AUTO automatic NONE automatically confirms the number of rabbitmq.acknowledgeMode=MANUAL# thread pools = concurrency * number of listeners rabbitmq.task-executor.pool-size=1003, Spring-rabbit.xml 4 、 Listener import cn.hutool.core.date.DateUtil Import com.fasterxml.jackson.databind.JsonNode;import com.fasterxml.jackson.databind.ObjectMapper;import org.springframework.amqp.core.Message;import org.springframework.amqp.core.MessageListener;import org.springframework.amqp.rabbit.core.RabbitTemplate;import org.springframework.beans.factory.annotation.Autowired;import java.io.IOException;import java.text.DateFormat;import java.util.Date / * * @ Author:MuJiuTian * @ Description: RabbitMq delay queue https://blog.csdn.net/m912595719/article/details/83787486 * ChannelAwareMessageListener (Message memssage,Channel channel) MessageListener (Message message) * @ Date: Created in 4:17 2019-8-12 * / public class DelayListener implements MessageListener {@ Autowired RabbitTemplate rabbitTemplate; private static final ObjectMapper MAPPER = new ObjectMapper () @ Override public void onMessage (Message message) {try {JsonNode jsonData = MAPPER.readTree (message.getBody ()); System.out.println ("delay queue time is:" + DateUtil.format (new Date (), DateFormat.getDateTimeInstance ());} catch (IOException e) {e.printStackTrace ();}} import com.fasterxml.jackson.databind.JsonNode Import com.fasterxml.jackson.databind.ObjectMapper;import com.platform.service.SeckillService;import org.springframework.amqp.core.Message;import org.springframework.amqp.core.MessageListener;import org.springframework.beans.factory.annotation.Autowired;/** * @ Author:MuJiuTian * @ Description: kill consumer news in seconds, monitor and execute business logic processing * @ Date: Created in 5:01 2019-8-14 * / public class SeckillHandler implements MessageListener {@ Autowired SeckillService seckillService Private static final ObjectMapper MAPPER = new ObjectMapper (); @ Override public void onMessage (Message message) {try {/ / continue to execute second kill in queue JsonNode jsonData = MAPPER.readTree (message.getBody ()); String goodsId = jsonData.get ("goodsId"). AsText (); int productId = jsonData.get ("productId"). AsInt () Int userId = jsonData.get ("userId"). AsInt (); int sellerNum = jsonData.get ("sellerNum"). AsInt (); / / start second kill seckillService.seckillRedis (goodsId,productId,sellerNum,userId);} catch (Exception e) {e.printStackTrace ();} 5, entity public class Mail implements Serializable {private static final long serialVersionUID =-8140693840257585779L Private String mailId; private String country; private Double weight; public Mail () {} public Mail (String mailId, String country, double weight) {this.mailId = mailId; this.country = country; this.weight = weight;} public String getMailId () {return mailId;} public void setMailId (String mailId) {this.mailId = mailId } public String getCountry () {return country;} public void setCountry (String country) {this.country = country;} public double getWeight () {return weight;} public void setWeight (double weight) {this.weight = weight } @ Override public String toString () {return "Mail [mailId=" + mailId + ", country=" + country + ", weight=" + weight + "]";}} 6. Controller/** * topic: wildcard pattern * / @ GetMapping (value = "/ test7") public void test11 () {Mail mail = new Mail ("21", "China", 27.2) System.out.println ("topic mode sends data to message queue" + DateUtil.format (new Date (), DateFormat.getDateTimeInstance (); rabbitTemplate.convertAndSend ("IExchange", "lazy.dtb", mail); long waiting time of dead letter queue. Currently, the test is: automatic consumption * / @ GetMapping (value = "/ test8") public void test13 (long time) throws IOException {Mail mail = randomMail () System.out.println ("delay queue: dlx mode" + DateUtil.format (new Date (), DateFormat.getDateTimeInstance (); rabbitTemplate.convertAndSend ("dlx_delay_exchange", "dlx_delay_road", mail, message-> {message.getMessageProperties () .setExpiration (time + "); return message;}) } / * randomly create a Mail entity object for interface testing * / public static Mail randomMail () {Mail mail = new Mail (); mail.setMailId (new Random (). NextInt (100) + "); mail.setCountry (" China "); mail.setWeight (new Random (). NextDouble ()); return mail } the above is how to integrate the xml configuration of the SSM framework in RabbitMQ shared by the editor. If you happen to have similar doubts, please refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
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.