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 API Support » Multiple Threads getting the same message

Post new topic  Reply to topic
 Multiple Threads getting the same message « View previous topic :: View next topic » 
Author Message
Washington Morais
PostPosted: Thu Feb 09, 2012 9:30 am    Post subject: Multiple Threads getting the same message Reply with quote

Newbie

Joined: 09 Feb 2012
Posts: 7

Hi all.

I have an application that is using multiple threads to retrieve messages from MQ. Each Thread open a new connection to MQ. The problem is that differents Threads are reading the same message. Any help, please?

Code fragments:

Code:

// Create a Task List
List<Task> procList = new List<Task>();

for (int i = 1; i <= intTotalTask; i++)
{
     procList.Add(Task.Factory.StartNew(() => new MyObject().MyMethod()));
}

Task.WaitAll(procList.ToArray());



And the MQ Options
Code:

MQGetMessageOptions mQGetMessageOptions = new MQGetMessageOptions();
mQGetMessageOptions.WaitInterval = 5000;
mQGetMessageOptions.Options = MQC.MQGMO_WAIT;
mQGetMessageOptions.Options |= MQC.MQPMO_SYNCPOINT;



Note: Then each [ MyObject().MyMethod() ] call, open a new connection to MQ

Tks in advance!
Back to top
View user's profile Send private message
Vitor
PostPosted: Thu Feb 09, 2012 9:40 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

WMQ version?
OS?
Platform (WAS, native, etc, etc)

How do you know it's the same message (same payload data, same message id in the MQMD, etc, etc)?

Do they all get the same message at the same time or does one thread pick it up, then another, then another?

Better information, better advice.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
bruce2359
PostPosted: Thu Feb 09, 2012 9:53 am    Post subject: Reply with quote

Poobah

Joined: 05 Jan 2008
Posts: 9469
Location: US: west coast, almost. Otherwise, enroute.

Code:

mQGetMessageOptions.Options |= MQC.MQPMO_SYNCPOINT;


MQPMO_SYNCPOINT is an mqput option.
_________________
I like deadlines. I like to wave as they pass by.
ב''ה
Lex Orandi, Lex Credendi, Lex Vivendi. As we Worship, So we Believe, So we Live.
Back to top
View user's profile Send private message
Washington Morais
PostPosted: Thu Feb 09, 2012 10:13 am    Post subject: Reply with quote

Newbie

Joined: 09 Feb 2012
Posts: 7

bruce2359 wrote:
Code:

mQGetMessageOptions.Options |= MQC.MQPMO_SYNCPOINT;


MQPMO_SYNCPOINT is an mqput option.


True. I'll change it and see the result.
Tks
Back to top
View user's profile Send private message
mqjeff
PostPosted: Thu Feb 09, 2012 10:18 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

Also.

Open one connection for each thread that has to GET messages, and then one connection for all threads that need to PUT messages.

Do not open any more connections than that, and do not ever open one connection for each get.
Back to top
View user's profile Send private message
bruce2359
PostPosted: Thu Feb 09, 2012 10:20 am    Post subject: Reply with quote

Poobah

Joined: 05 Jan 2008
Posts: 9469
Location: US: west coast, almost. Otherwise, enroute.

Washington Morais wrote:
bruce2359 wrote:
Code:

mQGetMessageOptions.Options |= MQC.MQPMO_SYNCPOINT;


MQPMO_SYNCPOINT is an mqput option.


True. I'll change it and see the result.
Tks

This change should not give you different results, as both constants have the same numeric value.
_________________
I like deadlines. I like to wave as they pass by.
ב''ה
Lex Orandi, Lex Credendi, Lex Vivendi. As we Worship, So we Believe, So we Live.
Back to top
View user's profile Send private message
mqjeff
PostPosted: Thu Feb 09, 2012 10:27 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

bruce2359 wrote:
Washington Morais wrote:
bruce2359 wrote:
Code:

mQGetMessageOptions.Options |= MQC.MQPMO_SYNCPOINT;


MQPMO_SYNCPOINT is an mqput option.


True. I'll change it and see the result.
Tks

This change should not give you different results, as both constants have the same numeric value.


The most likely cause here is that you're reusing the same MQMessage object and this is causing conflicts between the thread that did the last get and the thread that's trying to read the contents of the message.

i.e. make sure you at least clear the MQmessage object between gets and make sure that you are using a thread-local variable for the MQmessage object.
Back to top
View user's profile Send private message
Washington Morais
PostPosted: Fri Feb 10, 2012 4:16 am    Post subject: Reply with quote

Newbie

Joined: 09 Feb 2012
Posts: 7

Hi guys, tks for all answers. I guess i found the problem.

I was using Tasks for each message I wanted to read from MQ. I was thinking that Tasks and Threads are then same.

I changed my code to use explicitly Threads and all seams to work now.

p.s: i also changed MQPMO_SYNCPOINT to MQGMO_SYNCPOINT.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ API Support » Multiple Threads getting the same message
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.