Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

RabbitMQ integrates with spring and fully configured producers and consumers

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the integration of RabbitMQ and spring as well as the complete configuration of producers and consumers, the content is very detailed, interested friends can refer to, hope to be helpful to you.

For more information on RabbitMQ and AMQP protocols, you can take a look at this http://www.cnblogs.com/frankyou/p/5283539.html.

Here is the configuration for the integration of rabbitMQ and spring. I configured two kinds of ExCahange: topicExchange and directExChange

Spring public configuration

Generator demo example:

@ Controller @ RequestMapping ("/ amqpTest") public class AmqpTestController {@ Autowired private AmqpTemplate amqpTemplate; @ RequestMapping ("/ sendMsg") @ ResponseBody public String sendAmqbMsg (Model model,@RequestParam (value= "msg", defaultValue= "hello worldview!") String msg) {if (modelling empty boxes! "" .equals (msg)) {amqpTemplate.convertAndSend ("mq.asdfExChange", "mq.asdf.send", msg) } else {amqpTemplate.convertAndSend ("mq.asdfExChange", "mq.asdf.send", "hello world");} return "success" } @ RequestMapping ("/ sendMsg2") @ ResponseBody public String sendAmqbMsg2 (Model model,@RequestParam (value= "msg", defaultValue= "hello worldviews!") String msg) {if (modelling empty boxes! "" .equals (msg)) {amqpTemplate.convertAndSend ("mq.asdfExChange", "mq.asdf2.send", "it's a wonderful world!") } else {amqpTemplate.convertAndSend ("mq.asdfExChange", "mq.asdf2.send", "it's a wonderful world");} return "success" } @ RequestMapping ("/ sendMsg3") @ ResponseBody public String sendAmqbMsg3 (Model model,@RequestParam (value= "msg", defaultValue= "hello worldviews!") String msg) {if (modelling empty worlds! "" .equals (msg)) {amqpTemplate.convertAndSend ("mq.qwerExChange", "mq.qwer.send", "magical world!") } else {amqpTemplate.convertAndSend ("mq.qwerExChange", "mq.qwer.send", "Magic World");} return "success";}}

Consumers:

Here I list a Demo according to the configuration

Consumer

There is no problem with path matching. Public class AsdfConsumer implements MessageListener {

Static {System.out.println ("already dependent on success");} public void onMessage (Message message) {MessageProperties m=message.getMessageProperties (); / / System.out.println (m); String msg= new String (message.getBody ()); System.out.println ("consumed:" + msg+ "- >") }} this is the end of the integration of RabbitMQ and spring and the complete configuration of producers and consumers. I hope the above content can be of some help and learn more knowledge. If you think the article is good, you can share it for more people to see.

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report