You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by santhosh <ra...@gmail.com> on 2013/03/20 01:28:38 UTC
Camel receipient list with interceptor
My architecture needs to multicast to multiple endpoints which will be
constructed dynamically and before the message is sent to end point it needs
to be customized.Now its like
<multicast parallelProcessing="true" streaming="true"
id="staticrecipient " strategyRef="StringAggregationStrategy"
timeout="2500" onPrepareRef="StringDeepClonePrepare">
<to uri="direct:A" />
<to uri="direct:B" />
</multicast>
<route id="AClient">
<from uri="direct:A" />
<camel:setHeader headerName="A"> <!- some endpoint specific manipulation
similar to this-->
<camel:constant >Sending to A</camel:constant> <!- some endpoint specific
manipulation similar to this-->
</camel:setHeader>
<to uri="http://A.com"></to>
</route>
Now we are moving away from static recipient list list to dynamic recipient
list
<recipientList parallelProcessing="true" streaming="true"
id="dyanmicrecipient " strategyRef="StringAggregationStrategy"
timeout="3000" onPrepareRef="StringDeepClonePrepare">
<what should come here for spring DSL.cant find it in doc.I can use Header
based receipient list but just asking>
*<method(MessageRouter.class, "routeTo")>*
</recipientList >
The method routeTo will return url like A.com,B.com(left out http protocal
due to hyperlink issues) ... depending upon incoming message.i am assuming
camel-http will automatically take care of endpoint creation.correct me if i
am wrong.
Everything is same as previous but except i am trying to do everything
within multicast /recipientList list without defining additional routes
because i dont know the routes during compile time.
1)Can i use onPrep processor in some way.cant think of it because i dont
know which exchange is used for which endpoint.If i know endpoint in
exchange properties , then i think i can manipulate it
very high level of something what i think
public class OnPrepare implements Processor {
public void process(Exchange exchange) throws Exception {
//i know this function doesnt exist
String toURI=exchange.getTOUri()
//then perform endpoint based manipulation of message
}
}
Can opPrep be used for this.is it only for things like clone.
2)Can i use intercept only for receipient list only.
Problems:
1)i dont want to use intercept for whole route and filter based on
predicate.
2)I cant use interceptToSendEndpoint because i dont know endpoint at compile
time.
3)In short,i want to intercept the message. In multicast ,say if its sent to
Endpoint A then add header A in intercept bean.In multicast ,say if its sent
to Endpoint B then add header B in intercept bean.Noting Endpoint A and
Endpoint B will be constructed dynamically and will be in multicast as
probably receipient list.
Can this be done.
3)Whats the best way of doing it.I dont want to move away from Spring DSL.I
know i can mix spring DSL and java DSL.DO you guys think i should
dynamically construct routes/Endpoints using java DSL and invoke them in
multicast/recipientList in spring DSL.Rewrite Entire code in java DSL is the
last option.
Thanks for reading such a long post.Much appreciated.Please let me know if
its confusing. It would be nice if you can answer all three or whichever you
know.
--
View this message in context: http://camel.465427.n5.nabble.com/Camel-receipient-list-with-interceptor-tp5729462.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Camel receipient list with interceptor
Posted by santhosh <ra...@gmail.com>.
I will answer this question myself .You can find the endpoint which the
exchange is used by using
exchange.getProperty("CamelToEndpoint") .
To answer the overall question - how to manipulate the message in
recipient/multicast according to endpoint keeping in mind the endpoint list
will be created dynamically at runtime.What it means is we would know which
endpoints the message needs to be mulitcasted only at runtime and before it
gets sent we need to perform endpoint specific message manipulation.
<recipientList parallelProcessing="true" streaming="true"
id="recipientList" strategyRef="StringAggregationStrategy"
timeout="2500" onPrepareRef="CustomExchangeMessage" delimiter=","
ignoreInvalidEndpoints="true">
<header>endpointList</header>
</recipientList>
The below class is just an idea out of my mind.in real use case the
recipient list will be populated dynamically and the exchange body
manipulation will be dynamic.I dont know if this is the recommended way but
i think it will work .Please let me know if see any obvious problems
public class CustomExchangeMessage implements Processor {
public void process(Exchange exchange) throws Exception {
String body = exchange.getIn().getBody(String.class);
String toEndpoint=exchange.getProperty("CamelToEndpoint");
//this is a simple if now .but this will be where the dynamic part
willl kick in.
if(toEndpoint.equalsIgnoreCase("A"))
{
//manipulate the body for endpoint A
}
if(toEndpoint.equalsIgnoreCase("B"))
{
//manipulate the body for endpoint B
}
}
}
This question has been answered and can be closed.
--
View this message in context: http://camel.465427.n5.nabble.com/Camel-receipient-list-with-interceptor-tp5729462p5729568.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Camel receipient list with interceptor
Posted by santhosh <ra...@gmail.com>.
I have read through it and i couldnt figure anything out for reasons i
mentioned in previous post.Rephrasing my questions short
1)Is there a property in exchange which says the which endpoint the message
is intended for??Can i use it in multicast for identifying the endpoint for
which exchange will be used.
2)Is there a way to intercept message to dynamic endpoint.Endpoint that will
be available only in runtime.
--
View this message in context: http://camel.465427.n5.nabble.com/Camel-receipient-list-with-interceptor-tp5729462p5729549.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Camel receipient list with interceptor
Posted by Claus Ibsen <cl...@gmail.com>.
Hi
Maybe take a look at interceptors
http://camel.apache.org/intercept
On Wed, Mar 20, 2013 at 1:28 AM, santhosh <ra...@gmail.com> wrote:
> My architecture needs to multicast to multiple endpoints which will be
> constructed dynamically and before the message is sent to end point it needs
> to be customized.Now its like
>
> <multicast parallelProcessing="true" streaming="true"
> id="staticrecipient " strategyRef="StringAggregationStrategy"
> timeout="2500" onPrepareRef="StringDeepClonePrepare">
>
> <to uri="direct:A" />
> <to uri="direct:B" />
>
> </multicast>
>
> <route id="AClient">
> <from uri="direct:A" />
> <camel:setHeader headerName="A"> <!- some endpoint specific manipulation
> similar to this-->
> <camel:constant >Sending to A</camel:constant> <!- some endpoint specific
> manipulation similar to this-->
> </camel:setHeader>
> <to uri="http://A.com"></to>
> </route>
>
> Now we are moving away from static recipient list list to dynamic recipient
> list
>
> <recipientList parallelProcessing="true" streaming="true"
> id="dyanmicrecipient " strategyRef="StringAggregationStrategy"
> timeout="3000" onPrepareRef="StringDeepClonePrepare">
>
>
> <what should come here for spring DSL.cant find it in doc.I can use Header
> based receipient list but just asking>
> *<method(MessageRouter.class, "routeTo")>*
>
> </recipientList >
>
> The method routeTo will return url like A.com,B.com(left out http protocal
> due to hyperlink issues) ... depending upon incoming message.i am assuming
> camel-http will automatically take care of endpoint creation.correct me if i
> am wrong.
>
> Everything is same as previous but except i am trying to do everything
> within multicast /recipientList list without defining additional routes
> because i dont know the routes during compile time.
> 1)Can i use onPrep processor in some way.cant think of it because i dont
> know which exchange is used for which endpoint.If i know endpoint in
> exchange properties , then i think i can manipulate it
>
> very high level of something what i think
>
> public class OnPrepare implements Processor {
> public void process(Exchange exchange) throws Exception {
> //i know this function doesnt exist
> String toURI=exchange.getTOUri()
> //then perform endpoint based manipulation of message
>
>
> }
>
> }
>
> Can opPrep be used for this.is it only for things like clone.
>
> 2)Can i use intercept only for receipient list only.
> Problems:
> 1)i dont want to use intercept for whole route and filter based on
> predicate.
> 2)I cant use interceptToSendEndpoint because i dont know endpoint at compile
> time.
> 3)In short,i want to intercept the message. In multicast ,say if its sent to
> Endpoint A then add header A in intercept bean.In multicast ,say if its sent
> to Endpoint B then add header B in intercept bean.Noting Endpoint A and
> Endpoint B will be constructed dynamically and will be in multicast as
> probably receipient list.
>
> Can this be done.
>
> 3)Whats the best way of doing it.I dont want to move away from Spring DSL.I
> know i can mix spring DSL and java DSL.DO you guys think i should
> dynamically construct routes/Endpoints using java DSL and invoke them in
> multicast/recipientList in spring DSL.Rewrite Entire code in java DSL is the
> last option.
>
> Thanks for reading such a long post.Much appreciated.Please let me know if
> its confusing. It would be nice if you can answer all three or whichever you
> know.
>
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Camel-receipient-list-with-interceptor-tp5729462.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
--
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen