Author |
Message
|
kugynok |
Posted: Tue Jul 22, 2014 1:44 am Post subject: MQ 7.5 XMS .NET Sync communition, how can implement? |
|
|
Newbie
Joined: 21 Jul 2014 Posts: 7
|
Hi all!
I am fairly new to mq.
I use to XMS , .NET 4.5 I made an async mode and work well... I wanna make sync communication, but I don't know how can. Please help me!
Thank You!
K |
|
Back to top |
|
 |
IanAlderson |
Posted: Tue Jul 22, 2014 4:47 am Post subject: |
|
|
Novice
Joined: 23 Apr 2014 Posts: 17
|
Hi,
For synchronous mode you do not use a message listener but instead use one of the Receive methods (wait, infinite wait or no wait) of the MessageConsumer object. You should be able to find suitable documentation in the online Knowledge Center or take a look at the SampleConsumerCS sample program which has an example of both the asynchronous and synchronous consumers. |
|
Back to top |
|
 |
kugynok |
Posted: Tue Jul 22, 2014 9:31 pm Post subject: |
|
|
Newbie
Joined: 21 Jul 2014 Posts: 7
|
Hi IanAlderson!
Why should not I use? (a message listener)
Here is my code, how I can modify?
Code: |
public ITextMessage GetMessage(string qmName, string queuOut)
{
try
{
if (Session == null)
{
Session = Connection.CreateSession(true, AcknowledgeMode.ClientAcknowledge);
}
Destination = Session.CreateQueue(string.Format("queue://{0}/{1}", qmName, queuOut));
Destination.SetIntProperty(XMSC.WMQ_TARGET_CLIENT, XMSC.WMQ_TARGET_DEST_MQ);
Destination.SetStringProperty(XMSC.JMS_IBM_FORMAT, MQC.MQFMT_STRING);
var consumer = Session.CreateConsumer(Destination);
var message = consumer.ReceiveNoWait();
consumer.Close();
consumer.Dispose();
return message as ITextMessage;
}
catch (XMSException e)
{
Console.WriteLine(e.ToString());
return null;
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
return null;
}
} |
I think this line can modify:
Code: |
var message = consumer.ReceiveNoWait(); //orig
var message = consumer.Receive(3000); //changed |
but, how I find the reply message?
Thank you for help me!
K. |
|
Back to top |
|
 |
IanAlderson |
Posted: Wed Jul 23, 2014 2:05 am Post subject: |
|
|
Novice
Joined: 23 Apr 2014 Posts: 17
|
The message listener registers a method that is invoked (asynchronously) when a message arrives on the queue. The Receive method blocks until it returns. ReceiveNoWait returns immediately whether a message is available or not, Receive(3000) returns after 3 seconds or when a message is available and read from the queue, whichever is the sooner.
What error are you seeing in your program?
Try using the ImessageConsumer and IMessage objects rather than var. |
|
Back to top |
|
 |
kugynok |
Posted: Wed Jul 23, 2014 2:51 am Post subject: |
|
|
Newbie
Joined: 21 Jul 2014 Posts: 7
|
Thanks for the information!
var not problem, I could modifying the code and work well, but I dont get a reply message. How can use the message selector?
My code:
Code: |
var correlId = "JMSCorrelationID='SOKPOK'";
|
send message object:
Code: |
msg.JMSMessageID = correlId; |
reply message object:
Code: |
var consumer = Session.CreateConsumer(Destination, correlId);
var message = consumer.Receive(waitTime); |
What did I do wrong?
Thank You for help me!
K |
|
Back to top |
|
 |
fjb_saper |
Posted: Wed Jul 23, 2014 5:03 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
wrong sequence of things...
- send message
- get messagid (it was set during the send)
String msgid = msg.getJMSMessageId();
- build selector
String sel="JMSCorrelID='" + msgid + "'";
- create receiver with selector
- receive message or time out (remember sent message has to be committed before starting this step.
- close / discard receiver
- done
Have fun  _________________ MQ & Broker admin |
|
Back to top |
|
 |
kugynok |
Posted: Wed Jul 23, 2014 11:50 pm Post subject: |
|
|
Newbie
Joined: 21 Jul 2014 Posts: 7
|
Thank You!
Now works well!  |
|
Back to top |
|
 |
|