I'm writing a transformer that, among other things, needs to set some content on the message based upon whether there are messages pending in a given queue in ActiveMQ.
Is there a way to pass the jms:activemq-connector into the transformer code and make calls against it in the transformMessage() method to get the queue count?
Edit:
I found a way to get to the connector using the MuleContext but I'm not seeing the results I expect; the queue always appears to be empty. I loaded up the queue and then ran a flow that invoked the transformer. In the beginning of that transformer I had the following:
public Object transformMessage( MuleMessage message, String outputEncoding )
throws TransformerException
{
MuleContext context = message.getMuleContext();
MuleRegistry registry = context.getRegistry();
JmsConnector connector = (JmsConnector)registry.lookupConnector( "AMQConnector" );
try
{
Session session = connector.getSession( false, false );
Queue queue = session.createQueue( "MyQueue" );
QueueBrowser browser = session.createBrowser( queue );
Enumeration enumeration = browser.getEnumeration();
boolean hasMessages = enumeration.hasMoreElements();
System.out.println( "Value is: " + hasMessages );
}
catch ( Exception e )
{
}
....
I see the expected number of messages coming out...i.e., if I started with 8 messages in the queue, I see the message 8 times. However, the value of hasMessages is always false.
I guess my question has changed more to, "How do I get the count of a queue from within a Mule transformer?"