Author |
Message
|
santhosh_fischer |
Posted: Tue Aug 10, 2004 10:00 pm Post subject: problems in Asynchronous Messaging.... |
|
|
Novice
Joined: 05 Aug 2004 Posts: 13
|
i tried creating a meeage listener for a particular queue. but the code never calls the OnMessage ..
..this is working fine in synchronous way using the recieve function..
can anyone give me suggestions....
..
is there anything extra to do for putting a listener for a queue..
.
code is listed below..
-----------------------------------------------------------------------
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.*;
import javax.naming.*;
import com.ibm.mq.jms.*;
import com.ibm.mq.*;
/*
* Created on Aug 9, 2004
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
/**
* @author Administrator
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class fiscQueueReciever {
String queueName = null;
Context jndiContext = null;
QueueConnectionFactory queueConnectionFactory = null;
QueueConnection queueConnection = null;
QueueSession queueSession = null;
Queue queue = null;
QueueSender queueSender = null;
QueueReceiver queueReceiver = null;
MQQueueManager queueManager=null;
TextMessage message=null;
final int NUM_MSGS=0;
public fiscQueueReciever()
{
try {
queueConnectionFactory= new MQQueueConnectionFactory();
queueConnection = queueConnectionFactory.createQueueConnection();
queueSession = queueConnection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
queue=queueSession.createQueue( "testqueue1");
queueReceiver = queueSession.createReceiver(queue);
fiscListener fl=new fiscListener();
queueReceiver.setMessageListener(fl);
queueConnection.start();
//--------------------------------------------added listener and started
//connection---starting sending message-----------------------
queueSender = queueSession.createSender(queue);
message = queueSession.createTextMessage();
for (int i = 0; i < 1; i++) {
message.setText("This is sample message " + (i + 1));
System.out.println("Sending message: " + message.getText());
queueSender.send(message);
}
} catch (JMSException e) {
System.out.println("Exception occurred: " +
e.toString());
} catch (Exception se){
System.out.println(" last Exception occurred: " +
se.toString());
} finally {
// if (queueConnection != null) {
// try {
// queueConnection.close();
// } catch (JMSException e) {}
// }
}
}
*/
public static void main (String[] args)
{
fiscQueueReciever fqr=new fiscQueueReciever();
}
}//class
class fiscListener implements MessageListener
{
public void onMessage(Message arg0) {
TextMessage message = null;
Message m=null;
m=arg0;
try
{
System.out.println("entered");
if (m != null) {
if (m instanceof TextMessage)
{
message = (TextMessage) m;
System.out.println("Reading message: " +message.getText());
}
}
} catch (JMSException e) {
System.out.println("Exception occurred: " + e.toString());
} catch (Exception se){
System.out.println(" last Exception occurred: " + se.toString());
}
}//onMessage
}
----------------------------------------------------------------
pls give me soem suggestions..or point out my mistake.....
thanks in advance
Santhosh |
|
Back to top |
|
 |
jsware |
Posted: Tue Aug 10, 2004 11:52 pm Post subject: |
|
|
 Chevalier
Joined: 17 May 2001 Posts: 455
|
The Using Java manual says that with asynchronous reads (i.e via onMessage) exceptions cannot be passed to your application code because your not blocked waiting on a receive call (see Chapter 10 - Handling Errors subsection).
I'm not a JMS expert, but you could try adding an ExceptionListener class that implements the javax.jms.ExceptionListener interface and give that to the connection object using the setExceptionListener method.
In the onException method, output the jms exception provided as a parameter. This may give you the exceptions that are occurring on your asynchronous receive (onMessage) method. _________________ Regards
John
The pain of low quaility far outlasts the joy of low price. |
|
Back to top |
|
 |
fjb_saper |
Posted: Wed Aug 11, 2004 10:55 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Java may some times be a bit tricky.
I would use two different instances of the qcf, qcon, qsess for send and receive functions. Especially if both are being aquired in bindings mode.
The session is not being run in transacted mode. I would not know when to expect the messages to be in a gettable state.
Run the session in transacted mode and make sure you do a commit.
When receiving the messages get the session and do a commit. (pass the session to the listener class.)
And most important, just as scott said put an ExceptionListener to catch occurring exceptions. Remember to extract the linked exception as it will give you the rc and reason code from MQ.
Last but not least I do hope your queue is a local queue of the qmgr in the qcf. Otherwise .... read intercomm manuals.!
Enjoy |
|
Back to top |
|
 |
santhosh_fischer |
Posted: Wed Aug 11, 2004 8:15 pm Post subject: |
|
|
Novice
Joined: 05 Aug 2004 Posts: 13
|
i have to connect to a remote queue ..
the condition is such that ,..
the backbone or MQ is running on another system...and i want to get and put data to that queues (whether on different Qmanagers or not)....
is this possible??
..
in that case will that be considered as a remote queue??..and only puts can be done????
..
can anyone please advice on this??? |
|
Back to top |
|
 |
jefflowrey |
Posted: Thu Aug 12, 2004 4:46 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
You need to configure your Java connection to be a client connection instead of a bindings connection.
There are probably 100 or more direct answers to the next question "how do I configure a client connection in Java or JMS" on this forum. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
santhosh_fischer |
Posted: Fri Aug 13, 2004 12:13 am Post subject: Thanks jefff..now everything is fine.. |
|
|
Novice
Joined: 05 Aug 2004 Posts: 13
|
thanks a lot..
now i can connect to any queue in the intranet using host name, port,QManager,and queue and if needed server connection channel also as arguements..
i used MQQueueConnectionFactory....
..
and now going to WSDL for making a standard format for the messages...
what is ur comment on that...
at present direct SOAP calls are used...and now i'm going to replace that with messages..
..
any suggestion other than WSDL??
Thanks again.
Santhosh |
|
Back to top |
|
 |
|