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 » Synchronous MQ/JAVA

Post new topic  Reply to topic Goto page 1, 2  Next
 Synchronous MQ/JAVA « View previous topic :: View next topic » 
Author Message
pauloazevedo
PostPosted: Wed Dec 07, 2005 10:56 am    Post subject: Synchronous MQ/JAVA Reply with quote

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
View user's profile Send private message
jefflowrey
PostPosted: Wed Dec 07, 2005 11:08 am    Post subject: Reply with quote

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
View user's profile Send private message
pauloazevedo
PostPosted: Wed Dec 07, 2005 11:14 am    Post subject: Reply with quote

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
View user's profile Send private message
bower5932
PostPosted: Wed Dec 07, 2005 11:20 am    Post subject: Reply with quote

Jedi Knight

Joined: 27 Aug 2001
Posts: 3023
Location: Dallas, TX, USA

Go to:

http://www.developer.ibm.com/isv/tech/sampmq.html

and take a look at mqjmsreq and mqjmssrv.
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger
pauloazevedo
PostPosted: Wed Dec 07, 2005 11:34 am    Post subject: Reply with quote

Newbie

Joined: 07 Dec 2005
Posts: 9

Thanks i´m gonna take a look!
Back to top
View user's profile Send private message
pauloazevedo
PostPosted: Thu Dec 08, 2005 9:17 am    Post subject: Reply with quote

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
View user's profile Send private message
bower5932
PostPosted: Thu Dec 08, 2005 9:51 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger
pauloazevedo
PostPosted: Thu Dec 08, 2005 10:17 am    Post subject: Reply with quote

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
View user's profile Send private message
bower5932
PostPosted: Thu Dec 08, 2005 11:47 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger
pauloazevedo
PostPosted: Thu Dec 08, 2005 11:54 am    Post subject: Reply with quote

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
View user's profile Send private message
fjb_saper
PostPosted: Thu Dec 08, 2005 9:02 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
pauloazevedo
PostPosted: Wed Mar 08, 2006 6:01 am    Post subject: it works but... Reply with quote

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
View user's profile Send private message
jefflowrey
PostPosted: Wed Mar 08, 2006 6:23 am    Post subject: Reply with quote

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
View user's profile Send private message
pauloazevedo
PostPosted: Wed Mar 08, 2006 7:51 am    Post subject: Message Reply with quote

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
View user's profile Send private message
fschofer
PostPosted: Wed Mar 08, 2006 8:06 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic  Reply to topic Goto page 1, 2  Next Page 1 of 2

MQSeries.net Forum Index » IBM MQ Java / JMS » Synchronous MQ/JAVA
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.