Simple Example of ActiveMQ in JMS Message Queue: activemq in jms queue

Source: Internet
Author: User

Simple Example of ActiveMQ in JMS Message Queue: activemq in jms queue
Not to mention nonsense. 1. Add the required maven dependency 

<!-- active mq begin --><dependency><groupId>org.springframework</groupId><artifactId>spring-jms</artifactId><version>4.3.8.RELEASE</version></dependency><dependency><groupId>org.apache.activemq</groupId><artifactId>activemq-all</artifactId><version>5.14.5</version></dependency><!-- active mq end -->
    2. Add activemq configurations to the Spring configuration file.1) message sending
<! -- Configure the JMS connection factory --> <bean id = "connectionFactory" class = "org. apache. activemq. activeMQConnectionFactory "> <property name =" brokerURL "value =" tcp: // localhost: 61616 "/> </bean> <! -- Define the Message destination of the Queue type --> <bean id = "queueDestination" class = "org. apache. activemq. command. ActiveMQQueue"> <! -- Set the Queue name --> <constructor-arg> <value> bounter. queue </value> </constructor-arg> </bean> <! -- Define the Message destination of the Topic type --> <bean id = "topicDestination" class = "org. apache. activemq. command. ActiveMQTopic"> <! -- Set the Topic name --> <constructor-arg> <value> bounter. topic </value> </constructor-arg> </bean> <! -- Defines JmsTemplate to simplify message sending --> <bean id = "jmsTemplate" class = "org. springframework. jms. core. jmsTemplate "> <property name =" connectionFactory "ref =" connectionFactory "/> <property name =" defaultDestination "ref =" queueDestination "/> <property name =" receiveTimeout "value = "10000"/> </bean>
2) Message receiving (there are multiple receiving methods. Here we use Spring's Message Driven POJO asynchronous listening method)
<! -- Define the listener container for receiving messages --> <bean id = "messageListenerContainer" class = "org. springframework. jms. listener. defaultMessageListenerContainer "> <property name =" connectionFactory "ref =" connectionFactory "/> <! -- Configure the message listening destination, which can be the Queue or Topic defined above --> <! -- <Property name = "destination" ref = "queueDestination"/> --> <property name = "destination" ref = "topicDestination"/> <! -- Configure the custom message listener class --> <! -- <Property name = "messageListener" ref = "jmsQueueListener"/> --> <property name = "messageListener" ref = "jmsTopicListener"/> </bean>
    3. Define message senders and message ReceiversFor 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. ActiveMQTest    Is it easy! Try it on your own! If you have any suggestions, please leave a message! Github Source Code address: (Go Back To update tonight, work first)

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.