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

How to write Springweb Integration rabbitmq Code

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article shows you how to write Springweb integration rabbitmq code, the content is concise and easy to understand, can definitely brighten your eyes, through the detailed introduction of this article, I hope you can get something.

Introduce the java package:

Only four java packages have been introduced in this project: amqp-client-5.7.3.jar,spring-rabbit-2.2.2.RELEASE.jar,spring-retry-1.2.4.RELEASE.jar,spring-amqp-2.2.2.RELEASE.jar

Spring-rabbitmq.xml

This xml needs to be introduced into spring, mainly in the total spring.xml. Or web.xml needs to be introduced.

RabbitMqMessageConsumer

Package club.codeapes.web.core.rabbitmq;import club.codeapes.common.date.DateUtil;import com.alibaba.fastjson.JSON;import org.springframework.amqp.core.Message;import org.springframework.amqp.core.MessageListener;public class RabbitMqMessageConsumer implements MessageListener {@ Override public void onMessage (Message message) {System.out.println ("consumption Information," + DateUtil.getNow ("yyyy-MM-dd HH:mm:ss") + "- >" + message);}}

RabbitMqMessageProducer:

Package club.codeapes.web.core.rabbitmq;import org.springframework.amqp.core.AmqpTemplate;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Repository;@Repositorypublic class RabbitMqMessageProducer {@ Autowired private AmqpTemplate amqpTemplate; public void sendMessage (Object message) {System.out.println ("to send message:" + message); amqpTemplate.convertAndSend ("queueTestKey", message);}}

The above is how to write Springweb integration rabbitmq code, have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, 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.

Share To

Development

Wechat

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

12
Report