Simple Example of AMQP Message Queue RabbitMQ, amqp queue rabbitmq

Source: Internet
Author: User
Tags rabbitmq

Simple Example of AMQP Message Queue RabbitMQ, amqp queue rabbitmq

The previous article explains how to quickly build an ActiveMQ sample program. ActiveMQ is the implementation of JMS, in this article, let's look at another example of Message Queue AMQP to implement RabbitMQ. Before proceeding to the specific explanation, we will first use a diagram to give an overview:

1. Add Maven dependency

        <!-- rabbitmq begin -->        <dependency>            <groupId>org.springframework.amqp</groupId>            <artifactId>spring-rabbit</artifactId>            <version>1.7.2.RELEASE</version>        </dependency>        <!-- rabbitmq end -->

 

2.Add rabbitmq configurations to the Spring configuration file.

1) message sending

<! -- Configure connection-factory and specify the parameters for connecting to the rabbit server --> <rabbit: connection-factory id = "connectionFactory" host = "127.0.0.1" port = "5672" username = "guest" password = "guest"/> <! -- Define rabbit template for receiving and sending data --> <rabbit: template id = "amqpTemplate" connection-factory = "connectionFactory" exchange = "bounter. fanout "routing-key =" bounter. key "/> <! -- By specifying the following admin information, exchange and queue in the current producer will be automatically generated on the rabbitmq server --> <rabbit: admin connection-factory = "connectionFactory"/> <! -- Define queue --> <rabbit: queue name = "bounter. queue"/> <! -- Define fanout exchange and publish and subscribe mode --> <rabbit: fanout-exchange name = "bounter. fanout "> <rabbit: bindings> <rabbit: binding queue =" bounter. queue "/> </rabbit: bindings> </rabbit: fanout-exchange>

 

2) receive messages

<! -- Define the listener container for receiving messages --> <rabbit: listener-container connection-factory = "connectionFactory"> <rabbit: listener ref = "amqpFanoutListener" method = "onFanout" queue-names = "bounter. queue "/> <! -- <Rabbit: listener ref = "amqpDirectListener" method = "onDirect" queue-names = "bounter. queue"/> --> </rabbit: listener-container>

 

3. Define message senders and message listenersFor more information, see the sender and Cycler packages in the project source code. 4. Test message sending and receivingFor details, refer to the unit test class in the project source code. RabbitMQTestIs it easy! Try it on your own! If you have any suggestions, please leave a message! Github Source Code address: https://github.com/13babybear/mq-client

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.