You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by CobraTheSleek <ka...@yahoo.com> on 2007/11/09 19:01:47 UTC

Messages not being received by consumer

Hi,

ENV:
ActiveMQ-Snapshot-5.0
JBoss AS 4.2.1

I have the following queues defined:

 <mbean code="org.jboss.resource.deployment.AdminObject"
name="activemq.queue:name=org.apache.activemq.requestQueue">
	   <attribute name="JNDIName">activemq/requestQueue</attribute>
      <depends
optional-attribute-name="RARName">jboss.jca:service=RARDeployment,name='activemq-ra.rar'</depends>
      <attribute name="Type">javax.jms.Queue</attribute>
      <attribute
name="Properties">PhysicalName=org.apache.activemq.requestQueue</attribute>
   </mbean>

   <mbean code="org.jboss.resource.deployment.AdminObject"
name="activemq.queue:name=org.apache.activemq.replyQueue">
	   <attribute name="JNDIName">activemq/echoResponseQueue</attribute>
      <depends
optional-attribute-name="RARName">jboss.jca:service=RARDeployment,name='activemq-ra.rar'</depends>
      <attribute name="Type">javax.jms.Queue</attribute>
      <attribute
name="Properties">PhysicalName=org.apache.activemq.replyQueue</attribute>
   </mbean>

I have an MDB defined that listens for messages from the requestQueue and
posts a response on the replyQueue.

I am using the Spring unit tests provided (Producer and Consumer) and my
Producer sends messages to the requestQueue, the MDB receives the request
and posts a message back on to the replyQueue.

I can see that there are messages in the replyQueue via JMX. However, my
Consumer never receives messages from the replyQueue.

If I run the test without the MDB, by placing messages in the replyQueue via
the PRODUCER, my Consumer receives the messages successfully. In other words
messages posted by the MDB are never received by the consumer. 

The following is what my MDB does to place messages back on the reply queue:

InitialContext initCtx = new InitialContext();
		
	QueueConnectionFactory qcf = (QueueConnectionFactory) initCtx
		.lookup("java:comp/env/jms/MyQueueConnectionFactory");
	
	QueueConnection qcon = qcf.createQueueConnection();
	QueueSession qsession = qcon.createQueueSession(true, 0);
	Queue q = (Queue) initCtx.lookup("activemq/replyQueue");
	QueueSender qsender = qsession.createSender(q);
	
	TextMessage message = qsession.createTextMessage();
	
	message.setText(response);
	qsender.setTimeToLive(100000000);
	qsender.send(message);
	
	qsender.close();
	qsession.close();
	qcon.close();


I am quite confused as to why this is happening as I see messages as being
available in the replyQueue.
Any tips would be appreciated.
-- 
View this message in context: http://www.nabble.com/Messages-not-being-received-by-consumer-tf4779201s2354.html#a13672078
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Messages not being received by consumer

Posted by CobraTheSleek <ka...@yahoo.com>.
I beleive my problem is something related to the Spring support. When I used
the JMSTestClient provided by the Panacya which uses jmsTemplate.receive()
to retreive one message back from the queue, the message was successfully
dequed. I could run that multiple times over to keep dequeing messages.

However, when I use the SpringConsumer onMessage() example, I do not
retrieve a message. On looking at the JMX view, I noticed that the consumer
does appear as a client to the Queue so I eliminated the fact that the test
might be pointing to the wrong queue.

The following is my applicationContext definition, I am using JNDI
connection factory for sending but using the jmsfactory for receiving. I
tried to use the JNDI for both to no success as well.

Any assistance would be greately appreciated. Thanks in advance.

	<bean id="jndiTemplate"
		class="org.springframework.jndi.JndiTemplate">
		<property name="environment">
			<props>
				<prop key="brokerURL">tcp://localhost:61616</prop>

				<prop key="java.naming.factory.initial">
					org.apache.activemq.jndi.ActiveMQInitialContextFactory
				</prop>
				<prop key="queue.requestQueue">
					org.apache.activemq.requestQueue
				</prop>
			</props>
		</property>
	</bean>



	<!--  JNDI Object factory bean for request queue -->
	<bean id="requestQueue"
		class="org.springframework.jndi.JndiObjectFactoryBean">
		<property name="jndiTemplate">
			<ref bean="jndiTemplate" />
		</property>
		<property name="jndiName">
			<value>requestQueue</value>
		</property>
	</bean>


	<bean id="connectionFactory"
		class="org.springframework.jndi.JndiObjectFactoryBean">
		<property name="jndiTemplate">
			<ref bean="jndiTemplate" />
		</property>
		<property name="jndiName">
			<value>ConnectionFactory</value>
		</property>
	</bean>

	<bean id="jmsTemplate"
		class="org.springframework.jms.core.JmsTemplate">
		<property name="connectionFactory">
			<ref bean="connectionFactory" />
		</property>
		<property name="pubSubDomain">
			<value>false</value>
		</property>
	</bean>

	<!-- a sample POJO which uses a Spring JmsTemplate -->

	<bean id="producer" class="com.activemq.test.SpringProducer">
		<property name="template">
			<ref bean="jmsTemplate"></ref>
		</property>

		<property name="messageCount">
			<value>10</value>
		</property>

		<property name="destination">
			<ref bean="echoRequestQueue" />
		</property>
	</bean>


	<bean id="jmsFactory"
		class="org.apache.activemq.pool.PooledConnectionFactory"
		destroy-method="stop">
		<property name="connectionFactory">
			<bean
				class="org.apache.activemq.ActiveMQConnectionFactory">
				<property name="brokerURL">
					<value>tcp://localhost:61616</value>
				</property>
				<property name="userName">
					<value>user</value>
				</property>
				<property name="password">
					<value>password</value>
				</property>
			</bean>
		</property>
	</bean>

	<!-- Spring JMS Template -->
	<bean id="consumerJmsTemplate"
		class="org.springframework.jms.core.JmsTemplate">
		<property name="connectionFactory">
			<ref local="jmsFactory" />
		</property>

	</bean>

	<!-- a sample POJO consumer -->
	<bean id="consumer" class="com.activemq.test.SpringConsumer">
		<property name="template">
			<ref bean="consumerJmsTemplate"></ref>
		</property>

		<property name="destination">
			<ref bean="consumerDestination" />
		</property>
	</bean>

	<bean id="consumerDestination"
		class="org.apache.activemq.command.ActiveMQQueue"
		autowire="constructor" lazy-init="default"
		dependency-check="default">
		<constructor-arg value="org.apache.activemq.replyQueue" />
	</bean>


CobraTheSleek wrote:
> 
> Hi,
> 
> ENV:
> ActiveMQ-Snapshot-5.0
> JBoss AS 4.2.1
> 
> I have the following queues defined:
> 
>  <mbean code="org.jboss.resource.deployment.AdminObject"
> name="activemq.queue:name=org.apache.activemq.requestQueue">
> 	   <attribute name="JNDIName">activemq/requestQueue</attribute>
>       <depends
> optional-attribute-name="RARName">jboss.jca:service=RARDeployment,name='activemq-ra.rar'</depends>
>       <attribute name="Type">javax.jms.Queue</attribute>
>       <attribute
> name="Properties">PhysicalName=org.apache.activemq.requestQueue</attribute>
>    </mbean>
> 
>    <mbean code="org.jboss.resource.deployment.AdminObject"
> name="activemq.queue:name=org.apache.activemq.replyQueue">
> 	   <attribute name="JNDIName">activemq/replyQueue</attribute>
>       <depends
> optional-attribute-name="RARName">jboss.jca:service=RARDeployment,name='activemq-ra.rar'</depends>
>       <attribute name="Type">javax.jms.Queue</attribute>
>       <attribute
> name="Properties">PhysicalName=org.apache.activemq.replyQueue</attribute>
>    </mbean>
> 
> I have an MDB defined that listens for messages from the requestQueue and
> posts a response on the replyQueue.
> 
> I am using the Spring unit tests provided (Producer and Consumer) and my
> Producer sends messages to the requestQueue, the MDB receives the request
> and posts a message back on to the replyQueue.
> 
> I can see that there are messages in the replyQueue via JMX. However, my
> Consumer never receives messages from the replyQueue.
> 
> If I run the test without the MDB, by placing messages in the replyQueue
> via the PRODUCER, my Consumer receives the messages successfully. In other
> words messages posted by the MDB are never received by the consumer. 
> 
> The following is what my MDB does to place messages back on the reply
> queue:
> 
> InitialContext initCtx = new InitialContext();
> 		
> 	QueueConnectionFactory qcf = (QueueConnectionFactory) initCtx
> 		.lookup("java:comp/env/jms/MyQueueConnectionFactory");
> 	
> 	QueueConnection qcon = qcf.createQueueConnection();
> 	QueueSession qsession = qcon.createQueueSession(true, 0);
> 	Queue q = (Queue) initCtx.lookup("activemq/replyQueue");
> 	QueueSender qsender = qsession.createSender(q);
> 	
> 	TextMessage message = qsession.createTextMessage();
> 	
> 	message.setText(response);
> 	qsender.setTimeToLive(100000000);
> 	qsender.send(message);
> 	
> 	qsender.close();
> 	qsession.close();
> 	qcon.close();
> 
> 
> I am quite confused as to why this is happening as I see messages as being
> available in the replyQueue.
> Any tips would be appreciated.
> 

-- 
View this message in context: http://www.nabble.com/Messages-not-being-received-by-consumer-tf4779201s2354.html#a13691974
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Messages not being received by consumer

Posted by CobraTheSleek <ka...@yahoo.com>.
I  beleive my problem has been solved. It was my bad. I was using a selector
consumer = session.createConsumer(destination, selector, false); but when
dispatching the message from the ejb, I did not specify a property on the
message. Thus the consumer did not pick it up.



CobraTheSleek wrote:
> 
> Hi James, thanks much for the response. In my sender code, if I do an
> explicit commit() on the session, I receive the following message as an XA
> transaction is in progress:
> 
> 08:35:57,390 ERROR [STDERR]     at java.lang.Thread.run(Thread.java:595)
> 08:35:57,390 ERROR [STDERR] Caused by:
> javax.jms.TransactionInProgressException:
>  Cannot commit() if an XA transaction is already in progress
> 08:35:57,390 ERROR [STDERR]     at
> org.apache.activemq.TransactionContext.commit
> (TransactionContext.java:249)
> 08:35:57,390 ERROR [STDERR]     at
> org.apache.activemq.ra.ManagedTransactionCont
> ext.commit(ManagedTransactionContext.java:62)
> 08:35:57,390 ERROR [STDERR]     at
> org.apache.activemq.ActiveMQSession.commit(Ac
> tiveMQSession.java:494)
> 08:35:57,390 ERROR [STDERR]     at
> org.apache.activemq.ra.ManagedSessionProxy.co
> mmit(ManagedSessionProxy.java:101)
> 08:35:57,406 ERROR [STDERR]     at
> org.apache.activemq.ActiveMQQueueSession.comm
> it(ActiveMQQueueSession.java:72)
> 
> 
> If, I change the code to not send a transacted message, i.e., 
>  QueueSession qsession = qcon.createQueueSession(false, 0); I still do not
> see the message on my onMessage.
> 
> On my Consumer from the spring example, I am setting a transacted session,
> i.e.,
>  try {
>             ConnectionFactory factory = template.getConnectionFactory();
>             connection = factory.createConnection();
> 
>             // we might be a reusable connection in spring
>             // so lets only set the client ID once if its not set
>             synchronized (connection) {
>                 if (connection.getClientID() == null) {
>                     connection.setClientID(myId);
>                 }
>             }
>             connection.start();
> 
>             session = connection.createSession(true,
> Session.AUTO_ACKNOWLEDGE);
>             consumer = session.createConsumer(destination, selector,
> false);
>             consumer.setMessageListener(this);
> 
> If I however change it to be non-transacted on the Spring consumer, I
> still do not receive the messages.
> 
> Thanks in advance for any assitance.
> 
> 
> James.Strachan wrote:
>> 
>> It looks like you're creating a transactional session and never
>> calling commit().
>> 
>> On 09/11/2007, CobraTheSleek <ka...@yahoo.com> wrote:
>>>
>>> Hi,
>>>
>>> ENV:
>>> ActiveMQ-Snapshot-5.0
>>> JBoss AS 4.2.1
>>>
>>> I have the following queues defined:
>>>
>>>  <mbean code="org.jboss.resource.deployment.AdminObject"
>>> name="activemq.queue:name=org.apache.activemq.requestQueue">
>>>            <attribute name="JNDIName">activemq/requestQueue</attribute>
>>>       <depends
>>> optional-attribute-name="RARName">jboss.jca:service=RARDeployment,name='activemq-ra.rar'</depends>
>>>       <attribute name="Type">javax.jms.Queue</attribute>
>>>       <attribute
>>> name="Properties">PhysicalName=org.apache.activemq.requestQueue</attribute>
>>>    </mbean>
>>>
>>>    <mbean code="org.jboss.resource.deployment.AdminObject"
>>> name="activemq.queue:name=org.apache.activemq.replyQueue">
>>>            <attribute
>>> name="JNDIName">activemq/echoResponseQueue</attribute>
>>>       <depends
>>> optional-attribute-name="RARName">jboss.jca:service=RARDeployment,name='activemq-ra.rar'</depends>
>>>       <attribute name="Type">javax.jms.Queue</attribute>
>>>       <attribute
>>> name="Properties">PhysicalName=org.apache.activemq.replyQueue</attribute>
>>>    </mbean>
>>>
>>> I have an MDB defined that listens for messages from the requestQueue
>>> and
>>> posts a response on the replyQueue.
>>>
>>> I am using the Spring unit tests provided (Producer and Consumer) and my
>>> Producer sends messages to the requestQueue, the MDB receives the
>>> request
>>> and posts a message back on to the replyQueue.
>>>
>>> I can see that there are messages in the replyQueue via JMX. However, my
>>> Consumer never receives messages from the replyQueue.
>>>
>>> If I run the test without the MDB, by placing messages in the replyQueue
>>> via
>>> the PRODUCER, my Consumer receives the messages successfully. In other
>>> words
>>> messages posted by the MDB are never received by the consumer.
>>>
>>> The following is what my MDB does to place messages back on the reply
>>> queue:
>>>
>>> InitialContext initCtx = new InitialContext();
>>>
>>>         QueueConnectionFactory qcf = (QueueConnectionFactory) initCtx
>>>                 .lookup("java:comp/env/jms/MyQueueConnectionFactory");
>>>
>>>         QueueConnection qcon = qcf.createQueueConnection();
>>>         QueueSession qsession = qcon.createQueueSession(true, 0);
>>>         Queue q = (Queue) initCtx.lookup("activemq/replyQueue");
>>>         QueueSender qsender = qsession.createSender(q);
>>>
>>>         TextMessage message = qsession.createTextMessage();
>>>
>>>         message.setText(response);
>>>         qsender.setTimeToLive(100000000);
>>>         qsender.send(message);
>>>
>>>         qsender.close();
>>>         qsession.close();
>>>         qcon.close();
>>>
>>>
>>> I am quite confused as to why this is happening as I see messages as
>>> being
>>> available in the replyQueue.
>>> Any tips would be appreciated.
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Messages-not-being-received-by-consumer-tf4779201s2354.html#a13672078
>>> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>>>
>>>
>> 
>> 
>> -- 
>> James
>> -------
>> http://macstrac.blogspot.com/
>> 
>> Open Source SOA
>> http://open.iona.com
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Messages-not-being-received-by-consumer-tf4779201s2354.html#a13738207
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Messages not being received by consumer

Posted by CobraTheSleek <ka...@yahoo.com>.
Hi James, thanks much for the response. In my sender code, if I do an
explicit commit() on the session, I receive the following message as an XA
transaction is in progress:

08:35:57,390 ERROR [STDERR]     at java.lang.Thread.run(Thread.java:595)
08:35:57,390 ERROR [STDERR] Caused by:
javax.jms.TransactionInProgressException:
 Cannot commit() if an XA transaction is already in progress
08:35:57,390 ERROR [STDERR]     at
org.apache.activemq.TransactionContext.commit
(TransactionContext.java:249)
08:35:57,390 ERROR [STDERR]     at
org.apache.activemq.ra.ManagedTransactionCont
ext.commit(ManagedTransactionContext.java:62)
08:35:57,390 ERROR [STDERR]     at
org.apache.activemq.ActiveMQSession.commit(Ac
tiveMQSession.java:494)
08:35:57,390 ERROR [STDERR]     at
org.apache.activemq.ra.ManagedSessionProxy.co
mmit(ManagedSessionProxy.java:101)
08:35:57,406 ERROR [STDERR]     at
org.apache.activemq.ActiveMQQueueSession.comm
it(ActiveMQQueueSession.java:72)


If, I change the code to not send a transacted message, i.e., 
 QueueSession qsession = qcon.createQueueSession(false, 0); I still do not
see the message on my onMessage.

On my Consumer from the spring example, I am setting a transacted session,
i.e.,
 try {
            ConnectionFactory factory = template.getConnectionFactory();
            connection = factory.createConnection();

            // we might be a reusable connection in spring
            // so lets only set the client ID once if its not set
            synchronized (connection) {
                if (connection.getClientID() == null) {
                    connection.setClientID(myId);
                }
            }
            connection.start();

            session = connection.createSession(true,
Session.AUTO_ACKNOWLEDGE);
            consumer = session.createConsumer(destination, selector, false);
            consumer.setMessageListener(this);

If I however change it to be non-transacted on the Spring consumer, I still
do not receive the messages.

Thanks in advance for any assitance.


James.Strachan wrote:
> 
> It looks like you're creating a transactional session and never
> calling commit().
> 
> On 09/11/2007, CobraTheSleek <ka...@yahoo.com> wrote:
>>
>> Hi,
>>
>> ENV:
>> ActiveMQ-Snapshot-5.0
>> JBoss AS 4.2.1
>>
>> I have the following queues defined:
>>
>>  <mbean code="org.jboss.resource.deployment.AdminObject"
>> name="activemq.queue:name=org.apache.activemq.requestQueue">
>>            <attribute name="JNDIName">activemq/requestQueue</attribute>
>>       <depends
>> optional-attribute-name="RARName">jboss.jca:service=RARDeployment,name='activemq-ra.rar'</depends>
>>       <attribute name="Type">javax.jms.Queue</attribute>
>>       <attribute
>> name="Properties">PhysicalName=org.apache.activemq.requestQueue</attribute>
>>    </mbean>
>>
>>    <mbean code="org.jboss.resource.deployment.AdminObject"
>> name="activemq.queue:name=org.apache.activemq.replyQueue">
>>            <attribute
>> name="JNDIName">activemq/echoResponseQueue</attribute>
>>       <depends
>> optional-attribute-name="RARName">jboss.jca:service=RARDeployment,name='activemq-ra.rar'</depends>
>>       <attribute name="Type">javax.jms.Queue</attribute>
>>       <attribute
>> name="Properties">PhysicalName=org.apache.activemq.replyQueue</attribute>
>>    </mbean>
>>
>> I have an MDB defined that listens for messages from the requestQueue and
>> posts a response on the replyQueue.
>>
>> I am using the Spring unit tests provided (Producer and Consumer) and my
>> Producer sends messages to the requestQueue, the MDB receives the request
>> and posts a message back on to the replyQueue.
>>
>> I can see that there are messages in the replyQueue via JMX. However, my
>> Consumer never receives messages from the replyQueue.
>>
>> If I run the test without the MDB, by placing messages in the replyQueue
>> via
>> the PRODUCER, my Consumer receives the messages successfully. In other
>> words
>> messages posted by the MDB are never received by the consumer.
>>
>> The following is what my MDB does to place messages back on the reply
>> queue:
>>
>> InitialContext initCtx = new InitialContext();
>>
>>         QueueConnectionFactory qcf = (QueueConnectionFactory) initCtx
>>                 .lookup("java:comp/env/jms/MyQueueConnectionFactory");
>>
>>         QueueConnection qcon = qcf.createQueueConnection();
>>         QueueSession qsession = qcon.createQueueSession(true, 0);
>>         Queue q = (Queue) initCtx.lookup("activemq/replyQueue");
>>         QueueSender qsender = qsession.createSender(q);
>>
>>         TextMessage message = qsession.createTextMessage();
>>
>>         message.setText(response);
>>         qsender.setTimeToLive(100000000);
>>         qsender.send(message);
>>
>>         qsender.close();
>>         qsession.close();
>>         qcon.close();
>>
>>
>> I am quite confused as to why this is happening as I see messages as
>> being
>> available in the replyQueue.
>> Any tips would be appreciated.
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Messages-not-being-received-by-consumer-tf4779201s2354.html#a13672078
>> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>>
>>
> 
> 
> -- 
> James
> -------
> http://macstrac.blogspot.com/
> 
> Open Source SOA
> http://open.iona.com
> 
> 

-- 
View this message in context: http://www.nabble.com/Messages-not-being-received-by-consumer-tf4779201s2354.html#a13706889
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Messages not being received by consumer

Posted by James Strachan <ja...@gmail.com>.
It looks like you're creating a transactional session and never
calling commit().

On 09/11/2007, CobraTheSleek <ka...@yahoo.com> wrote:
>
> Hi,
>
> ENV:
> ActiveMQ-Snapshot-5.0
> JBoss AS 4.2.1
>
> I have the following queues defined:
>
>  <mbean code="org.jboss.resource.deployment.AdminObject"
> name="activemq.queue:name=org.apache.activemq.requestQueue">
>            <attribute name="JNDIName">activemq/requestQueue</attribute>
>       <depends
> optional-attribute-name="RARName">jboss.jca:service=RARDeployment,name='activemq-ra.rar'</depends>
>       <attribute name="Type">javax.jms.Queue</attribute>
>       <attribute
> name="Properties">PhysicalName=org.apache.activemq.requestQueue</attribute>
>    </mbean>
>
>    <mbean code="org.jboss.resource.deployment.AdminObject"
> name="activemq.queue:name=org.apache.activemq.replyQueue">
>            <attribute name="JNDIName">activemq/echoResponseQueue</attribute>
>       <depends
> optional-attribute-name="RARName">jboss.jca:service=RARDeployment,name='activemq-ra.rar'</depends>
>       <attribute name="Type">javax.jms.Queue</attribute>
>       <attribute
> name="Properties">PhysicalName=org.apache.activemq.replyQueue</attribute>
>    </mbean>
>
> I have an MDB defined that listens for messages from the requestQueue and
> posts a response on the replyQueue.
>
> I am using the Spring unit tests provided (Producer and Consumer) and my
> Producer sends messages to the requestQueue, the MDB receives the request
> and posts a message back on to the replyQueue.
>
> I can see that there are messages in the replyQueue via JMX. However, my
> Consumer never receives messages from the replyQueue.
>
> If I run the test without the MDB, by placing messages in the replyQueue via
> the PRODUCER, my Consumer receives the messages successfully. In other words
> messages posted by the MDB are never received by the consumer.
>
> The following is what my MDB does to place messages back on the reply queue:
>
> InitialContext initCtx = new InitialContext();
>
>         QueueConnectionFactory qcf = (QueueConnectionFactory) initCtx
>                 .lookup("java:comp/env/jms/MyQueueConnectionFactory");
>
>         QueueConnection qcon = qcf.createQueueConnection();
>         QueueSession qsession = qcon.createQueueSession(true, 0);
>         Queue q = (Queue) initCtx.lookup("activemq/replyQueue");
>         QueueSender qsender = qsession.createSender(q);
>
>         TextMessage message = qsession.createTextMessage();
>
>         message.setText(response);
>         qsender.setTimeToLive(100000000);
>         qsender.send(message);
>
>         qsender.close();
>         qsession.close();
>         qcon.close();
>
>
> I am quite confused as to why this is happening as I see messages as being
> available in the replyQueue.
> Any tips would be appreciated.
>
> --
> View this message in context: http://www.nabble.com/Messages-not-being-received-by-consumer-tf4779201s2354.html#a13672078
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>
>


-- 
James
-------
http://macstrac.blogspot.com/

Open Source SOA
http://open.iona.com