Author |
Message
|
pauloazevedo |
Posted: Wed Dec 07, 2005 10:56 am Post subject: Synchronous MQ/JAVA |
|
|
Newbie
Joined: 07 Dec 2005 Posts: 9
|
I need to start a transaction inside a session bean(that´s why i can´t use threads). This transaction have to put a message in mq and wait for replay. I know it´s not the better approach, but it´s the only one i got. Any help? |
|
Back to top |
|
 |
jefflowrey |
Posted: Wed Dec 07, 2005 11:08 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
So.
Your code needs to start two transactions.
One to put the request message.
One to wait for the reply message.
These must be seperate transactions. Otherwise the reply message will never come because you never sent the request message.
I don't know what this has to do with using threads or not.
In fact, I don't know why you need to use transactions, either. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
pauloazevedo |
Posted: Wed Dec 07, 2005 11:14 am Post subject: |
|
|
Newbie
Joined: 07 Dec 2005 Posts: 9
|
but haw can i 'make a put' and retrieve the operation until reply? do you have any java example? |
|
Back to top |
|
 |
bower5932 |
Posted: Wed Dec 07, 2005 11:20 am Post subject: |
|
|
 Jedi Knight
Joined: 27 Aug 2001 Posts: 3023 Location: Dallas, TX, USA
|
|
Back to top |
|
 |
pauloazevedo |
Posted: Wed Dec 07, 2005 11:34 am Post subject: |
|
|
Newbie
Joined: 07 Dec 2005 Posts: 9
|
Thanks i´m gonna take a look! |
|
Back to top |
|
 |
pauloazevedo |
Posted: Thu Dec 08, 2005 9:17 am Post subject: |
|
|
Newbie
Joined: 07 Dec 2005 Posts: 9
|
Hi,
I´m using this code;
com.ibm.mq.jms.MQQueueConnectionFactory factory;
factory = new com.ibm.mq.jms.MQQueueConnectionFactory();
factory.setTransportType( com.ibm.mq.jms.JMSC.MQJMS_TP_CLIENT_MQ_TCPIP );
factory.setQueueManager(nomeQMGRdest);
factory.setHostName(Host);
factory.setChannel(SrvChannel);
factory.setPort(qmgrprt);
QueueConnection connection = factory.createQueueConnection( );
QueueSession session = connection.createQueueSession( true, Session.AUTO_ACKNOWLEDGE );
Queue queue = session.createQueue(nomefilaMQ);
Queue queue2 = session.createQueue(nomefilareply);
QueueSender sender = session.createSender( queue );
TextMessage msg = session.createTextMessage();
msg.setText(dados);
String messageId = "12345";
msg.setJMSType("text");
msg.setJMSMessageID(messageId);
msg.setJMSReplyTo(queue2);
sender.send( msg );
but i think i need to use MQMessage instead of Message, to set correlid ans stuff, how can i do this? i ´ve tried this(from IBM site):
MQQueueManager QMGR = null;
MQQueue filaMQ = null;
MQMessage messageMQ = null;
MQPutMessageOptions putOptions = null;
int openOptions = 0;
//Conectando ao sistema de mensagens
try
{ QMGR = new MQQueueManager("");
}
catch (Exception e)
{ System.out.println("\nErro ao tentar conexao ao sistema de mensagens.");
e.printStackTrace(System.out);
System.exit(1);
}
openOptions = MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING;
try
{ filaMQ = QMGR.accessQueue(nomefilaMQ, openOptions, nomeQMGRdest, "", "");
}
catch (Exception e)
{ System.out.println("\nErro ao tentar conexao a fila " + nomefilaMQ );
e.printStackTrace(System.out);
try
{ QMGR.disconnect();
}
catch(Throwable thr)
{
thr.printStackTrace(System.out);
}
System.exit(1);
}
messageMQ = new MQMessage();
try
{ messageMQ.clearMessage();
}
catch (Exception e)
{ System.out.println("\nErro ao tentar limpar a mensagem");
e.printStackTrace(System.out);
System.exit(1);
}
messageMQ.format = MQC.MQFMT_STRING;
messageMQ.persistence = MQC.MQPER_PERSISTENT;
messageMQ.replyToQueueName = nomefilareply;
messageMQ.replyToQueueManagerName = nomemqreply;
messageMQ.report = MQC.MQRO_COA | MQC.MQRO_COD | MQC.MQRO_PASS_MSG_ID | MQC.MQRO_DEAD_LETTER_Q | MQC.MQRO_EXPIRATION | MQC.MQRO_EXCEPTION;
try
{ messageMQ.writeString(message);
}
catch (Exception e)
{ System.out.println("\nErro ao tentar gravar no buffer");
e.printStackTrace(System.out);
System.exit(1);
}
try
{ putOptions = new MQPutMessageOptions();
putOptions.options = MQC.MQPMO_FAIL_IF_QUIESCING + MQC.MQPMO_NO_SYNCPOINT;
filaMQ.put(messageMQ, putOptions);
}
catch (Exception e)
{ System.out.println("\nErro ao tentar conexao a fila " + nomefilaMQ );
e.printStackTrace(System.out);
try
{ filaMQ.close();
}
catch(Throwable thr)
{
thr.printStackTrace(System.out);
}
try
{ QMGR.disconnect();
}
catch(Throwable thr)
{
thr.printStackTrace(System.out);
}
System.exit(1);
}
but i´m receiving code 2058, and i,m using the same parameters! |
|
Back to top |
|
 |
bower5932 |
Posted: Thu Dec 08, 2005 9:51 am Post subject: |
|
|
 Jedi Knight
Joined: 27 Aug 2001 Posts: 3023 Location: Dallas, TX, USA
|
2058 is a qmgr name error. Double-check your queue manager name (especially the case). Also, make sure that you are connecting into the right qmgr. |
|
Back to top |
|
 |
pauloazevedo |
Posted: Thu Dec 08, 2005 10:17 am Post subject: |
|
|
Newbie
Joined: 07 Dec 2005 Posts: 9
|
but when i use the first example with factory it works fine(com.ibm.mq.jms), but when i use com.ibm.mq i got 2058! |
|
Back to top |
|
 |
bower5932 |
Posted: Thu Dec 08, 2005 11:47 am Post subject: |
|
|
 Jedi Knight
Joined: 27 Aug 2001 Posts: 3023 Location: Dallas, TX, USA
|
I see the following lines of code that use qmgr names:
Code: |
factory.setQueueManager(nomeQMGRdest);
factory.setHostName(Host);
factory.setChannel(SrvChannel);
factory.setPort(qmgrprt);
|
and then
Code: |
MQQueueManager QMGR = null;
MQQueue filaMQ = null;
MQMessage messageMQ = null;
MQPutMessageOptions putOptions = null;
int openOptions = 0;
//Conectando ao sistema de mensagens
try
{ QMGR = new MQQueueManager("");
} |
In the first one, you pass in an explicit name. In the second, you are connecting to a blank name (ie, the default queue manager). Do you have a default queue manager? Also, the first one is client connecting. The second one appears to be bindings. Is this right? |
|
Back to top |
|
 |
pauloazevedo |
Posted: Thu Dec 08, 2005 11:54 am Post subject: |
|
|
Newbie
Joined: 07 Dec 2005 Posts: 9
|
the first one works fine, my problem is the second, but i've found this(it works fine!!!! thanks a lot!!):
MQEnvironment.hostname=Host;
MQEnvironment.channel=SrvChannel;
MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY,MQC.TRANSPORT_MQSERIES);
try {
QMGR = new MQQueueManager(nomeQMGRdest);
} catch (MQException e) {
// TODO Bloco catch gerado automaticamente
e.printStackTrace();
} |
|
Back to top |
|
 |
fjb_saper |
Posted: Thu Dec 08, 2005 9:02 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Read the Using java manual --
Section about Selector -- AND USE the SEARCH Button about JMS and Selector.... There is important performance info there...
Have fun  |
|
Back to top |
|
 |
pauloazevedo |
Posted: Wed Mar 08, 2006 6:01 am Post subject: it works but... |
|
|
Newbie
Joined: 07 Dec 2005 Posts: 9
|
ok, i got it done, but my scenario is this:
the same java application that put the message in queue a, try to to gete the message in queue b. I'm controlling time with a 'for' , ii am looking for another solution before i die in shame!!! |
|
Back to top |
|
 |
jefflowrey |
Posted: Wed Mar 08, 2006 6:23 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
You will never get a reply message until AFTER you have committed the request message - because the server will never get the request message until then.
This gets tricky to do in JMS. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
pauloazevedo |
Posted: Wed Mar 08, 2006 7:51 am Post subject: Message |
|
|
Newbie
Joined: 07 Dec 2005 Posts: 9
|
but i get the message already!! what i want to do is a "conditional get"!
that´s my code:
MQPutMessageOptions pmo = new MQPutMessageOptions();
try {
filaMQ.put(mensagem,pmo);
} catch (MQException e3) {
e3.printStackTrace();
}
retrieveMSG = new MQMessage();
MQGetMessageOptions gmo = new MQGetMessageOptions();
// that's what i wanna get rid off
for(long i=0;i<100000000;i++){
}
System.out.println("no get..................");
try {
filaReply = QMGR.accessQueue(nomeFilaSaida,openOptions);
} catch (MQException e1) {
e1.printStackTrace();
}
try {
filaReply.get(retrieveMSG,gmo);
getCorrel = retrieveMSG.correlationId; |
|
Back to top |
|
 |
fschofer |
Posted: Wed Mar 08, 2006 8:06 am Post subject: |
|
|
 Knight
Joined: 02 Jul 2001 Posts: 524 Location: Mainz, Germany
|
Hi,
try something like this
Code: |
MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.options = MQC.MQGMO_WAIT;
gmo.waitInterval = <time in ms>; |
Greetings
Frank |
|
Back to top |
|
 |
|