You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@activemq.apache.org by Allen Reese <ar...@yahoo-inc.com> on 2011/07/18 23:15:14 UTC

AMQ-3404 & querying via JMX

I'm looking at the patch we have put together for AMQ-3404 (Fix the Purge command to use message selectors), and I've run into something that just doesn't seem right.

In order to create the list of messages to remove, an AmqMessagesQueryFilter is created, and this requires a broker URL.  However, the rest of the purge command is done using JMX commands.

The added code is something like this:
// apply additive operations.
List messages = AmqMessagesUtil.getMessages(getBrokerUrl(), dest, queryAddObjects);
context.printInfo("Messages are: "+ messages.toString());

// apply subtraction operations
if (querySubObjects.size() > 0) {
	List subMsgs = AmqMessagesUtil.getMessages(getBrokerUrl(), dest, querySubObjects);
	messages.removeAll(subMsgs);
}

purgeMessages(queueName, messages);

Is there any way to do the query over JMX instead of creating a JMS connection to the broker? I'm hesitant to send in a patch that adds what feels like an extreme hack.

Allen Reese
Core Platforms
Yahoo! Inc.

RE: AMQ-3404 & querying via JMX

Posted by Allen Reese <ar...@yahoo-inc.com>.
On a related note, it seems that neither PurgeCommand nor BrowseCommand support -xmsgsel:

This is the options code: (which is pretty much the same as the --msgsel):
        } else if (token.startsWith("--xmsgsel")) {
            // If token is a substractive message selector option

            // If no message selector is specified, or next token is a new
            // option
            if (tokens.isEmpty() || ((String)tokens.get(0)).startsWith("-")) {
                context.printException(new IllegalArgumentException("Message selector not specified"));
                return;
            }

            StringTokenizer queryTokens = new StringTokenizer((String)tokens.remove(0), COMMAND_OPTION_DELIMETER);
            while (queryTokens.hasMoreTokens()) {
                querySubObjects.add(queryTokens.nextToken());
            }

But in the runTasks, it only looks at queryAddObjects:

                // Iterate through the queue result
                for (Iterator j = queueList.iterator(); j.hasNext();) {
                    List messages = JmxMBeansUtil.createMessageQueryFilter(createJmxConnection(), ((ObjectInstance)j.next()).getObjectName()).query(queryAddObjects);
                    context.printMessage(JmxMBeansUtil.filterMessagesView(messages, groupViews, queryViews));
                }

Shouldn't it take that list, and subtract anything that was in --xmsgsel?

--Allen

RE: AMQ-3404 & querying via JMX

Posted by Allen Reese <ar...@yahoo-inc.com>.
> On Mon, 2011-07-18 at 14:15 -0700, Allen Reese wrote:
> > I'm looking at the patch we have put together for AMQ-3404 (Fix the Purge command to use message
> selectors), and I've run into something that just doesn't seem right.
> >
> >
> > Is there any way to do the query over JMX instead of creating a JMS connection to the broker? I'm
> hesitant to send in a patch that adds what feels like an extreme hack.
> >
> > Allen Reese
> > Core Platforms
> > Yahoo! Inc.
> 
> The QueueViewMBean has a method "removeMatchingMessages" that takes a
> selector, doesn't that do what you want?  If not what is the use case?

That is probably easier to use.  I'm going to look at that next. 
Thanks!


> Regards
> Tim.
> 
> 
> --
> Tim Bish
> ------------
> FuseSource
> Email: tim.bish@fusesource.com
> Web: http://fusesource.com
> Twitter: tabish121
> Blog: http://timbish.blogspot.com/
> 


Allen Reese
Core Platforms
Yahoo! Inc.

RE: AMQ-3404 & querying via JMX

Posted by Allen Reese <ar...@yahoo-inc.com>.
OK this is actually what is missing from the purge command.
Earlier I thought it was that the JMX selectors worked wrong, but really it's a matter of getting a QueueViewMbean, and using that to remove the messages or match the selector.

I'm going to fix the junk I call a test into a junit test, and make it exercise the PurgeCommand class, and then I'll have a patch to fix AMQ-3404.

--Allen

> -----Original Message-----
> From: Timothy Bish [mailto:tabish121@gmail.com]
> Sent: Monday, July 18, 2011 2:23 PM
> To: dev@activemq.apache.org
> Subject: Re: AMQ-3404 & querying via JMX
> 
> On Mon, 2011-07-18 at 14:15 -0700, Allen Reese wrote:
> > I'm looking at the patch we have put together for AMQ-3404 (Fix the Purge command to use message
> selectors), and I've run into something that just doesn't seem right.
> >
> > In order to create the list of messages to remove, an AmqMessagesQueryFilter is created, and this
> requires a broker URL.  However, the rest of the purge command is done using JMX commands.
> >
> > The added code is something like this:
> > // apply additive operations.
> > List messages = AmqMessagesUtil.getMessages(getBrokerUrl(), dest, queryAddObjects);
> > context.printInfo("Messages are: "+ messages.toString());
> >
> > // apply subtraction operations
> > if (querySubObjects.size() > 0) {
> > 	List subMsgs = AmqMessagesUtil.getMessages(getBrokerUrl(), dest, querySubObjects);
> > 	messages.removeAll(subMsgs);
> > }
> >
> > purgeMessages(queueName, messages);
> >
> > Is there any way to do the query over JMX instead of creating a JMS connection to the broker? I'm
> hesitant to send in a patch that adds what feels like an extreme hack.
> >
> > Allen Reese
> > Core Platforms
> > Yahoo! Inc.
> 
> The QueueViewMBean has a method "removeMatchingMessages" that takes a
> selector, doesn't that do what you want?  If not what is the use case?
> 
> Regards
> Tim.
> 
> 
> --
> Tim Bish
> ------------
> FuseSource
> Email: tim.bish@fusesource.com
> Web: http://fusesource.com
> Twitter: tabish121
> Blog: http://timbish.blogspot.com/
> 
> 


Re: AMQ-3404 & querying via JMX

Posted by Timothy Bish <ta...@gmail.com>.
On Mon, 2011-07-18 at 14:15 -0700, Allen Reese wrote:
> I'm looking at the patch we have put together for AMQ-3404 (Fix the Purge command to use message selectors), and I've run into something that just doesn't seem right.
> 
> In order to create the list of messages to remove, an AmqMessagesQueryFilter is created, and this requires a broker URL.  However, the rest of the purge command is done using JMX commands.
> 
> The added code is something like this:
> // apply additive operations.
> List messages = AmqMessagesUtil.getMessages(getBrokerUrl(), dest, queryAddObjects);
> context.printInfo("Messages are: "+ messages.toString());
> 
> // apply subtraction operations
> if (querySubObjects.size() > 0) {
> 	List subMsgs = AmqMessagesUtil.getMessages(getBrokerUrl(), dest, querySubObjects);
> 	messages.removeAll(subMsgs);
> }
> 
> purgeMessages(queueName, messages);
> 
> Is there any way to do the query over JMX instead of creating a JMS connection to the broker? I'm hesitant to send in a patch that adds what feels like an extreme hack.
> 
> Allen Reese
> Core Platforms
> Yahoo! Inc.

The QueueViewMBean has a method "removeMatchingMessages" that takes a
selector, doesn't that do what you want?  If not what is the use case?

Regards
Tim.


-- 
Tim Bish
------------
FuseSource
Email: tim.bish@fusesource.com
Web: http://fusesource.com
Twitter: tabish121
Blog: http://timbish.blogspot.com/




RE: AMQ-3404 & querying via JMX

Posted by Allen Reese <ar...@yahoo-inc.com>.
Nevermind, I just had to look closer.

I found this in BrowseCommand.java:

// Iterate through the queue result
for (Iterator j = queueList.iterator(); j.hasNext();) {
    List messages = JmxMBeansUtil.createMessageQueryFilter(createJmxConnection(), ((ObjectInstance)j.next()).getObjectName()).query(queryAddObjects);
     context.printMessage(JmxMBeansUtil.filterMessagesView(messages, groupViews, queryViews));
}


Allen Reese
Core Platforms
Yahoo! Inc.

> -----Original Message-----
> From: Allen Reese [mailto:areese@yahoo-inc.com]
> Sent: Monday, July 18, 2011 2:15 PM
> To: dev@activemq.apache.org
> Subject: AMQ-3404 & querying via JMX
> 
> I'm looking at the patch we have put together for AMQ-3404 (Fix the Purge command to use message
> selectors), and I've run into something that just doesn't seem right.
> 
> In order to create the list of messages to remove, an AmqMessagesQueryFilter is created, and this
> requires a broker URL.  However, the rest of the purge command is done using JMX commands.
> 
> The added code is something like this:
> // apply additive operations.
> List messages = AmqMessagesUtil.getMessages(getBrokerUrl(), dest, queryAddObjects);
> context.printInfo("Messages are: "+ messages.toString());
> 
> // apply subtraction operations
> if (querySubObjects.size() > 0) {
> 	List subMsgs = AmqMessagesUtil.getMessages(getBrokerUrl(), dest, querySubObjects);
> 	messages.removeAll(subMsgs);
> }
> 
> purgeMessages(queueName, messages);
> 
> Is there any way to do the query over JMX instead of creating a JMS connection to the broker? I'm
> hesitant to send in a patch that adds what feels like an extreme hack.
> 
> Allen Reese
> Core Platforms
> Yahoo! Inc.