You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by gmh <go...@gmail.com> on 2014/11/10 16:43:02 UTC

how to process json and dispatch to several processors

All,
I have a simple use case I am trying to implement.
We will be receiving data from websocket.
I am thinking about using poll consumer pattern to test for now.
Essentially I will have the following json coming thru the activemq queue. 

{name: abc
  address: xyz
}

Where the json does not really matter but how I dispatch the data to
different components is what I am looking for.
I need to be able to rout the json data to different components. I am
thinking about using jsonpath.

Something like this?

from("direct:type")
                      .choice()
                     
.when(PredicateBuilder.isEqualTo(ExpressionBuilder.languageExpression("jsonpath",
"$.kind"), ExpressionBuilder.constantExpression("full")))
                        .to("mock:full")
                        .otherwise()
                        .to("mock:empty");
            }

But the components will be the same just need t send the value of name
(example above) to some component that will do the processing (calling the
db  to do some querying)
So essentially this is the work flow.

Receive a json
Read the json and dispatch the value of the json to some processor to do
some type of querying against the database (find name in db) .  Do this for
each json name:value pair (json wil not change, will always have the same
name:value pairs)  Combine the result for each name:value pair.

Any pointers/ideas as how to implement this type of processing? What kind of
patterns should I implement? Any simple code snippets to illustrate the
points.
I am also thinking about leveraging Akka for this pattern as well since we
have potentially many millions of records and will need to ensure the
processing is done per json and concurrency is guaranteed.
Thanks,
Gordon



--
View this message in context: http://camel.465427.n5.nabble.com/how-to-process-json-and-dispatch-to-several-processors-tp5758838.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: how to process json and dispatch to several processors

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Do you need to route to a "dynamic to" then see this FAQ
http://camel.apache.org/how-to-use-a-dynamic-uri-in-to.html

On Mon, Nov 10, 2014 at 4:43 PM, gmh <go...@gmail.com> wrote:
> All,
> I have a simple use case I am trying to implement.
> We will be receiving data from websocket.
> I am thinking about using poll consumer pattern to test for now.
> Essentially I will have the following json coming thru the activemq queue.
>
> {name: abc
>   address: xyz
> }
>
> Where the json does not really matter but how I dispatch the data to
> different components is what I am looking for.
> I need to be able to rout the json data to different components. I am
> thinking about using jsonpath.
>
> Something like this?
>
> from("direct:type")
>                       .choice()
>
> .when(PredicateBuilder.isEqualTo(ExpressionBuilder.languageExpression("jsonpath",
> "$.kind"), ExpressionBuilder.constantExpression("full")))
>                         .to("mock:full")
>                         .otherwise()
>                         .to("mock:empty");
>             }
>
> But the components will be the same just need t send the value of name
> (example above) to some component that will do the processing (calling the
> db  to do some querying)
> So essentially this is the work flow.
>
> Receive a json
> Read the json and dispatch the value of the json to some processor to do
> some type of querying against the database (find name in db) .  Do this for
> each json name:value pair (json wil not change, will always have the same
> name:value pairs)  Combine the result for each name:value pair.
>
> Any pointers/ideas as how to implement this type of processing? What kind of
> patterns should I implement? Any simple code snippets to illustrate the
> points.
> I am also thinking about leveraging Akka for this pattern as well since we
> have potentially many millions of records and will need to ensure the
> processing is done per json and concurrency is guaranteed.
> Thanks,
> Gordon
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/how-to-process-json-and-dispatch-to-several-processors-tp5758838.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Re: how to process json and dispatch to several processors

Posted by gmh <go...@gmail.com>.
Thanks Claus.
I have came across the Composed Message Processor in my research before and
it does look like something we can leverage.
How do you incorporate JsonPath in this pattern? 
Are there simple test cases I can use to illustrate the use of this pattern?
How about concurrency issue?
Can we ensure the json is processed in a concurrent manner?
Should I consider adding Akka in the solution to ensure concurrency?
Thanks,   Gordon



--
View this message in context: http://camel.465427.n5.nabble.com/how-to-process-json-and-dispatch-to-several-processors-tp5758838p5758847.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: how to process json and dispatch to several processors

Posted by Claus Ibsen <cl...@gmail.com>.
Oh and your use-case may seem a bit like this eip
http://camel.apache.org/composed-message-processor.html

You can more easily do this using the splitter only, so see  the
_splitter only_ section on that page

On Mon, Nov 10, 2014 at 4:43 PM, gmh <go...@gmail.com> wrote:
> All,
> I have a simple use case I am trying to implement.
> We will be receiving data from websocket.
> I am thinking about using poll consumer pattern to test for now.
> Essentially I will have the following json coming thru the activemq queue.
>
> {name: abc
>   address: xyz
> }
>
> Where the json does not really matter but how I dispatch the data to
> different components is what I am looking for.
> I need to be able to rout the json data to different components. I am
> thinking about using jsonpath.
>
> Something like this?
>
> from("direct:type")
>                       .choice()
>
> .when(PredicateBuilder.isEqualTo(ExpressionBuilder.languageExpression("jsonpath",
> "$.kind"), ExpressionBuilder.constantExpression("full")))
>                         .to("mock:full")
>                         .otherwise()
>                         .to("mock:empty");
>             }
>
> But the components will be the same just need t send the value of name
> (example above) to some component that will do the processing (calling the
> db  to do some querying)
> So essentially this is the work flow.
>
> Receive a json
> Read the json and dispatch the value of the json to some processor to do
> some type of querying against the database (find name in db) .  Do this for
> each json name:value pair (json wil not change, will always have the same
> name:value pairs)  Combine the result for each name:value pair.
>
> Any pointers/ideas as how to implement this type of processing? What kind of
> patterns should I implement? Any simple code snippets to illustrate the
> points.
> I am also thinking about leveraging Akka for this pattern as well since we
> have potentially many millions of records and will need to ensure the
> processing is done per json and concurrency is guaranteed.
> Thanks,
> Gordon
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/how-to-process-json-and-dispatch-to-several-processors-tp5758838.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/