[jboss-user] [Messaging, JMS & JBossMQ] - Re: MDB multiple queues
jpersson
do-not-reply at jboss.com
Tue Sep 12 05:45:15 EDT 2006
Thanks!
Now my MDB is partly annotated and partly XML-descriptor driven. Works fine.
When my MDB runs in two instances is there a concurrency issue when passing incoming messages to the 'next' queue (two mdb instances sending/routing to a single queue) ?
THIS IS SOURCE MDB:
package com.mdm.mdb.bean;
import javax.annotation.Resource;
import javax.ejb.MessageDriven;
import javax.ejb.ActivationConfigProperty;
import javax.jms.Message;
import javax.jms.TextMessage;
import javax.jms.MapMessage;
import javax.jms.ObjectMessage;
import javax.jms.MessageListener;
import javax.jms.JMSException;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.Session;
import com.thoughtworks.xstream.XStream;
import static java.lang.System.out;
/** Message Listener setup with annotations, override with XML-descriptor. */
@MessageDriven(activationConfig ={@ActivationConfigProperty(propertyName="destinationType",
propertyValue="javax.jms.Queue")})
public class ServiceBrixRoutingMDB implements MessageListener{
// Dependecy injection.
@Resource(mappedName="java:ConnectionFactory")
QueueConnectionFactory connectionFactory;
// Dependecy injection.
QueueConnection queueConnection;
// Dependecy injection.
@Resource(mappedName="queue/mdm-input")
Queue mDMInputQueue;
// Parser for Object to XML marshaller.
private XStream xstream = null;
/** This is the entry for the message listener. */
public void onMessage(Message messageFromServicemix){
try{
if(messageFromServicemix instanceof TextMessage){
sendMesageToMDM();
}
}catch(Exception e){
out.println(e);
}
}
/** Send MapMessage to MDM node. */
private void sendMesageToMDM() throws JMSException{
QueueSender qsender = null;
queueConnection = getConnection();
QueueSession qsession = queueConnection.createQueueSession(
false, Session.AUTO_ACKNOWLEDGE);
TextMessage mdmMessagge = null;
qsender = qsession.createSender(mDMInputQueue);
mdmMessagge = qsession.createTextMessage("MESSAGE_FROM_SERVICEMIX");
qsender.send(mdmMessagge);
qsession.close();
queueConnection.close();
queueConnection = null;
}
/** Get QueConnection from JBoss Factory. */
private QueueConnection getConnection() throws JMSException{
if (queueConnection == null){
synchronized(connectionFactory){
if(queueConnection == null){
queueConnection = connectionFactory.createQueueConnection();
}
}
}
return queueConnection;
}
/** Get thread safe XStream object for marshall/unmarshall Object/XML. */
private XStream getXStream(){
if(xstream == null){xstream = new XStream();}return xstream;
}
}
THIS IS SOURCE EJBJAR-XML:
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
version="3.0">
Message Driven Bean for Routing from Servicemix to Flowbrix
<display-name>MDB for routing from Servicemix to Flowbrix</display-name>
<enterprise-beans>
<message-driven>
<ejb-name>CPAssistedRequestMDB</ejb-name>
<ejb-class>com.smarttrust.mdm.mdb.bean.ServiceBrixRoutingMDB</ejb-class>
<transaction-type>Bean</transaction-type>
<message-destination-type>javax.jms.Queue</message-destination-type>
<activation-config>
<activation-config-property>
<activation-config-property-name>acknowledgeMode</activation-config-property-name>
<activation-config-property-value>AUTO_ACKNOWLEDGE</activation-config-property-value>
</activation-config-property>
</activation-config>
</message-driven>
<message-driven>
<ejb-name>CPAssistedReplyMDB</ejb-name>
<ejb-class>com.smarttrust.mdm.mdb.bean.ServiceBrixRoutingMDB</ejb-class>
<transaction-type>Bean</transaction-type>
<message-destination-type>javax.jms.Queue</message-destination-type>
<activation-config>
<activation-config-property>
<activation-config-property-name>acknowledgeMode</activation-config-property-name>
<activation-config-property-value>AUTO_ACKNOWLEDGE</activation-config-property-value>
</activation-config-property>
</activation-config>
</message-driven>
</enterprise-beans>
</ejb-jar>
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3970956#3970956
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3970956
More information about the jboss-user
mailing list