Dynami JMS selection in Mule 2.2.1

View: New views
6 Messages — Rating Filter:   Alert me  

Dynami JMS selection in Mule 2.2.1

by Richard Swart :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

In mule 1.4 we have the following code to select a message from a jms queue with a property named 'REFFERD_EMS_MESSAGE_ID' having a specified value.:

private Message receiveXmlMessage(UMOEventContext context, String endpointURI, String refferedEmsMessageId) throws Exception {
UMOMessage message = context.receiveEvent(createReceiptEndpoint(((UMOEndpoint) context.getComponentDescriptor().getInboundRouter().getEndpoints().get(0)).getConnector(), endpointURI, refferedEmsMessageId) , Constant.JMS_SERVICE_TIMEOUT);
if (message != null) {
String xml = message.getPayloadAsString();
if (xml != null) {
return (Message) messageFactory.createXmlMessage(xml);
}
}
throw new Exception("Message not found on corresponding wait queue " + transport + endpointURI + " for REFFERD_EMS_MESSAGE_ID=" + refferedEmsMessageId);
}

private UMOEndpoint createReceiptEndpoint(UMOConnector connector, String endpointURI, String refferedEmsMessageId) throws UMOException {
UMOEndpoint endpoint = new MuleEndpoint("getWaitingMessage", new MuleEndpointURI(transport + endpointURI), connector ,null, "receiver", 0, null, null);
MessagePropertyFilter filter = new MessagePropertyFilter();
filter.setExpression("REFFERD_EMS_MESSAGE_ID=" + refferedEmsMessageId);
endpoint.setFilter(filter);
return endpoint;
}

This works just fine....

In Mule 2.2.1 we try to do the same using:

private Message receiveXmlMessage(MuleEventContext context, String endpointURI, String refferedEmsMessageId) throws Exception {
                MuleMessage message = context.requestEvent(createReceiptEndpoint(context.getMuleContext().getRegistry().lookupConnector("jmsConnector_mod3"), endpointURI, refferedEmsMessageId) , Constant.JMS_SERVICE_TIMEOUT);
               
                if (message != null) {
                        String xml = message.getPayloadAsString();
                        if (xml != null) {
                                return (Message) messageFactory.createXmlMessage(xml);
                        }
                }
                throw new Exception("Message not found on corresponding wait queue " + transport + endpointURI + " for REFFERD_EMS_MESSAGE_ID=" + refferedEmsMessageId);
        }

private InboundEndpoint createReceiptEndpoint(Connector connector, String endpointURI, String refferedEmsMessageId) throws MuleException {
                System.out.println("Endpoint refferedEmsMessageId          : " + refferedEmsMessageId + " for " + endpointURI);
                MessagePropertyFilter filter = new MessagePropertyFilter();
                Map properties = new HashMap();
                InboundEndpoint endpoint = null;
                filter.setPattern("REFFERD_EMS_MESSAGE_ID=" + refferedEmsMessageId);
                MuleEndpointURI muleEndpoint;
                try {
                        muleEndpoint = new MuleEndpointURI(endpointURI,"endpointName","jmsConnector_mod3",null,null,null,new URI(endpointURI));
                        endpoint = new DefaultInboundEndpoint(connector,muleEndpoint,null,null,"getWaitingMessage",properties,null,filter,false,null,false,30000,"started","","",connector.getMuleContext(),null);
                } catch (URISyntaxException e) {
                        e.printStackTrace();
                }
                return endpoint;
        }

This selects any message from the queue without using the filter...  How can we configure this so it will apply the MessagePropertyFilter?

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: Dynami JMS selection in Mule 2.2.1

by antoine.borg :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Have you tried using JMS Selectors?

HTH

A
Tonny Bruckers wrote:

> In mule 1.4 we have the following code to select a message from a jms queue with a property named 'REFFERD_EMS_MESSAGE_ID' having a specified value.:
>
> private Message receiveXmlMessage(UMOEventContext context, String endpointURI, String refferedEmsMessageId) throws Exception {
> UMOMessage message = context.receiveEvent(createReceiptEndpoint(((UMOEndpoint) context.getComponentDescriptor().getInboundRouter().getEndpoints().get(0)).getConnector(), endpointURI, refferedEmsMessageId) , Constant.JMS_SERVICE_TIMEOUT);
> if (message != null) {
> String xml = message.getPayloadAsString();
> if (xml != null) {
> return (Message) messageFactory.createXmlMessage(xml);
> }
> }
> throw new Exception("Message not found on corresponding wait queue " + transport + endpointURI + " for REFFERD_EMS_MESSAGE_ID=" + refferedEmsMessageId);
> }
>
> private UMOEndpoint createReceiptEndpoint(UMOConnector connector, String endpointURI, String refferedEmsMessageId) throws UMOException {
> UMOEndpoint endpoint = new MuleEndpoint("getWaitingMessage", new MuleEndpointURI(transport + endpointURI), connector ,null, "receiver", 0, null, null);
> MessagePropertyFilter filter = new MessagePropertyFilter();
> filter.setExpression("REFFERD_EMS_MESSAGE_ID=" + refferedEmsMessageId);
> endpoint.setFilter(filter);
> return endpoint;
> }
>
> This works just fine....
>
> In Mule 2.2.1 we try to do the same using:
>
> private Message receiveXmlMessage(MuleEventContext context, String endpointURI, String refferedEmsMessageId) throws Exception {
> MuleMessage message = context.requestEvent(createReceiptEndpoint(context.getMuleContext().getRegistry().lookupConnector("jmsConnector_mod3"), endpointURI, refferedEmsMessageId) , Constant.JMS_SERVICE_TIMEOUT);
>
> if (message != null) {
> String xml = message.getPayloadAsString();
> if (xml != null) {
> return (Message) messageFactory.createXmlMessage(xml);
> }
> }
> throw new Exception("Message not found on corresponding wait queue " + transport + endpointURI + " for REFFERD_EMS_MESSAGE_ID=" + refferedEmsMessageId);
> }
>
> private InboundEndpoint createReceiptEndpoint(Connector connector, String endpointURI, String refferedEmsMessageId) throws MuleException {
> System.out.println("Endpoint refferedEmsMessageId          : " + refferedEmsMessageId + " for " + endpointURI);
> MessagePropertyFilter filter = new MessagePropertyFilter();
> Map properties = new HashMap();
> InboundEndpoint endpoint = null;
> filter.setPattern("REFFERD_EMS_MESSAGE_ID=" + refferedEmsMessageId);
> MuleEndpointURI muleEndpoint;
> try {
> muleEndpoint = new MuleEndpointURI(endpointURI,"endpointName","jmsConnector_mod3",null,null,null,new URI(endpointURI));
> endpoint = new DefaultInboundEndpoint(connector,muleEndpoint,null,null,"getWaitingMessage",properties,null,filter,false,null,false,30000,"started","","",connector.getMuleContext(),null);
> } catch (URISyntaxException e) {
> e.printStackTrace();
> }
> return endpoint;
> }
>
> This selects any message from the queue without using the filter...  How can we configure this so it will apply the MessagePropertyFilter?
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>
>
>  
--

Antoine Borg , Director of Services | Tel: +32 28 504 696
ricston Ltd., BP 2, 1180 Uccle, Brussels, BELGIUM
See our full schedule of Mule and Android courses online: Ricston Course
Schedules <http://www.ricston.com/courses/schedules>
email: antoine.borg@... <mailto:antoine.borg@...> |
twitter: twitter.com/antoinericston <http://www.twitter.com/antoinericston>
----------
* Disclaimer* - This email and any files transmitted with it are
confidential and contain privileged or copyright information. You must
not present this message to another party without first gaining
permission from the sender. If you are not the intended recipient you
must not copy, distribute or use this email or the information contained
in it for any purpose other than to notify us. If you have received this
message in error, please notify the sender immediately and delete this
email from your system. We do not guarantee that this material is free
from viruses or any other defects although due care has been taken to
minimise the risk. Any views stated in this communication are those of
the actual sender and not necessarily those of Ricston Ltd. or its
subsidiaries.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: Dynami JMS selection in Mule 2.2.1

by Richard Swart :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Since mule 2.2 you should be able to use expressions in your selector. See

http://www.mulesoft.org/jira/browse/MULE-4119

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: Dynami JMS selection in Mule 2.2.1

by torghal :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Can you give an example how to do this, we have messages waiting on the queue which where created like this:

MuleMessage umoXmlMessage = new DefaultMuleMessage(xmlMessage);
umoXmlMessage.setProperty("REFFERD_EMS_MESSAGE_ID", comr.getRefferedEmsMessageId());

We would like to select a message ussing the REFFERD_EMS_MESSAGE_ID property.


Trond Kvarenes-2 wrote:
Since mule 2.2 you should be able to use expressions in your selector. See

http://www.mulesoft.org/jira/browse/MULE-4119

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Re: Dynami JMS selection in Mule 2.2.1

by Richard Swart :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Looking at your example for Mule-2.2.1 I guess something like the following.

JmsSelectorFilter filter = new JmsSelectorFilter();
filter.setExpression("REFFERD_EMS_MESSAGE_ID==" + refferedEmsMessageId);
........

I am curious at the complete use case as I find the concept of selecting a single message from a wait queue a little bit strange. Normally queues are best at fifo type operations (so consume them all). Would it be an alternative to use a database table instead and select the message from directly from the table?

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: Dynami JMS selection in Mule 2.2.1

by torghal :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Finally worked with:
filter.setExpression("REFFERD_EMS_MESSAGE_ID='" + refferedEmsMessageId + "'");

We put the messages that where sent to an external system on a queue, after the external system "answers" we get the corresponding message from the queue to move it to a next queueu.  A database solution as you suggested was also possible, but since we already used a lot of queues we decided to go with jms queueus.

Sunil Kukde wrote:
Looking at your example for Mule-2.2.1 I guess something like the following.

JmsSelectorFilter filter = new JmsSelectorFilter();
filter.setExpression("REFFERD_EMS_MESSAGE_ID==" + refferedEmsMessageId);
........

I am curious at the complete use case as I find the concept of selecting a single message from a wait queue a little bit strange. Normally queues are best at fifo type operations (so consume them all). Would it be an alternative to use a database table instead and select the message from directly from the table?

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email