ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » IBM MQ Java / JMS » IBMMQ listener is not running continuously

Post new topic  Reply to topic
 IBMMQ listener is not running continuously « View previous topic :: View next topic » 
Author Message
mchaudhari
PostPosted: Wed Feb 02, 2011 1:32 am    Post subject: IBMMQ listener is not running continuously Reply with quote

Newbie

Joined: 01 Feb 2011
Posts: 2

Hi,
I have a requirement where my IBMMQ listener should run continuously and keep listening messages still I stop it forcefully.

I am not using any server; it’s just a simple JAVA file which should keep running continuously in background.

Thanks
Mahesh Chaudhari.

Code:
//MainClass
public class QTPStarter
{
public static MQQueueConnectionFactory m_connectionFactory = null;
public static QueueConnection m_connection = null;
public static void main(String[] args) throws Exception
{
String w_queueManager = args[1];
String w_queueHostname = args[2];
String w_queueChannel = args[3];
String w_queuePortNumber = args[4];
m_connectionFactory = new MQQueueConnectionFactory();
m_connectionFactory.setTransportType(JMSC.MQJMS_TP_CLIENT_MQ_TCPIP);
m_connectionFactory.setQueueManager(w_queueManager);
m_connectionFactory.setHostName(w_queueHostname);
m_connectionFactory.setChannel(w_queueChannel);
m_connectionFactory.setPort(Integer.parseInt(w_queuePortNumber));
m_connection = m_connectionFactory.createQueueConnection();
boolean transacted = false;
QueueSession w_session = m_connection.createQueueSession(transacted,Session.AUTO_ACKNOWLEDGE);
Queue w_rubiToswireMsgQueue = w_session.createQueue("My QueueName");
QueueReceiver w_rubiToswireMsgConsumer = w_session.createReceiver(w_rubiToswireMsgQueue);
QTPReceiver w_qtp_receiver = new QTPReceiver();
w_rubiToswireMsgConsumer.setMessageListener(w_qtp_receiver);
m_connection.start();

}

//Listner Class
public class QTPReceiver implements MessageListener
{
public void onMessage(Message a_receivedXml)
{
try
{
System.out.println(GlobalConstant.DATEFORMAT.format(new java.util.Date())+":XML Received:");
TextMessage w_xmlMessage = (TextMessage) a_receivedXml;
//storeXML(w_xmlMessage.getText());
}
catch (Exception e)
{
e.printStackTrace();
}
}

public void onException(JMSException e)
{
System.out.println("Error found");
e.printStackTrace();
}
}
Back to top
View user's profile Send private message
Vitor
PostPosted: Wed Feb 02, 2011 5:03 am    Post subject: Re: IBMMQ listener is not running continuously Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

mchaudhari wrote:
I have a requirement where my IBMMQ listener should run continuously and keep listening messages still I stop it forcefully.


Well you're not going to be making any friends in your MQ admin team. If your application continiously listens for messages it'll stop them performing an orderly closedown of the queue manager unless they happen to know about your listener and how to stop it. As a minimum you should code it to respond to shutdown commands from the queue manager.

Given that, and glossing over the desirability of this design, was there a question? What you're describing is a straightforward enough application & the code (though I'm no expert in Java) seems reasonable enough. What happens when you try it? You say in the title not running continiously but what happens? Error messages? Unexpected crashes? Death threats from the admin team?

Better information, better advice
_________________
Honesty is the best policy.
Insanity is the best defence.


Last edited by Vitor on Thu Feb 03, 2011 5:44 am; edited 1 time in total
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Wed Feb 02, 2011 10:52 am    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

Looks like a good solid JMS MessageListener design.
However you did not implement an ExceptionListener with the connection.
As such when the connection breaks your message Listener and the rest of your application are out of the loop.

You need to design in such a way that a call to the ExceptionListener allows you to perform a shutdown of the MessageListener, a controlled release of the resources, and reacquire the resources (perhaps after a growing sleep interval?)

Have fun
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
mqjeff
PostPosted: Wed Feb 02, 2011 11:03 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

Perhaps this is me being out of my depth in Java/JMS, but isn't the connection.start() method going to complete immediately, rather than delay until the connection is stopped?

If that's the case, isn't the program going to then immediately end, since the main() method has finished?
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Wed Feb 02, 2011 11:07 am    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

mqjeff wrote:
Perhaps this is me being out of my depth in Java/JMS, but isn't the connection.start() method going to complete immediately, rather than delay until the connection is stopped?

If that's the case, isn't the program going to then immediately end, since the main() method has finished?


Dah I did not check that .... This should be a runnable and finish when the corresponding signal is being passed...
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
mchaudhari
PostPosted: Thu Feb 03, 2011 2:42 am    Post subject: Re: IBMMQ listener is not running continuously Reply with quote

Newbie

Joined: 01 Feb 2011
Posts: 2

Vitor wrote:
mchaudhari wrote:
I have a requirement where my IBMMQ listener should run continuously and keep listening messages still I stop it forcefully.


Well you're not going to be making any friends in your MQ admin team. If your application continiously listens for messages it'll stop them performing an orderly closedown of the queue manager unless they happen to know about your listener and how to stop it. As a minimum you should code it to respond to shutdown commands from the queue manager.

Given that, and glossing over the desirability of this design, was there a question? What you're describing is a straightforward enough application & the code (though I'm no expert in Java) seems reasonable enough. What happens when you try it? You say in the title not running continiously but what happens? Error messages? Unexpected crashes? Death threats from the admin team?

Better information, better advice


Thanks Vitor,

I am not so expert in JMS coding, but the similar code works for activeMQ i.e. after connection.start() the main thread keeps running still I close the process (java.exe) from task manager,and keep excuting onMessage() {} whenever message comes without an error.
This same code also runns propely for IBM MQ but after connection.start() the main thread dies (without an error ) and there is no process java in taskmanager as well.

What want is some how the code should run as it is running for ActiveMQ and do the samething.

looking fwd for reply form all u guys..

Thanks
Mahesh Chaudhari (9821932258)
Back to top
View user's profile Send private message
Vitor
PostPosted: Thu Feb 03, 2011 5:48 am    Post subject: Re: IBMMQ listener is not running continuously Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

mchaudhari wrote:
What want is some how the code should run as it is running for ActiveMQ and do the samething.


As I indicated above, the WMQ admin may not enjoy this code quite as much as WMQ works differently under the covers to ActiveMQ.

As I also indicated above, I'm not really qualified to speak on Java matters but will fall in line with the comments of my most worthy associates regarding the code.

Is this a standalone Java app (as I believe you're indicating) or is there any intention to run it as an MDB under an app server?
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
mqjeff
PostPosted: Thu Feb 03, 2011 6:51 am    Post subject: Re: IBMMQ listener is not running continuously Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

mchaudhari wrote:
This same code also runns propely for IBM MQ but after connection.start() the main thread dies (without an error ) and there is no process java in taskmanager as well.


As I said, connection.start() is completing, not remaining in execution until the connection ends. The main thread does not then "die", it COMPLETES because you've not done anything after connection.start().

mchaudhari wrote:
Mahesh Chaudhari (phonenumberelided)

Absolutely nobody is going to call you based on a posting here.

If you want personal assistance, please hire a consultant.
Back to top
View user's profile Send private message
Vitor
PostPosted: Thu Feb 03, 2011 6:53 am    Post subject: Re: IBMMQ listener is not running continuously Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

mqjeff wrote:
mchaudhari wrote:
Mahesh Chaudhari (phonenumberelided)

Absolutely nobody is going to call you based on a posting here.


Or if they do, they may not be discussing WMQ.....
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
mqjeff
PostPosted: Thu Feb 03, 2011 6:55 am    Post subject: Re: IBMMQ listener is not running continuously Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

Vitor wrote:
mqjeff wrote:
mchaudhari wrote:
Mahesh Chaudhari (phonenumberelided)

Absolutely nobody is going to call you based on a posting here.


Or if they do, they may not be discussing WMQ.....


NOT ONLY will these pills increase the *uptime* of your queue manager, they'll also significantly increase your capacity to meet your SLAs.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Thu Feb 03, 2011 7:14 am    Post subject: Re: IBMMQ listener is not running continuously Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

mchaudhari wrote:

I am not so expert in JMS coding, but the similar code works for activeMQ i.e. after connection.start() the main thread keeps running still I close the process (java.exe) from task manager,and keep executing onMessage() {} whenever message comes without an error.
This same code also runs propely for IBM MQ but after connection.start() the main thread dies (without an error ) and there is no process java in taskmanager as well.

What want is some how the code should run as it is running for ActiveMQ and do the samething.

looking fwd for reply form all u guys..

Thanks
Mahesh Chaudhari (9821932258)


Don't know what activeMQ does behind the scenes of its connection.start() method.
As a standalone JMS program you should create a runnable with an additional method to break out of the loop you enter in the run method.
Thus you will stay alive as long as the run method executes and the onMessage will get triggered when needed.

And please remember to clean up the resources used. You will need to add those calls to your code at the appropriate timing too.

Have fun
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ Java / JMS » IBMMQ listener is not running continuously
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.