ACTIVEMQ Consumer Integration Spring

Source: Internet
Author: User

Package Com.mq.consumer;

Import javax.jms.JMSException;
Import Javax.jms.Message;
Import Javax.jms.MessageListener;
Import Javax.jms.TextMessage;

public class Consumermessagelistener implements messagelistener{
@Override
public void OnMessage (message message) {
TextMessage TM = (textmessage) message;
try {
SYSTEM.OUT.PRINTLN ("---------Message consumption---------");
System.out.println ("subscriber: \ t consumerClient1");
SYSTEM.OUT.PRINTLN ("message content: \ t" + tm.gettext ());
SYSTEM.OUT.PRINTLN ("message id:\t" + Tm.getjmsmessageid ());
SYSTEM.OUT.PRINTLN ("message destination:\t" + tm.getjmsdestination ());
/* SYSTEM.OUT.PRINTLN ("---------More information---------");
SYSTEM.OUT.PRINTLN (Tostringbuilder.reflectiontostring (tm)); */
System.out.println ("-------------------------");
} catch (JMSException e) {
E.printstacktrace ();
}
}
}

The corresponding spring configuration file

<?xml version= "1.0" encoding= "UTF-8"?>
<beans xmlns= "Http://www.springframework.org/schema/beans"
Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
Xsi:schemalocation= "Http://www.springframework.org/schema/beans
Http://www.springframework.org/schema/beans/spring-beans.xsd ">


<!--Configuring the JMS Connection Factory--
<bean id= "Consumerconnectionfactory" class= "Org.apache.activemq.ActiveMQConnectionFactory" >
<property name= "Brokerurl" value= "Failover: (tcp://10.31.88.166:61616)"/>
<property name= "Useasyncsend" value= "true"/>
<property name= "ClientID" value= "Consumerclienctconnect"/>
</bean>

<!--defining Messages destination
<bean id= "topicdestination" class= "Org.apache.activemq.command.ActiveMQTopic" >
<constructor-arg value= "Testspringtopic"/>
</bean>

<!--Configure message consumption listener-->
<bean id= "Consumermessagelistener" class= " Com.mq.consumer.ConsumerMessageListener "/>
<bean id=" ConsumerMessageListener2 "class=" Com.mq.consumer.ConsumerMessageListener2 "/>

<!--message Subscription Client 1--
<bean id= "ConsumerListenerClient1" class= "Org.springframework.jms.listener.DefaultMessageListenerContainer" >
<property name= "ConnectionFactory" ref= "Consumerconnectionfactory"/>
<!--turn on subscription mode--
<property name= "Pubsubdomain" value= "true"/>
<property name= "Destination" ref= "Topicdestination"/>
<property name= "subscriptiondurable" value= "true"/>
<!---here is the ID to set the receive client, when persisted, but the client is not in the line, the message exists in the database until it is consumed by the client of this ID.
<property name= "ClientId" value= "ConsumerClient1"/>
<property name= "MessageListener" ref= "Consumermessagelistener"/>
<!--message Answering methods
Session.auto_acknowledge Message Auto Sign
Session.client_acknowledge Client call acknowledge method manual sign-off
Session.dups_ok_acknowledge does not have to be signed, messages may be sent repeatedly
-
<property name= "Sessionacknowledgemode" value= "1"/>
</bean>

</beans>

ACTIVEMQ Consumer Integration Spring

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.