Author |
Message
|
mchaudhari |
Posted: Wed Feb 02, 2011 1:32 am Post subject: IBMMQ listener is not running continuously |
|
|
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 |
|
 |
Vitor |
Posted: Wed Feb 02, 2011 5:03 am Post subject: Re: IBMMQ listener is not running continuously |
|
|
 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 |
|
 |
fjb_saper |
Posted: Wed Feb 02, 2011 10:52 am Post subject: |
|
|
 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 |
|
 |
mqjeff |
Posted: Wed Feb 02, 2011 11:03 am Post subject: |
|
|
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 |
|
 |
fjb_saper |
Posted: Wed Feb 02, 2011 11:07 am Post subject: |
|
|
 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 |
|
 |
mchaudhari |
Posted: Thu Feb 03, 2011 2:42 am Post subject: Re: IBMMQ listener is not running continuously |
|
|
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 |
|
 |
Vitor |
Posted: Thu Feb 03, 2011 5:48 am Post subject: Re: IBMMQ listener is not running continuously |
|
|
 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 |
|
 |
mqjeff |
Posted: Thu Feb 03, 2011 6:51 am Post subject: Re: IBMMQ listener is not running continuously |
|
|
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 |
|
 |
Vitor |
Posted: Thu Feb 03, 2011 6:53 am Post subject: Re: IBMMQ listener is not running continuously |
|
|
 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 |
|
 |
mqjeff |
Posted: Thu Feb 03, 2011 6:55 am Post subject: Re: IBMMQ listener is not running continuously |
|
|
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 |
|
 |
fjb_saper |
Posted: Thu Feb 03, 2011 7:14 am Post subject: Re: IBMMQ listener is not running continuously |
|
|
 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 |
|
 |
|