In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail the example analysis of SpringMVC consumption RabbitMQ queue for you. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
1. Environment introduction
Jdk1.8.0_202
Spring 4.3.9.RELEASE
Spring-webmvc 4.3.9.RELEASE
two。 Add Maven dependency com.rabbitmq amqp-client 5.6.0 org.springframework.amqp spring-amqp 2.0.12.RELEASE org.springframework.amqp spring-rabbit 2.0.12.RELEASE org.springframework.retry spring-retry 1.2.4.RELEASE3. Add RabbitMQ configuration add RabbitMQ address port user password and other information in the jdbc.properties file # RabbitMQ address mq_host=127.0.0.1#RabbitMQ port mq_port=5672#RabbitMQ virtual host mq_virtual_host=/#RabbitMQ username mq_username=admin#RabbitMQ password mq_password=your rabbitmq password4. Create a RabbitMQ profile create a new applicationContext-rabbitmq.xml
The content is as follows: RabbitMQ connection service configuration 5. To create a listener consumer to create a consumer class corresponding to ref= "plateNumRabbitConsumer", you must add @ Component to Spring management. The instance name can be customized, but must be consistent with the name associated with ref. The consumer class must implement MessageListener, listen for queue changes, and achieve real-time consumption.
Problems encountered
If there are both producers and consumers in the same project, the factories, routes and queues declared in applicationContext-rabbitmq.xml do not pay special attention; producers need to use rabbit:template, consumers do not need this configuration.
If you only need to consume queues, when declaring queues, if a queue with the same name has been created in the rabbitmq service, you must configure ignore-declaration-exceptions= "true", otherwise an error will be reported when the project starts.
For the configuration of the listening container, you should pay attention to prefetch= "1" and acknowledge= "auto". Prefetch indicates the quantity consumed from the queue at a time. Prefetch= "1" indicates that one message is consumed at a time. If multiple listeners are configured in the container to consume, it will be fairly distributed. Acknowledge= "auto" means automatic reply, reply confirmation after consumption is completed, change message will be deleted from rabbitmq service, and the next message will be automatically consumed. Acknowledge= "manual" means manual reply when message processing fails: it will be retransmitted until the message is successfully processed and needs to be manually submitted; otherwise, it will not continue to be consumed. Manual reply requires configuration of template's confirm-callback callback method.
This is the end of the article on "sample Analysis of SpringMVC consumption RabbitMQ queue". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, please 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.
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.