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 » General Discussion » Expired messages cleaning

Post new topic  Reply to topic Goto page 1, 2, 3  Next
 Expired messages cleaning « View previous topic :: View next topic » 
Author Message
pitm3n
PostPosted: Fri Aug 12, 2005 2:21 am    Post subject: Expired messages cleaning Reply with quote

Novice

Joined: 12 Aug 2005
Posts: 10
Location: Gdansk,PL

Hello,

I've got a following problem to pass through:

I'd like to periodically clean a queue from undelivered messages older than certain period of time (for example, older than 2 days), but have no
idea how to deal with that (application which register messages is out of
our responsibility, so we can't force to set expiry time on messages).
Could it be done by browsing the queue and manually getting specified
messages from this queue ?
Maybe you've got any ideas, thank you in advance...
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Fri Aug 12, 2005 3:08 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

Can you control the receiving application?

What I might do is put a new queue between the sender and the receiver, and write a little program that will copy messages from the sender output queue to the receiver input queue, but set the expiry.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
pitm3n
PostPosted: Fri Aug 12, 2005 4:22 am    Post subject: Reply with quote

Novice

Joined: 12 Aug 2005
Posts: 10
Location: Gdansk,PL

Yes,we can control receiver.
Can you tell me, because it's not completely clear for me:
If message expiry time is exceed, is that message removed from
the queue automatically, or a further action is necessary to purge it?

Thank you,

Peter
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Fri Aug 12, 2005 4:26 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

It is only removed when someone attempts to get the message.

Otherwise it stays there.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
RogerLacroix
PostPosted: Fri Aug 12, 2005 7:03 am    Post subject: Reply with quote

Jedi Knight

Joined: 15 May 2001
Posts: 3264
Location: London, ON Canada

Hi,

If you are comfortable coding in C or Java then this is pretty stright forward. I wrote a simple app for a client that runs from a crontab entry at midnight everynight.

It takes 3 parameters: QMgrName, QName and ###

The first 2 parameters are obvious; the 3rd is the number of hours "older" that messages should be deleted. I can't give you the code by the logic is very straight forward:

Code:
connect to QMgr
open Queue

get message with options browse first  & lock

loop more

   if (current_time > (MQMD.PutTime + ###)
   {
       get message under cursor (destructive get)
   }

   get message with options browse next & lock

end loop

close queue
disconnect


Regards,
Roger Lacroix
_________________
Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter
Back to top
View user's profile Send private message Visit poster's website
pitm3n
PostPosted: Fri Aug 12, 2005 11:01 pm    Post subject: Reply with quote

Novice

Joined: 12 Aug 2005
Posts: 10
Location: Gdansk,PL

That's exactly what I've asked for...
Thank you very much for your help
Back to top
View user's profile Send private message
pitm3n
PostPosted: Mon Aug 22, 2005 11:53 pm    Post subject: Reply with quote

Novice

Joined: 12 Aug 2005
Posts: 10
Location: Gdansk,PL

Roger,

I've tried to write a program using your algorythm, but looks like
I'm not experienced with programming enough
Could you please tell me how you've solved this ?
(especially puttime and local time comparation - i'm converting
values to int type, but maybe it's a better way to do that).

Thanks in advance,

Peter
Back to top
View user's profile Send private message
bob_buxton
PostPosted: Tue Aug 23, 2005 1:33 am    Post subject: Reply with quote

Master

Joined: 23 Aug 2001
Posts: 266
Location: England

Since messages are normally stored in age order you could optimise the logic in Roger's program to quit when you reach the first message that is too young to be discarded.

If you might have messages with different priorities on the queue then you would need to scan the whole queue or scan each priority in turn.
_________________
Bob Buxton
Ex-Websphere MQ Development
Back to top
View user's profile Send private message
RogerLacroix
PostPosted: Tue Aug 23, 2005 10:04 am    Post subject: Reply with quote

Jedi Knight

Joined: 15 May 2001
Posts: 3264
Location: London, ON Canada

Well, post a snippet of your code and we'll have a look. Please use the BBCode of [code] .. [/code] when you post your code.

Regards,
Roger Lacroix
_________________
Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter
Back to top
View user's profile Send private message Visit poster's website
pitm3n
PostPosted: Wed Aug 24, 2005 2:04 am    Post subject: Reply with quote

Novice

Joined: 12 Aug 2005
Posts: 10
Location: Gdansk,PL

Using sample amqsget.c as a basis.
First I'm getting a local time using standard time() function.

Code:

time_t curtime;
struct tm *loctime;
curtime = time (NULL);


then, after getting first message i'm picking up
PutDate field from message descriptor:
(it contains string including year,month,day,hour,minute,second,tenth
- 2005082408564308 for example) and trying to put in tm structure
(for further mktime() use).

Code:

time_t puttime;
struct tm putdate;
printf("Message putdate: %s\n", md.PutDate);
strptime(md.PutDate, "%Y%m%d%H%M%S%", &putdate);


but this fails(strptime returns NULL pointer). My idea is to convert
message put time to "seconds since the epoch" format and compare
with local time (I believe it's easier that comparing a strings).
I'm not sure where an error is, could it be caused because PutDate is
CHAR8 type variable ?I've tried to copy it to new buffer, add termination
\0 character, but without result. Maybe you've another idea how to compare those times?

Thank you and regards,

Peter
Back to top
View user's profile Send private message
KeeferG
PostPosted: Wed Aug 24, 2005 6:55 am    Post subject: Reply with quote

Master

Joined: 15 Oct 2004
Posts: 215
Location: Basingstoke, UK

Any messages that have expired will be removed at the next appropriate get. This could a get of any message from the queue, expired or not.

e.g. a queue has 20 messages 10 of which have expired. Application succesfully gets a non-expired message from the queue. The queue manager will remove the expired messages at the same time.

I think even a browse is valid to clear the queue of expired messages
_________________
Keith Guttridge
-----------------
Using MQ since 1995
Back to top
View user's profile Send private message Visit poster's website
bob_buxton
PostPosted: Wed Aug 24, 2005 7:08 am    Post subject: Reply with quote

Master

Joined: 23 Aug 2001
Posts: 266
Location: England

KeeferG wrote:
Any messages that have expired will be removed at the next appropriate get. This could a get of any message from the queue, expired or not.

e.g. a queue has 20 messages 10 of which have expired. Application succesfully gets a non-expired message from the queue. The queue manager will remove the expired messages at the same time.

I think even a browse is valid to clear the queue of expired messages


The original posters problem was that he didn't have access to the putting application to set a message expiry interval.
_________________
Bob Buxton
Ex-Websphere MQ Development
Back to top
View user's profile Send private message
KeeferG
PostPosted: Wed Aug 24, 2005 7:17 am    Post subject: Reply with quote

Master

Joined: 15 Oct 2004
Posts: 215
Location: Basingstoke, UK



I'm getting quite good at this
_________________
Keith Guttridge
-----------------
Using MQ since 1995
Back to top
View user's profile Send private message Visit poster's website
fjb_saper
PostPosted: Wed Aug 24, 2005 2:15 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

And remember date and time information on the message is in UTC.
So if your API does not automatically adjust you will have to.

Enjoy
Back to top
View user's profile Send private message Send e-mail
RogerLacroix
PostPosted: Thu Aug 25, 2005 7:31 am    Post subject: Reply with quote

Jedi Knight

Joined: 15 May 2001
Posts: 3264
Location: London, ON Canada

Hi,
pitm3n wrote:
then, after getting first message i'm picking up
PutDate field from message descriptor:
(it contains string including year,month,day,hour,minute,second,tenth
- 2005082408564308 for example) and trying to put in tm structure
(for further mktime() use).

No, it doesn't. MQMD has 2 fields for the message's time PutDate and PutTime. Please read the WMQ Application Programming Reference Manual.

pitm3n wrote:
Code:

time_t puttime;
struct tm putdate;
printf("Message putdate: %s\n", md.PutDate);
strptime(md.PutDate, "%Y%m%d%H%M%S%", &putdate);


but this fails(strptime returns NULL pointer).

Well, no kidding. There are so many 'C' programming errors in that little snippet of code, it is not even funny.

Code:
printf("Message putdate: %s\n", md.PutDate);

First off, never ever use printf with %s when the varaible is not null termiated unless you explicitly state the length. MQMD string variables (CHAR8) are not null terminate. The proper way to do it is:
Code:
printf("Message putdate: %.*s\n", MQ_PUT_DATE_LENGTH, md.PutDate);

Secondly, strptime() function is not a cross-platform function so I would strongly recommend not using it. But if you are going to use it, AT LEAST READ THE MANUAL.
http://www.opengroup.org/onlinepubs/007908799/xsh/strptime.html

You have 2 mistakes in this statement:
Code:
strptime(md.PutDate, "%Y%m%d%H%M%S%", &putdate);

PutDate only contains year, month & day. i.e. YYYYMMDD. Hence, the second parameter should be "%Y%m%d". Plus the third argument is supposed to be a POINTER and NOT an address reference. Huge difference.

Since you have not read the MQ manuals you made a huge and incorrect assumption about the PutDate field. The message's timestamp is actually in 2 fields: PutDate and PutTime. You need to combine these fields for strptime(). Again, you did not read the manual about strptime() because it does not handle milliseconds. Hence, if you going to use strptime() then you need to strip those values from PutTime.

If you are going to stick with the strptime() function then lets code it up correctly:
Code:
struct tm *msgDateTime;
char   tempBuf[17];

printf("Message putdate: %.*s and puttime: %.*s\n",
       MQ_PUT_DATE_LENGTH,
       md.PutDate,
       MQ_PUT_TIME_LENGTH,
       md.PutTime);

// Since strptime() does not handle milliseconds
// We only want the first 6 characters of PutTime
sprintf(tempBuf,
        "%.*s%.*s",
        MQ_PUT_DATE_LENGTH,
        md.PutDate,
        6,
        md.PutTime);

strptime(tempBuf, "%Y%m%d%H%M%S%", msgDateTime);

I realize that some people are new to both C and MQ but PLEASE take time to read the manuals (at least the approprate sections). Or use Google. Seriously, Google can be a developers best friend or at least a very power tool.

Regards,
Roger Lacroix
Capitalware Inc.
_________________
Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic  Reply to topic Goto page 1, 2, 3  Next Page 1 of 3

MQSeries.net Forum Index » General Discussion » Expired messages cleaning
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.