Not able to receive JMS Messages.
dhaval_shah_m Mar 8, 2005 2:43 PMI am not able to receive messages. Not sure what I am doing wrong here.
I am using JBoss4.0.1sp1 and JDK1.4
Here are the code snippets :
Initialize the queue sender :
InitialContext jndiContext = new InitialContext(); QueueConnectionFactory factory = (QueueConnectionFactory)jndiContext.lookup("UIL2ConnectionFactory"); Queue associationQueue = (Queue)jndiContext.lookup("queue/associationQueue"); QueueConnection connect = factory.createQueueConnection(); m_associationQueueSession = connect.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); m_associationQueueSender = i m_associationQueueSession.createSender(associationQueue); System.out.println("QUEUE SENDER INITIALIZED");
Send the message :
QueueSender associate = ms_controller.getAssociationQueueSender(); QueueSession associateSession = ms_controller.getAssociationQueueSession(); ObjectMessage message = associateSession.createObjectMessage(); message.setObject(comp); associate.send(message);
I have written a simple MDB to receive the messages :
public void setMessageDrivenContext(MessageDrivenContext mdc) { System.out.println("AssociateBean:Obtaining the Initial JNDI Context"); ejbContext = mdc; try { jndiContext = new InitialContext(); } catch(NamingException ne) { throw new EJBException(ne); } } public void ejbCreate() { // Log in full debug mode System.out.println("AssociateBean Created"); } public void onMessage(Message message) { try { ObjectMessage componentObj = (ObjectMessage)message; Component component = (Component)componentObj.getObject(); System.out.println("Got Message to set associations for Component "+component.getName()); } catch (Exception e) { throw new EJBException(e); } }
Ofcourse I am able to create the factory, session and also send the message [atleast no exceptions are thrown there]. However I am not able to receive the messages. Here are my deployment descriptors :
ejb-jar.xml
<ejb-jar xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd" version="2.1"> <enterprise-beans> <message-driven> <ejb-name>AssociateBean</ejb-name> <description>Java Message Bean to handle component Association</description> <display-name>AssociateBean</display-name> <ejb-class>com.sensage.rt.server.componentmanager.AssociateBean</ejb-class> <transaction-type>Container</transaction-type> <messaging-type>javax.jms.MessageListener</messaging-type> <message-destination-type>javax.jms.Queue</message-destination-type> <message-destination-link>LogicalQueue</message-destination-link> <!-- <resource-ref> <res-ref-name>jms/QueueFactory</res-ref-name> <res-type>javax.jms.QueueConnectionFactory</res-type> <res-auth>Container</res-auth> </resource-ref> --> <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-property> <activation-config-property-name>destinationType</activation-config-property-name> <activation-config-property-value>javax.jms.Queue</activation-config-property-value> </activation-config-property> <activation-config-property> <activation-config-property-name>destination</activation-config-property-name> <activation-config-property-value>queue/associationQueue</activation-config-property-value> </activation-config-property> </activation-config> </message-driven> </enterprise-beans> </ejb-jar>
jboss.xml is as follows :
<jboss> <enterprise-beans> <message-driven> <ejb-name>AssociateBean</ejb-name> <configuration-name>Standard Message Driven Bean</configuration-name> <destination-jndi-name>queue/associationQueue</destination-jndi-name> </message-driven> </enterprise-beans> <resource-ref> <res-ref-name>jms/QueueFactory</res-ref-name> <res-type>javax.jms.QueueConnectionFactory</res-type> <res-auth>Container</res-auth> </resource-ref> </jboss>
Also I have stuck the following in the jbossqueue-service.xml in "default/deploy/jms" directory.
<server> <mbean code="org.jboss.mq.server.jmx.Queue" name="jboss.mq.destination:service=Queue,name=associationQueue"> <depends optional-attribute-name="DestinationManager"> jboss.mq:service=DestinationManager </depends> </mbean> </server>
Note sure what I am missing. If somebody can point out the obvious then please let me know. Also I did went through the docs, but I am a newbie to JMS and hence need some help.
Thanks in advance,
Dhaval