You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by rogerroger <tr...@gmail.com> on 2012/04/01 23:54:54 UTC

onmessage not picking up messages

Hi

I am using tomee plus and it's active mq version.  I have started a broker,
verified by 'telnet localhost 61616' and added topic and connection factory
using openejb.xml resource elements.  I am able to send messages to the
broker, verified with the jConsole, but none are consumed.  The same code
worked using tomcat 7.11 and active mc core jar 5.5.1. I am starting up the
consumers using a servlet listener.  Yes, I have remembered the
connection.start() and there is only one consumer in the code.

Help is appreciated.



--
View this message in context: http://activemq.2283324.n4.nabble.com/onmessage-not-picking-up-messages-tp4524534p4524534.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: onmessage not picking up messages

Posted by rogerroger <tr...@gmail.com>.
This is the listener startup code, started by a servlet listener.  The 'Queue
Setup done' is printed to the console, no errors:

    public TestMyQueueListener startTestQueueConsumer() {
        try {
            if (testMyQueueListener == null) {
                testMyQueueListener = new TestMyQueueListener();
            }
            InitialContext initCtx = new InitialContext();
            //Context envContext = (Context)
initCtx.lookup("java:comp/env");
            QueueConnectionFactory connectionFactory =
(QueueConnectionFactory)
initCtx.lookup("openejb:Resource/MyJmsConnectionFactory");
            QueueConnection connection =
connectionFactory.createQueueConnection();
            Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
            MessageConsumer consumer = session.createConsumer((Destination)
initCtx.lookup("openejb:Resource/MyQueue"));

            consumer.setMessageListener(testMyQueueListener);
            connection.start();
            System.out.println("Queue Setup done");
        } catch (NamingException ex) {
            ex.printStackTrace();
        } catch (JMSException ex) {
           ex.printStackTrace();
        }
        return testMyQueueListener;
    }

public class TestMyQueueListener implements MessageListener {

  
    public void onMessage(Message message) {
         if (message instanceof TextMessage) {
            TextMessage textMessage = (TextMessage) message;
            try {
                System.out.println(textMessage.getText());
            } catch (JMSException ex) {
                ex.printStackTrace();
            }
        }
    }
}


--
View this message in context: http://activemq.2283324.n4.nabble.com/onmessage-not-picking-up-messages-tp4524534p4526352.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: onmessage not picking up messages

Posted by Torsten Mielke <to...@fusesource.com>.
Its a bit difficult to follow your observations. However forget about the ActiveMQ.Advisory.* topics, these are just advisory channels (http://activemq.apache.org/advisory-message.html).

Your code snippet below seems to send a message to a queue called MyQueue. If the consumerCount for that destination is constantly at 0, then there is no consumer connected and hence the messages will not get dispatched but remain on the queue. 

You will need to look at your consumer side code and try to understand why is it not connecting to MyQueue? Does it perhaps connect to MyTopic instead? Or to some other destination? Or does not connect a consumer to the broker at all?


Regards,
Torsten





On Apr 2, 2012, at 2:42 PM, rogerroger wrote:

> Param 'DestinationName' on the message I send(find it in JMX) has
> ActiveMQ.Advisory.TempTopic and TempQueue, not MyQueue.  It is listed under
> Subscription.Non-Durable.Topic...
> 
> 
> I am using this code to produce the message(Can you see why it isn't
> published on MyTopic?):
> 
> 
> String message = "test message";
> Session session = getSession(getQueueConnection());
> TextMessage textMessage = session.createTextMessage();
> textMessage.setText("Sending to queue: "+message);
> getProducer(session, "openejb:Resource/MyQueue").send(textMessage);
> System.out.println("Queue Message w/ id:"+textMessage.getJMSMessageID()+"
> sent");
> 
> 	private Context envContext = null;
> 
> 	private Context getEnvContext() throws NamingException {
> 		if (envContext == null) {
> 			envContext = new InitialContext();
> 			// envContext = (Context) initCtx.lookup("java:comp/env");
> 		}
> 		return envContext;
> 	}
> 
> 	private ConnectionFactory connectionFactory;
> 
> 	private TopicConnection getTopicConnection() throws NamingException,
> 			JMSException {
> 		if (connectionFactory == null) {
> 			connectionFactory = (ConnectionFactory) getEnvContext().lookup(
> 					"openejb:Resource/MyJmsConnectionFactory");
> 		}
> 		return (TopicConnection) connectionFactory.createConnection();
> 
> 	}
> 
> 	private QueueConnection getQueueConnection() throws NamingException,
> 			JMSException {
> 		if (connectionFactory == null) {
> 			connectionFactory = (ConnectionFactory) getEnvContext().lookup(
> 					"openejb:Resource/MyJmsConnectionFactory");
> 		}
> 		return (QueueConnection) connectionFactory.createConnection();
> 
> 	}
> 
> 	private MessageProducer getProducer(Session session, String topicOrQueue)
> 			throws NamingException, JMSException {
> 		MessageProducer producer = session
> 				.createProducer((Destination) getEnvContext().lookup(
> 						topicOrQueue));
> 		return producer;
> 
> 	}
> 
> 	private Session getSession(Connection connection) throws JMSException {
> 		return connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
> 	}
> 
> 
> and this in openejb.xml:
> 
> 
> 	 <Resource id="MyJmsResourceAdapter" type="ActiveMQResourceAdapter">
>        BrokerXmlConfig =  broker:(tcp://localhost:61616)
>        ServerUrl       =  tcp://localhost:61616
>    </Resource>
> 
>    <Resource id="MyJmsConnectionFactory"
> type="javax.jms.ConnectionFactory">
>        ResourceAdapter = MyJmsResourceAdapter
>    </Resource>
> 
>    <Container id="MyJmsMdbContainer" ctype="MESSAGE">
>        ResourceAdapter = MyJmsResourceAdapter
>    </Container>
> 
>    <Resource id="MyQueue" type="javax.jms.Queue"/>
>    <Resource id="MyTopic" type="javax.jms.Topic"/>
> 
> 
> 
> Torsten Mielke-2 wrote
>> 
>> Hi,
>> 
>> Check using jconsole that a consumer is registered on the destination that
>> you want to consume from. 
>> If its not registered, then there is most likely a problem with your
>> consumer code.
>> 
>> 
>> Hope this serves as a starting point.
>> 
>> 
>> Torsten Mielke
>> torsten@
>> tmielke@
>> 
>> 
>> On Apr 1, 2012, at 11:54 PM, rogerroger wrote:
>> 
>>> Hi
>>> 
>>> I am using tomee plus and it's active mq version.  I have started a
>>> broker,
>>> verified by 'telnet localhost 61616' and added topic and connection
>>> factory
>>> using openejb.xml resource elements.  I am able to send messages to the
>>> broker, verified with the jConsole, but none are consumed.  The same code
>>> worked using tomcat 7.11 and active mc core jar 5.5.1. I am starting up
>>> the
>>> consumers using a servlet listener.  Yes, I have remembered the
>>> connection.start() and there is only one consumer in the code.
>>> 
>>> Help is appreciated.
>>> 
>>> 
>>> 
>>> --
>>> View this message in context:
>>> http://activemq.2283324.n4.nabble.com/onmessage-not-picking-up-messages-tp4524534p4524534.html
>>> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>> 
> 
> 
> 
> 
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/onmessage-not-picking-up-messages-tp4524534p4525904.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Torsten Mielke
torsten@fusesource.com
tmielke@blogspot.com




Re: onmessage not picking up messages

Posted by rogerroger <tr...@gmail.com>.
Param 'DestinationName' on the message I send(find it in JMX) has
ActiveMQ.Advisory.TempTopic and TempQueue, not MyQueue.  It is listed under
Subscription.Non-Durable.Topic...


I am using this code to produce the message(Can you see why it isn't
published on MyTopic?):


String message = "test message";
Session session = getSession(getQueueConnection());
TextMessage textMessage = session.createTextMessage();
textMessage.setText("Sending to queue: "+message);
getProducer(session, "openejb:Resource/MyQueue").send(textMessage);
System.out.println("Queue Message w/ id:"+textMessage.getJMSMessageID()+"
sent");

	private Context envContext = null;

	private Context getEnvContext() throws NamingException {
		if (envContext == null) {
			envContext = new InitialContext();
			// envContext = (Context) initCtx.lookup("java:comp/env");
		}
		return envContext;
	}

	private ConnectionFactory connectionFactory;

	private TopicConnection getTopicConnection() throws NamingException,
			JMSException {
		if (connectionFactory == null) {
			connectionFactory = (ConnectionFactory) getEnvContext().lookup(
					"openejb:Resource/MyJmsConnectionFactory");
		}
		return (TopicConnection) connectionFactory.createConnection();

	}

	private QueueConnection getQueueConnection() throws NamingException,
			JMSException {
		if (connectionFactory == null) {
			connectionFactory = (ConnectionFactory) getEnvContext().lookup(
					"openejb:Resource/MyJmsConnectionFactory");
		}
		return (QueueConnection) connectionFactory.createConnection();

	}

	private MessageProducer getProducer(Session session, String topicOrQueue)
			throws NamingException, JMSException {
		MessageProducer producer = session
				.createProducer((Destination) getEnvContext().lookup(
						topicOrQueue));
		return producer;

	}

	private Session getSession(Connection connection) throws JMSException {
		return connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
	}


and this in openejb.xml:


	 <Resource id="MyJmsResourceAdapter" type="ActiveMQResourceAdapter">
        BrokerXmlConfig =  broker:(tcp://localhost:61616)
        ServerUrl       =  tcp://localhost:61616
    </Resource>

    <Resource id="MyJmsConnectionFactory"
type="javax.jms.ConnectionFactory">
        ResourceAdapter = MyJmsResourceAdapter
    </Resource>

    <Container id="MyJmsMdbContainer" ctype="MESSAGE">
        ResourceAdapter = MyJmsResourceAdapter
    </Container>

    <Resource id="MyQueue" type="javax.jms.Queue"/>
    <Resource id="MyTopic" type="javax.jms.Topic"/>
    


Torsten Mielke-2 wrote
> 
> Hi,
> 
> Check using jconsole that a consumer is registered on the destination that
> you want to consume from. 
> If its not registered, then there is most likely a problem with your
> consumer code.
> 
> 
> Hope this serves as a starting point.
> 
> 
> Torsten Mielke
> torsten@
> tmielke@
> 
> 
> On Apr 1, 2012, at 11:54 PM, rogerroger wrote:
> 
>> Hi
>> 
>> I am using tomee plus and it's active mq version.  I have started a
>> broker,
>> verified by 'telnet localhost 61616' and added topic and connection
>> factory
>> using openejb.xml resource elements.  I am able to send messages to the
>> broker, verified with the jConsole, but none are consumed.  The same code
>> worked using tomcat 7.11 and active mc core jar 5.5.1. I am starting up
>> the
>> consumers using a servlet listener.  Yes, I have remembered the
>> connection.start() and there is only one consumer in the code.
>> 
>> Help is appreciated.
>> 
>> 
>> 
>> --
>> View this message in context:
>> http://activemq.2283324.n4.nabble.com/onmessage-not-picking-up-messages-tp4524534p4524534.html
>> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
> 




--
View this message in context: http://activemq.2283324.n4.nabble.com/onmessage-not-picking-up-messages-tp4524534p4525904.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: onmessage not picking up messages

Posted by rogerroger <tr...@gmail.com>.
Also, there are two consumers listed under 'Topic' folder as
'ActiveMQ.Advisory.Consumer.Queue.MyQueue' and
'ActiveMQ.Advisory.Consumer.Topic.MyTopic' and when I send messages, new
entries in the monitor occur as 'ActiveMQ.Advisory.Producer .. Queue.MyQueue
and Topic.MyTopic'.  The topic and queue I referred to in the previous post
are simply denoted by 'MyTopic' and 'MyQueue'

Both advisory consumers have the value 2 for 'EnqueueCount' allthough I have
only sent one message.  Could there be a blocking problem or is it just
previous persisted messages in the KahaDB?

--
View this message in context: http://activemq.2283324.n4.nabble.com/onmessage-not-picking-up-messages-tp4524534p4525387.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: onmessage not picking up messages

Posted by rogerroger <tr...@gmail.com>.
There is a MyTopic and a MyQueue and both have 'ConsumerCount' set to 1 at
startup. However I noticed that 'ProducerCount' is set to 0 for both. Also,
when I send messages the 'ConsumerCount' goes to zero and the
'ProducerCount' goes to the number of messages sent.  Same as
'EnqueueCount'.

--
View this message in context: http://activemq.2283324.n4.nabble.com/onmessage-not-picking-up-messages-tp4524534p4525343.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: onmessage not picking up messages

Posted by rogerroger <tr...@gmail.com>.
I suppose doing it using the failing pattern makes it more vulnerable to
classloader issues.  

--
View this message in context: http://activemq.2283324.n4.nabble.com/onmessage-not-picking-up-messages-tp4524534p4529293.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: onmessage not picking up messages

Posted by rogerroger <tr...@gmail.com>.
It works when doing this:

subscriber.setMessageListener(this);

and not this:


subscriber.setMessageListener(myListenerImpl);


The last way of doing it has the jndi lookups outside of the myListenerImpl.

This method works in regular tomcat with active mq jar 5.5.1.  Strange thing
is that the BrokerVersion in tomee plus is also 5.5.1

If this makes sense to anyone, please let me know.

--
View this message in context: http://activemq.2283324.n4.nabble.com/onmessage-not-picking-up-messages-tp4524534p4529208.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: onmessage not picking up messages

Posted by Torsten Mielke <to...@fusesource.com>.
Hi,

Check using jconsole that a consumer is registered on the destination that you want to consume from. 
If its not registered, then there is most likely a problem with your consumer code.


Hope this serves as a starting point.


Torsten Mielke
torsten@fusesource.com
tmielke@blogspot.com


On Apr 1, 2012, at 11:54 PM, rogerroger wrote:

> Hi
> 
> I am using tomee plus and it's active mq version.  I have started a broker,
> verified by 'telnet localhost 61616' and added topic and connection factory
> using openejb.xml resource elements.  I am able to send messages to the
> broker, verified with the jConsole, but none are consumed.  The same code
> worked using tomcat 7.11 and active mc core jar 5.5.1. I am starting up the
> consumers using a servlet listener.  Yes, I have remembered the
> connection.start() and there is only one consumer in the code.
> 
> Help is appreciated.
> 
> 
> 
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/onmessage-not-picking-up-messages-tp4524534p4524534.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.