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 does SpringBoot automatically help us create Queue and Exchange for RabbitMQ?

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 SpringBoot automatically helps us create RabbitMQ Queue and Exchange. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

If you want to see the automatic configuration that SpringBoot did for us in the SpringBoot project, it's easy to search for XXXAutoConfiguration.

Such as: RabbitAutoConfiguration,RedisAutoConfiguration, etc.

Go to the RabbitAutoConfiguration class explanation: when RabbitTemplate.class and Channel.class exist in classpath (that is, RabbitMQ-related dependencies are introduced in the project), the current configuration class will take effect. The Bean defined within the configuration class also takes effect.

See which bean is registered in the current configuration class, one of which is explained to RabbitAdmin: and the Bean takes effect by default when spring.rabbitmq.dynamic is not configured.

Go to this class and see what has been done during the creation of the bean. Explanation: you can see that this class implements the InitializingBean interface, so continue to see what has been done in the afterPropertiesSet () method.

Explanation: a listener is registered in the connection factory connectionFactory and the initialize () method is executed in the listener.

View the initialize () method.

Explanation: you can clearly see that it is through the applicationContext.getBeansOfType (XXX.class) method to get all the bean of type Queue, Exchange and Binding in the container, and based on the information of these bean to help us create queues, switches and binding relationships in RabbitMQ.

Enter any method, such as declareExchanges ()

Explanation: as you can see, in the end, the channel.exchangeDeclare () is called, which is consistent with the effect created by our manual call.

This is a way of writing code, which can be used for reference at ordinary times.

This is how the SpringBoot shared by the editor automatically helped us create RabbitMQ Queue and Exchange. 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.

Share To

Internet Technology

Wechat

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

12
Report