activemq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From neelam <neelam.ba...@emc.com>
Subject Not able to receive messages in client
Date Mon, 21 Sep 2015 18:12:57 GMT
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-messages-in-client-tp4702145.html
Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.

Mime
View raw message