Author |
Message
|
zenstudent |
Posted: Wed Sep 26, 2012 7:55 pm Post subject: C# How to set message expiration |
|
|
Newbie
Joined: 26 Sep 2012 Posts: 6
|
I am using C# and currently sending a message to a queue. Once message arrives at the target queue, I would like for the message to expire within two minutes to prevent queue buildup. How do I do that? |
|
Back to top |
|
 |
exerk |
Posted: Thu Sep 27, 2012 12:51 am Post subject: |
|
|
 Jedi Council
Joined: 02 Nov 2006 Posts: 6339
|
Set the appropriate expiry time in your messages, allowing for any transit time through networks. The Application Programming Guide (APG) is your friend in this endeavour. _________________ It's puzzling, I don't think I've ever seen anything quite like this before...and it's hard to soar like an eagle when you're surrounded by turkeys. |
|
Back to top |
|
 |
zpat |
Posted: Thu Sep 27, 2012 1:07 am Post subject: |
|
|
 Jedi Council
Joined: 19 May 2001 Posts: 5866 Location: UK
|
Of course this only matters if the message is not processed (consumed).
This sounds like a strange requirement.
Why would you not expect messages to be consumed normally? If non-consumption is exceptional then having a longer expiry (e.g. one day) would normally be enough to prevent a build-up of orphaned messages - this usually only applies when messages are consumed selectively (i.e. by matching the msgid or correlid).
Non-selective (unconditional) consumption should keep the queue clear anyway.
If you just want the latest status of something (like a share price) you should look at pub/sub and retained publications.
Better to give us the overall requirements and let us advise, than to ask a specific question about expiry. |
|
Back to top |
|
 |
zenstudent |
Posted: Thu Sep 27, 2012 9:22 am Post subject: |
|
|
Newbie
Joined: 26 Sep 2012 Posts: 6
|
I know this is a strange requirement, but it is what it is.
This is the snippet of code I am using to send the message:
Hashtable envr = new Hashtable();
envr.Add(MQC.CHANNEL_PROPERTY, channelName);
envr.Add(MQC.PORT_PROPERTY, port);
envr.Add(MQC.HOST_NAME_PROPERTY, hostName);
envr.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_MANAGED);
envr.Add(MQC.MQRO_EXPIRATION, 120000);
if (!string.IsNullOrEmpty(sslCipherSpec) && !string.IsNullOrEmpty(sslCertStore))
{
envr.Add(MQC.SSL_CIPHER_SPEC_PROPERTY, sslCipherSpec);
envr.Add(MQC.SSL_CERT_STORE_PROPERTY, sslCertStore);
}
mqQMgr = new MQQueueManager(qManager, envr);
mqQueue = mqQMgr.AccessQueue(outputQname, MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING);
queueMessage = new MQMessage();
queueMessage.WriteString(message);
queueMessage.Format = MQC.MQFMT_STRING;
mqQueue.Put(queueMessage);
I added, "envr.Add(MQC.MQRO_EXPIRATION, 120000)", in my existing code to satisfy the expiry of 2 mins. Will this code be able to set the expiry of message to 2 mins? |
|
Back to top |
|
 |
zpat |
Posted: Thu Sep 27, 2012 9:55 am Post subject: |
|
|
 Jedi Council
Joined: 19 May 2001 Posts: 5866 Location: UK
|
Setting expiry is NOT the requirement. It is your idea of how to meet the requirement.
What is the actual requirement? |
|
Back to top |
|
 |
mqjeff |
Posted: Thu Sep 27, 2012 9:59 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
You need to set the expiry on each specific message in it's mqmd, not on the connection or the environment. |
|
Back to top |
|
 |
zenstudent |
Posted: Thu Sep 27, 2012 10:44 am Post subject: |
|
|
Newbie
Joined: 26 Sep 2012 Posts: 6
|
mqjeff: could you provide the sample code pls. Thanks in advance. |
|
Back to top |
|
 |
mqjeff |
Posted: Thu Sep 27, 2012 5:08 pm Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
|
Back to top |
|
 |
zenstudent |
Posted: Thu Sep 27, 2012 7:09 pm Post subject: |
|
|
Newbie
Joined: 26 Sep 2012 Posts: 6
|
I have set the Expiry property to two mins.
Thank you so much! |
|
Back to top |
|
 |
zpat |
Posted: Fri Sep 28, 2012 1:16 am Post subject: |
|
|
 Jedi Council
Joined: 19 May 2001 Posts: 5866 Location: UK
|
Even though it may be the wrong design - oh well..... |
|
Back to top |
|
 |
zenstudent |
Posted: Fri Oct 05, 2012 10:13 pm Post subject: |
|
|
Newbie
Joined: 26 Sep 2012 Posts: 6
|
Code: message.Expiry = 120000;
I am setting the expiry property in the message, but the message is still not expiring. Do I need to set another parameter? Need help with the actual code pls.
Any help would be greatly appreciated. |
|
Back to top |
|
 |
exerk |
Posted: Sat Oct 06, 2012 1:04 am Post subject: |
|
|
 Jedi Council
Joined: 02 Nov 2006 Posts: 6339
|
zenstudent wrote: |
Code: message.Expiry = 120000;
I am setting the expiry property in the message, but the message is still not expiring. Do I need to set another parameter? Need help with the actual code pls.
Any help would be greatly appreciated. |
See note 2 HERE. _________________ It's puzzling, I don't think I've ever seen anything quite like this before...and it's hard to soar like an eagle when you're surrounded by turkeys. |
|
Back to top |
|
 |
bruce2359 |
Posted: Sat Oct 06, 2012 4:43 am Post subject: |
|
|
 Poobah
Joined: 05 Jan 2008 Posts: 9469 Location: US: west coast, almost. Otherwise, enroute.
|
zenstudent wrote: |
Code: message.Expiry = 120000;
I am setting the expiry property in the message, but the message is still not expiring. Do I need to set another parameter? Need help with the actual code pls.
Any help would be greatly appreciated. |
How do you know that the messages are not expiring? Can you browse/get them from the queue? _________________ 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 |
|
 |
zenstudent |
Posted: Sat Oct 06, 2012 9:19 pm Post subject: |
|
|
Newbie
Joined: 26 Sep 2012 Posts: 6
|
That the messages are not expiring was confirmed by the other team which is reading the queue. The queue was building up and the messages are not getting deleted from the queue.
Any help with trying to figure out how to fix the code will be greatly appreciated. |
|
Back to top |
|
 |
mqjeff |
Posted: Sun Oct 07, 2012 4:36 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Messages sitting on a queue and not getting deleted doesn't mean that they're not expired.
It only means that they're not expired if the app does NOT get an MQRC 2033 for an MQGET that matches any message.
Expired messages are removed from queues - at current releases of MQ that is - by a background process that acts at intervals. Messages are *not* immediately removed from the queue at the exact second that they are expired. |
|
Back to top |
|
 |
|