You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Jeff Segal <je...@gmail.com> on 2011/07/14 19:41:09 UTC
Adding properties to an Exchange
I'd like to know the best way to add domain-specific context information to
Exchanges linked to a particular RouteBuilder. Let's say that I have the
following:
public class MyRouteBuilder extends RouteBuilder {
String someProperty;
@Override
public void configure() throws Exception {
from("direct:foo").to("bean:myBean");
}
}
public class MyBean {
public void handle(Exchange exchange) {
// Want to access 'someProperty' of MyRouteBuilder here
}
}
One way that I believe would work here would be to add a Processor to the
Route which called exchange.setProperty(), then access it in MyBean via
exchange.getProperty(). However, I'm curious if there is an easier/more
preferred way of doing this.
Thanks,
Jeff
Re: Adding properties to an Exchange
Posted by Donald Whytock <dw...@gmail.com>.
Sorry...make that
http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/model/ProcessorDefinition.html#setProperty(java.lang.String,
org.apache.camel.Expression)
On Thu, Jul 14, 2011 at 1:51 PM, Donald Whytock <dw...@gmail.com> wrote:
> Actually, you don't need the Processor, if it's a relatively static
> value. You can use
>
> from().setProperty().to()
>
> http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/model/ProcessorDefinition.html#setProperty(java.lang.String)
>
> Don
>
> On Thu, Jul 14, 2011 at 1:41 PM, Jeff Segal <je...@gmail.com> wrote:
>> I'd like to know the best way to add domain-specific context information to
>> Exchanges linked to a particular RouteBuilder. Let's say that I have the
>> following:
>>
>> public class MyRouteBuilder extends RouteBuilder {
>>
>> String someProperty;
>>
>> @Override
>> public void configure() throws Exception {
>> from("direct:foo").to("bean:myBean");
>> }
>>
>> }
>>
>> public class MyBean {
>> public void handle(Exchange exchange) {
>> // Want to access 'someProperty' of MyRouteBuilder here
>> }
>> }
>>
>> One way that I believe would work here would be to add a Processor to the
>> Route which called exchange.setProperty(), then access it in MyBean via
>> exchange.getProperty(). However, I'm curious if there is an easier/more
>> preferred way of doing this.
>>
>> Thanks,
>> Jeff
>>
>
Re: Adding properties to an Exchange
Posted by Donald Whytock <dw...@gmail.com>.
Actually, you don't need the Processor, if it's a relatively static
value. You can use
from().setProperty().to()
http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/model/ProcessorDefinition.html#setProperty(java.lang.String)
Don
On Thu, Jul 14, 2011 at 1:41 PM, Jeff Segal <je...@gmail.com> wrote:
> I'd like to know the best way to add domain-specific context information to
> Exchanges linked to a particular RouteBuilder. Let's say that I have the
> following:
>
> public class MyRouteBuilder extends RouteBuilder {
>
> String someProperty;
>
> @Override
> public void configure() throws Exception {
> from("direct:foo").to("bean:myBean");
> }
>
> }
>
> public class MyBean {
> public void handle(Exchange exchange) {
> // Want to access 'someProperty' of MyRouteBuilder here
> }
> }
>
> One way that I believe would work here would be to add a Processor to the
> Route which called exchange.setProperty(), then access it in MyBean via
> exchange.getProperty(). However, I'm curious if there is an easier/more
> preferred way of doing this.
>
> Thanks,
> Jeff
>
Re: Adding properties to an Exchange
Posted by Jeff Segal <je...@gmail.com>.
Thanks all - lots of good suggestions for me to look into.
Claus - I should have added that in my notional example, I did not intend
either Bean to be a singleton. So I need a more dynamic strategy than simply
setting static properties using IoC. That said, I should be able to find a
good solution by following Ben and Donald's advice.
Cheers,
Jeff
On Thu, Jul 14, 2011 at 2:01 PM, Claus Ibsen <cl...@gmail.com> wrote:
> On Thu, Jul 14, 2011 at 7:41 PM, Jeff Segal <je...@gmail.com>
> wrote:
> > I'd like to know the best way to add domain-specific context information
> to
> > Exchanges linked to a particular RouteBuilder. Let's say that I have the
> > following:
> >
> > public class MyRouteBuilder extends RouteBuilder {
> >
> > String someProperty;
> >
> > @Override
> > public void configure() throws Exception {
> > from("direct:foo").to("bean:myBean");
> > }
> >
> > }
> >
> > public class MyBean {
> > public void handle(Exchange exchange) {
> > // Want to access 'someProperty' of MyRouteBuilder here
> > }
> > }
> >
> > One way that I believe would work here would be to add a Processor to the
> > Route which called exchange.setProperty(), then access it in MyBean via
> > exchange.getProperty(). However, I'm curious if there is an easier/more
> > preferred way of doing this.
> >
>
> This is not really Camel specific as you have 2 java beans:
> - MyRouteBuilder
> - MyBean
>
> And you need to access the instance of MyRouteBuilder from the
> instance of MyBean.
> For that you can do IoC stuff.
>
>
>
> > Thanks,
> > Jeff
> >
>
>
>
> --
> Claus Ibsen
> -----------------
> FuseSource
> Email: cibsen@fusesource.com
> Web: http://fusesource.com
> Twitter: davsclaus, fusenews
> Blog: http://davsclaus.blogspot.com/
> Author of Camel in Action: http://www.manning.com/ibsen/
>
Re: Adding properties to an Exchange
Posted by Claus Ibsen <cl...@gmail.com>.
On Thu, Jul 14, 2011 at 7:41 PM, Jeff Segal <je...@gmail.com> wrote:
> I'd like to know the best way to add domain-specific context information to
> Exchanges linked to a particular RouteBuilder. Let's say that I have the
> following:
>
> public class MyRouteBuilder extends RouteBuilder {
>
> String someProperty;
>
> @Override
> public void configure() throws Exception {
> from("direct:foo").to("bean:myBean");
> }
>
> }
>
> public class MyBean {
> public void handle(Exchange exchange) {
> // Want to access 'someProperty' of MyRouteBuilder here
> }
> }
>
> One way that I believe would work here would be to add a Processor to the
> Route which called exchange.setProperty(), then access it in MyBean via
> exchange.getProperty(). However, I'm curious if there is an easier/more
> preferred way of doing this.
>
This is not really Camel specific as you have 2 java beans:
- MyRouteBuilder
- MyBean
And you need to access the instance of MyRouteBuilder from the
instance of MyBean.
For that you can do IoC stuff.
> Thanks,
> Jeff
>
--
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/
Re: Adding properties to an Exchange
Posted by boday <be...@initekconsulting.com>.
If you want to apply common decoration to all messages/routes, then use an
http://camel.apache.org/intercept.html interceptor strategy
Otherwise, using a Bean or Processor is fine and can be reused across routes
easily as well, etc.
Jeff Segal wrote:
>
> I'd like to know the best way to add domain-specific context information
> to
> Exchanges linked to a particular RouteBuilder. Let's say that I have the
> following:
>
> public class MyRouteBuilder extends RouteBuilder {
>
> String someProperty;
>
> @Override
> public void configure() throws Exception {
> from("direct:foo").to("bean:myBean");
> }
>
> }
>
> public class MyBean {
> public void handle(Exchange exchange) {
> // Want to access 'someProperty' of MyRouteBuilder here
> }
> }
>
> One way that I believe would work here would be to add a Processor to the
> Route which called exchange.setProperty(), then access it in MyBean via
> exchange.getProperty(). However, I'm curious if there is an easier/more
> preferred way of doing this.
>
> Thanks,
> Jeff
>
-----
Ben O'Day
IT Consultant -http://consulting-notes.com
--
View this message in context: http://camel.465427.n5.nabble.com/Adding-properties-to-an-Exchange-tp4587592p4587635.html
Sent from the Camel - Users mailing list archive at Nabble.com.