You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by neelam <ne...@emc.com> on 2015/09/21 20:10:59 UTC

Not able to receive the events in the client

Hi All,

I have a requirement where I need to monitor active MQ events. For this I
have created two Java clients, 1st where I publish the events and 2nd where
I listen to the events and receive those. Both the clients are running in
the same linux server.
I am able to post the events to the queue but I don't receive them at the
same time as if I run both the clients simultaneously it gives me the error
that activeMQ is locked. If I publish first and then run the other client to
receive the events it works fine. How can I resolve this issue? My
requirement is to continuously monitor the events in the queue.
My publish method is as below:
        public void publish(ResourceIdentityInfo rii) {
        try {
                if (topic == null) {
                                initialize();
                        }
                topicConnection = factory.createTopicConnection("system",
"system-pw");
                
                topicConnection.start();
                
                topicSession = topicConnection.createTopicSession(false,
Session.AUTO_ACKNOWLEDGE);
                MessageProducer producer =
topicSession.createProducer(topic);
                TextMessage message = topicSession.createTextMessage();

                message.setText("JOBID:" +rii.getResourceName()+" IS
SCHEDULED");
                // Here we are sending the message!
                producer.setDeliveryMode(javax.jms.DeliveryMode.PERSISTENT);
               
                producer.send(message);
                System.out.println("Sent message '" + message.getText() +
"'");
                topicSession.close();
               topicConnection.close();

                }

listener is as below:

        public void  listen() {
        try {
                if (topic == null) {
                        System.out.println("topic is null...");
                                initialize();
                        }
                topicConnection = factory.createTopicConnection("system",
"system-pw");
                topicConnection.setClientID("123");
                System.out.println("Connection obtained " +
topicConnection);

                topicSession = topicConnection.createTopicSession(false,
Session.AUTO_ACKNOWLEDGE);

                MessageConsumer consumer =
topicSession.createDurableSubscriber(topic,"TestConnection123");
                 topicConnection.start();
                System.out.println("Connection started!" + topicConnection);


                MessageListener listner = new MessageListener() {
                    public void onMessage(Message message) {
                        try {
                        System.out.println("Entered OnMessage..");
                        if (message instanceof TextMessage) {
                        TextMessage textMessage = (TextMessage) message;
                        System.out.println("Received message"
                                + textMessage.getText() + "'");
                                }
                        } catch (JMSException e) {
                        System.out.println("Caught:" + e);
                        e.printStackTrace();
                        }
                }
                };

                consumer.setMessageListener(listner);
                System.in.read();
                topicSession.close();
                topicConnection.close();
            }


config.properties is as below:
cc.remoting.servlet.base=http://server_hostname:8881/ncm-webapp/remoting/
jms.java.naming.provider.url=vm:broker:(vm://server_hostname:61616)
jms.java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory
com.powerup.configmgr.server.default.jms.connection.factory=ConnectionFactory
com.powerup.configmgr.server.default.jms.queue.connection.factory=QueueConnectionFactory
com.powerup.configmgr.server.default.jms.topic.connection.factory=TopicConnectionFactory
com.powerup.configmgr.server.default.jms.user.name=system
com.powerup.configmgr.server.default.jms.user.password=system-pw

Regards
Neelam




--
View this message in context: http://activemq.2283324.n4.nabble.com/Not-able-to-receive-the-events-in-the-client-tp4702144.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Not able to receive the events in the client

Posted by Christopher Shannon <ch...@gmail.com>.
What is the exact error message that you are getting?  Is there a stack
trace?

On Mon, Sep 21, 2015 at 2:10 PM, neelam <ne...@emc.com> wrote:

> Hi All,
>
> I have a requirement where I need to monitor active MQ events. For this I
> have created two Java clients, 1st where I publish the events and 2nd where
> I listen to the events and receive those. Both the clients are running in
> the same linux server.
> I am able to post the events to the queue but I don't receive them at the
> same time as if I run both the clients simultaneously it gives me the error
> that activeMQ is locked. If I publish first and then run the other client
> to
> receive the events it works fine. How can I resolve this issue? My
> requirement is to continuously monitor the events in the queue.
> My publish method is as below:
>         public void publish(ResourceIdentityInfo rii) {
>         try {
>                 if (topic == null) {
>                                 initialize();
>                         }
>                 topicConnection = factory.createTopicConnection("system",
> "system-pw");
>
>                 topicConnection.start();
>
>                 topicSession = topicConnection.createTopicSession(false,
> Session.AUTO_ACKNOWLEDGE);
>                 MessageProducer producer =
> topicSession.createProducer(topic);
>                 TextMessage message = topicSession.createTextMessage();
>
>                 message.setText("JOBID:" +rii.getResourceName()+" IS
> SCHEDULED");
>                 // Here we are sending the message!
>
> producer.setDeliveryMode(javax.jms.DeliveryMode.PERSISTENT);
>
>                 producer.send(message);
>                 System.out.println("Sent message '" + message.getText() +
> "'");
>                 topicSession.close();
>                topicConnection.close();
>
>                 }
>
> listener is as below:
>
>         public void  listen() {
>         try {
>                 if (topic == null) {
>                         System.out.println("topic is null...");
>                                 initialize();
>                         }
>                 topicConnection = factory.createTopicConnection("system",
> "system-pw");
>                 topicConnection.setClientID("123");
>                 System.out.println("Connection obtained " +
> topicConnection);
>
>                 topicSession = topicConnection.createTopicSession(false,
> Session.AUTO_ACKNOWLEDGE);
>
>                 MessageConsumer consumer =
> topicSession.createDurableSubscriber(topic,"TestConnection123");
>                  topicConnection.start();
>                 System.out.println("Connection started!" +
> topicConnection);
>
>
>                 MessageListener listner = new MessageListener() {
>                     public void onMessage(Message message) {
>                         try {
>                         System.out.println("Entered OnMessage..");
>                         if (message instanceof TextMessage) {
>                         TextMessage textMessage = (TextMessage) message;
>                         System.out.println("Received message"
>                                 + textMessage.getText() + "'");
>                                 }
>                         } catch (JMSException e) {
>                         System.out.println("Caught:" + e);
>                         e.printStackTrace();
>                         }
>                 }
>                 };
>
>                 consumer.setMessageListener(listner);
>                 System.in.read();
>                 topicSession.close();
>                 topicConnection.close();
>             }
>
>
> config.properties is as below:
> cc.remoting.servlet.base=http://server_hostname:8881/ncm-webapp/remoting/
> jms.java.naming.provider.url=vm:broker:(vm://server_hostname:61616)
>
> jms.java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory
>
> com.powerup.configmgr.server.default.jms.connection.factory=ConnectionFactory
>
> com.powerup.configmgr.server.default.jms.queue.connection.factory=QueueConnectionFactory
>
> com.powerup.configmgr.server.default.jms.topic.connection.factory=TopicConnectionFactory
> com.powerup.configmgr.server.default.jms.user.name=system
> com.powerup.configmgr.server.default.jms.user.password=system-pw
>
> Regards
> Neelam
>
>
>
>
> --
> View this message in context:
> http://activemq.2283324.n4.nabble.com/Not-able-to-receive-the-events-in-the-client-tp4702144.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>