Camel Routing using map message help required

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

Camel Routing using map message help required

prabumca06@gmail.com

Hi All,

Mapmessage.setInt("TRANS_ID,112323);
Mapmessage.setInt("ACCOUNT_ID,112323);
Mapmessage.setInt("AMOUNT",112323);
Mapmessage.setString("OPTION","C");
Mapmessage.setInt("DATE",11/2/2013);

I have set above value in map messages and messages reached Queue1

I want implement below logic in camle routing. To route messages from Queue1 to Queue2

1.In Queue1 map message key OPTION is "C",I want create new map messages set account_ID value only
  forward that map messages into Queue2.
 
Please kindly help
Reply | Threaded
Open this post in threaded view
|

AW: Camel Routing using map message help required

Jan Matèrne (jhm)
I would try to split that into two parts:
- content based router: route to another route according to the OPTION value
- transformer: as 1st step of that route create your new map

Jan

> -----Ursprüngliche Nachricht-----
> Von: [hidden email] [mailto:[hidden email]]
> Gesendet: Freitag, 27. September 2013 17:46
> An: [hidden email]
> Betreff: Camel Routing using map message help required
>
>
> Hi All,
>
> Mapmessage.setInt("TRANS_ID,112323);
> Mapmessage.setInt("ACCOUNT_ID,112323);
> Mapmessage.setInt("AMOUNT",112323);
> Mapmessage.setString("OPTION","C");
> Mapmessage.setInt("DATE",11/2/2013);
>
> I have set above value in map messages and messages reached Queue1
>
> I want implement below logic in camle routing. To route messages from
> Queue1 to Queue2
>
> 1.In Queue1 map message key OPTION is "C",I want create new map
> messages set account_ID value only
>   forward that map messages into Queue2.
>
> Please kindly help
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Camel-
> Routing-using-map-message-help-required-tp5740305.html
> Sent from the Camel - Users mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|

Re: AW: Camel Routing using map message help required

prabumca06@gmail.com

Please provide some example...
Reply | Threaded
Open this post in threaded view
|

AW: AW: Camel Routing using map message help required

Jan Matèrne (jhm)
Maybe this helps:

public class MapMessageTest extends CamelTestSupport {

        private Map<String, Object> createMap(String option) {
                Map<String,Object> map = new HashMap<String, Object>();
                map.put("OPTION", option);
                map.put("text", "Hello " + option);
                return map;
        }
       
        @Test
        public void isMap() throws InterruptedException {
                template.sendBody("direct:in", createMap("does not
matter"));
        }
       
        @Test
        public void isNotMap() throws InterruptedException {
                template.sendBody("direct:in", "just string");
        }
       
        @Test
        public void optionC() {
                template.sendBody("direct:in", createMap("C"));
        }
       
        @Override
        protected RouteBuilder createRouteBuilder() throws Exception {
                return new RouteBuilder() {
    private Processor transformMessage = new Processor()
{
                                @Override
                                public void process(Exchange exchange)
throws Exception {
                                        Map<String,Object> newBody = new
HashMap<String, Object>();
                                        newBody.put("account_ID", "1234");
                                        exchange.getIn().setBody(newBody);
                                        System.out.println("-- process --");
                                }
                        };

                        @Override
                        public void configure() throws Exception {
    // General check: right message type?
                                from("direct:in")
                                        .choice()
                                                .when().simple("${body} is
'java.util.Map'")
                                                        .to("direct:valid")
                                                .otherwise()
       
.setHeader("type").constant("otherwise")
       
.to("direct:invalid")
                                        .end();
                                // Ok, now route according to the chosen
option
                                from("direct:valid")
                                        .choice()
       
.when(isOption("C")).to("direct:optionC")
       
.otherwise().to("direct:process")
                                        .end();
                                // Final processing
                                from("direct:invalid").to("stream:err");
                                from("direct:optionC")
                                        .process(transformMessage)
                                        .to("direct:process");
                                from("direct:process").to("stream:out");
                        }

                        private Predicate isOption(final String
exptectedOptionValue) {
                                return new Predicate() {
                                        @Override
                                        public boolean matches(Exchange
exchange) {
                                                Object option =
exchange.getIn().getBody(Map.class).get("OPTION");
                                                return option != null &&
option.equals(exptectedOptionValue);
                                        }
                                };
                        }
                };
        }

}

> -----Ursprüngliche Nachricht-----
> Von: [hidden email] [mailto:[hidden email]]
> Gesendet: Montag, 30. September 2013 11:35
> An: [hidden email]
> Betreff: Re: AW: Camel Routing using map message help required
>
>
> Please provide some example...
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Camel-
> Routing-using-map-message-help-required-tp5740305p5740469.html
> Sent from the Camel - Users mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|

Re: AW: AW: Camel Routing using map message help required

prabumca06@gmail.com
I want use filter (not when) without too many functions

If  u don't mind can u give example
Reply | Threaded
Open this post in threaded view
|

Re: AW: AW: Camel Routing using map message help required

prabumca06@gmail.com

I was trying to do some thing like this

     from("Queue1")
        .filter(header(EVENT_TYPE)).isEqualTo("Transaction")
        .filter(in.).isEqualTo("C")
        .process(new Processor() {
         public void process(Exchange exchange) {
          Map map = (Map) exchange.getIn().getbody();
               String Account_No = map.get("ACCOUNTID");
               map.clear();
                map.put("ACCOUNTID",Account_No);                  
                  exchange.getOut().setBody(map);                                    
            }
       }).to("queue2");


Please correct me above code and Please tell me how to check message OPTION is C (messages is mapmessage (.filter(in.).isEqualTo("C"))

Thanks in advance




Reply | Threaded
Open this post in threaded view
|

Re: AW: AW: Camel Routing using map message help required

prabumca06@gmail.com
Please help how can i do this using filter
Reply | Threaded
Open this post in threaded view
|

Re: AW: AW: Camel Routing using map message help required

kraythe
If you mean a JMS queue you will have a problem doing that because with JMS
queues, messages only get picked up by a single consumer so if that
consumer filters the message, it is dropped into the ether of nothingness.
So that is why it is better routed before the queue. Look at recipient list
EIP pattern. Declare custom queues for each of the destinations and route
to them using a recipient list that keys off of what is in the message.

*Robert Simmons Jr. MSc. - Lead Java Architect @ EA*
*Author of: Hardcore Java (2003) and Maintainable Java (2012)*
*LinkedIn: **http://www.linkedin.com/pub/robert-simmons/40/852/a39*


On Mon, Sep 30, 2013 at 11:58 AM, [hidden email] <[hidden email]
> wrote:

> Please help how can i do this using filter
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Camel-Routing-using-map-message-help-required-tp5740305p5740581.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

Re: AW: AW: Camel Routing using map message help required

prabumca06@gmail.com
My message is mapmessage.

I.e my map message contain key CREDITORDEBIT.I want check if it is credit i want move message or i want discard the message

I have added following code,But this didn't work.

.filter(property(CREDITORDEBIT).isEqualTo(CREDIT))


Please kindly help me.
Reply | Threaded
Open this post in threaded view
|

Re: AW: AW: Camel Routing using map message help required

kraythe
choice()
.when(simple("${body[CREDITORDEBIT]} == true").to(credit_uri).endChoice()
.otherwise().to(debit_uri)
.end()

*Robert Simmons Jr. MSc. - Lead Java Architect @ EA*
*Author of: Hardcore Java (2003) and Maintainable Java (2012)*
*LinkedIn: **http://www.linkedin.com/pub/robert-simmons/40/852/a39*


On Mon, Oct 7, 2013 at 8:45 AM, [hidden email]
<[hidden email]>wrote:

> My message is mapmessage.
>
> I.e my map message contain key CREDITORDEBIT.I want check if it is credit i
> want move message or i want discard the message
>
> I have added following code,But this didn't work.
>
> .filter(property(CREDITORDEBIT).isEqualTo(CREDIT))
>
>
> Please kindly help me.
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Camel-Routing-using-map-message-help-required-tp5740305p5741033.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

Re: AW: AW: Camel Routing using map message help required

kraythe
Ack ... premature submit ... check out the content based router EIP.

http://camel.apache.org/enterprise-integration-patterns.html

*Robert Simmons Jr. MSc. - Lead Java Architect @ EA*
*Author of: Hardcore Java (2003) and Maintainable Java (2012)*
*LinkedIn: **http://www.linkedin.com/pub/robert-simmons/40/852/a39*


On Mon, Oct 7, 2013 at 11:45 AM, kraythe . <[hidden email]> wrote:

> choice()
> .when(simple("${body[CREDITORDEBIT]} == true").to(credit_uri).endChoice()
> .otherwise().to(debit_uri)
> .end()
>
> *Robert Simmons Jr. MSc. - Lead Java Architect @ EA*
> *Author of: Hardcore Java (2003) and Maintainable Java (2012)*
> *LinkedIn: **http://www.linkedin.com/pub/robert-simmons/40/852/a39*
>
>
> On Mon, Oct 7, 2013 at 8:45 AM, [hidden email] <[hidden email]
> > wrote:
>
>> My message is mapmessage.
>>
>> I.e my map message contain key CREDITORDEBIT.I want check if it is credit
>> i
>> want move message or i want discard the message
>>
>> I have added following code,But this didn't work.
>>
>> .filter(property(CREDITORDEBIT).isEqualTo(CREDIT))
>>
>>
>> Please kindly help me.
>>
>>
>>
>>
>> --
>> View this message in context:
>> http://camel.465427.n5.nabble.com/Camel-Routing-using-map-message-help-required-tp5740305p5741033.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: AW: AW: Camel Routing using map message help required

prabumca06@gmail.com
i want use filter not when
Reply | Threaded
Open this post in threaded view
|

Re: AW: AW: Camel Routing using map message help required

prabumca06@gmail.com
In reply to this post by kraythe
Sorry i have copied full code here

I hope it will give you idea what i am trying to achieve

from(ACT_TYPE_SPECFIC_QNAME).choice()
   .when(header(EVENT_TYPE).isEqualTo(ACT_TRANSACTION))          
   .filter(simple("{body[isCredit]} == true"))
   .process(new Processor() {
    public void process(Exchange exchange) {
        Map map = (Map) exchange.getIn().getBody();
        String Account_No = (String) map.get(ACCOUNT_ID);
        Map<String,Object> newBody = new HashMap<String, Object>();
        newBody.put(ACCOUNT_ID, Account_No);
        exchange.getIn().setBody(newBody);                                                        
    }}).to(ACTIVATE_QNAME)
   .endChoice()
   .otherwise()
   .setHeader(DESTINATION, constant(DESTINATION_VALUE))
   .to(EROOR_QNAME)
   .end();
   
Message reached ACT_TYPE_SPECFIC_QNAME but it only checking when ( .when(header(EVENT_TYPE).isEqualTo(ACT_TRANSACTION)) )
condition routing message to ACTIVATE_QNAME

Filter not working property in this case.

Please kindly help me
Reply | Threaded
Open this post in threaded view
|

Re: AW: AW: Camel Routing using map message help required

kraythe
Filter has to be first in the route.

Sent from my iPad

> On Oct 7, 2013, at 12:14 PM, "[hidden email]" <[hidden email]> wrote:
>
> Sorry i have copied full code here
>
> I hope it will give you idea what i am trying to achieve
>
> from(ACT_TYPE_SPECFIC_QNAME).choice()
>   .when(header(EVENT_TYPE).isEqualTo(ACT_TRANSACTION))          
>   .filter(simple("{body[isCredit]} == true"))
>   .process(new Processor() {
>    public void process(Exchange exchange) {
>        Map map = (Map) exchange.getIn().getBody();
>        String Account_No = (String) map.get(ACCOUNT_ID);
>        Map<String,Object> newBody = new HashMap<String, Object>();
>        newBody.put(ACCOUNT_ID, Account_No);
>        exchange.getIn().setBody(newBody);                                                        
>    }}).to(ACTIVATE_QNAME)
>   .endChoice()
>   .otherwise()
>   .setHeader(DESTINATION, constant(DESTINATION_VALUE))
>   .to(EROOR_QNAME)
>   .end();
>
> Message reached ACT_TYPE_SPECFIC_QNAME but it only checking when (
> .when(header(EVENT_TYPE).isEqualTo(ACT_TRANSACTION)) )
> condition routing message to ACTIVATE_QNAME
>
> Filter not working property in this case.
>
> Please kindly help me
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Camel-Routing-using-map-message-help-required-tp5740305p5741049.html
> Sent from the Camel - Users mailing list archive at Nabble.com.