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 use message Middleware in springboot

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

Share

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

This article mainly introduces how to use message middleware in springboot. It is very detailed and has certain reference value. Friends who are interested must finish reading it.

Preface

Using SpringBoot to integrate rabbitmq to achieve a send and receive

Content

1. Introduce dependency

Org.springframework.boot spring-boot-starter-amqp

2.application.properties

# rabbitmq configuration spring.application.name=springboot-mqspring.rabbitmq.host=192.168.17.129spring.rabbitmq.port=5672spring.rabbitmq.username=mytestspring.rabbitmq.password=mytest

3.rabbitmap configuration class

Import org.springframework.amqp.core.Queue;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;@Configurationpublic class RabbitMQConfig {@ Bean public Queue mqQueue () {return new Queue ("mqboot");}}

4. Sending class

< 大专栏 zyzx(53)-springboot使用消息中间件/h6>

@ Componentpublic class Sender {@ Autowired private AmqpTemplate rabbitTemplate; public void send () {String content = "send: hello" + new Date (); System.out.println ("Sender:" + content) this.rabbitTemplate.convertAndSend ("mqboot", content);}}

Collect category

@ Component@RabbitListener (queues = "mqboot") public class Receiver {@ RabbitHandler public void process (String data) {System.out.println ("Receiver:" + data);}}

6. test

Start springBoot

The following shows that the connection is successful:

@ RunWith (SpringRunner.class) @ SpringBootTestpublic class ApplicationTests {@ Autowired private TeacherRepository teacherRepository; / * @ Autowired private JavaMailSender javaMailSender;*/ @ Autowired private Sender sender; @ Testpublic void contextLoads () {/ / mq Test sender.send ();}}

These are all the contents of the article "how to use message Middleware in springboot". Thank you for reading! Hope to share the content to help you, more related knowledge, 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