You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Sri <sr...@googlemail.com> on 2012/07/05 17:03:19 UTC

creating routes dynamically

Hi,

I wanted to create routes dynamically based on the msg header I receive and
send msg to that route .

This routes can grow to thousands over the period of time. And is it feasble
to have this kind of architecture?.



Regards
Sri


--
View this message in context: http://camel.465427.n5.nabble.com/creating-routes-dynamically-tp5715557.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: creating routes dynamically

Posted by Christian Müller <ch...@gmail.com>.
Yeah, reconsider your design.
and instead of

CamelContext context = new DefaultCamelContext();

the preferred way is

CamelContext context = exchange.getContext();

if you use a processor to build your routes dynamically.

Best,
Christian

On Thu, Jul 5, 2012 at 6:31 PM, Henryk Konsek <he...@gmail.com> wrote:

> Hi Sri,
>
> > I wanted to create routes dynamically based on the msg header I receive
> and
> > send msg to that route .
>
> Yes, you can.
>
> CamelContext context = new DefaultCamelContext();
> context.addRoutes(new RouteBuilder() {
>   @Override
>   public void configure() throws Exception {
>     from("direct:start1").to("log:OUT1");
>   }
> });
> context.start();
> context.createProducerTemplate().sendBody("direct:start1","Hello!");
>
> // Now add route to the running Camel context.
> context.addRoutes(new RouteBuilder() {
>   @Override
>   public void configure() throws Exception {
>     from("direct:start2").to("log:OUT2");
>   }
> });
> // And test it.
> context.createProducerTemplate().sendBody("direct:start2","Hello!");
>
> > This routes can grow to thousands over the period of time. And is it
> feasble
> > to have this kind of architecture?.
>
> From my experience if you need such complex solution, you should
> reconsider design of your architecture. People often over-complicate
> Camel routing. My advice is to keep your integration solution as
> simple as possible. Camel routing is a powerful tool, but this power
> should be used wisely.
>
> Maybe simple RecipentList[1] will match your goals?
>
> Best regards.
>
> [1] http://camel.apache.org/recipient-list.html
>
> --
> Henryk Konsek
> http://henryk-konsek.blogspot.com
>

Re: creating routes dynamically

Posted by Henryk Konsek <he...@gmail.com>.
Hi Sri,

> I wanted to create routes dynamically based on the msg header I receive and
> send msg to that route .

Yes, you can.

CamelContext context = new DefaultCamelContext();
context.addRoutes(new RouteBuilder() {
  @Override
  public void configure() throws Exception {
    from("direct:start1").to("log:OUT1");
  }
});
context.start();
context.createProducerTemplate().sendBody("direct:start1","Hello!");

// Now add route to the running Camel context.
context.addRoutes(new RouteBuilder() {
  @Override
  public void configure() throws Exception {
    from("direct:start2").to("log:OUT2");
  }
});
// And test it.
context.createProducerTemplate().sendBody("direct:start2","Hello!");

> This routes can grow to thousands over the period of time. And is it feasble
> to have this kind of architecture?.

>From my experience if you need such complex solution, you should
reconsider design of your architecture. People often over-complicate
Camel routing. My advice is to keep your integration solution as
simple as possible. Camel routing is a powerful tool, but this power
should be used wisely.

Maybe simple RecipentList[1] will match your goals?

Best regards.

[1] http://camel.apache.org/recipient-list.html

-- 
Henryk Konsek
http://henryk-konsek.blogspot.com

Re: creating routes dynamically

Posted by Henryk Konsek <he...@gmail.com>.
> How ever I wanted to read the messages from these routes
> and But no clue how to inform this routes the which is going to be consumed?

I don't get this sentence, could you elaborate it a little bit?

-- 
Henryk Konsek
http://henryk-konsek.blogspot.com

Re: creating routes dynamically

Posted by Christian Müller <ch...@gmail.com>.
Sri, if this is a new topic, please start a new thread with a meaningful
subject.
If this is the same topic (creating new routes at runtime which listen on
'jms:incomingData1', 'jms:incomingData2', ...), than the solution could
look like:

RouteBuilder rb1 = new RouteBuilder() {
    public void configure() throws Exception {
        from("jms:incomingData1")
            // put your routing logic here
            .to("XXX");
    };
};


RouteBuilder rb2 = new RouteBuilder() {
    public void configure() throws Exception {
        from("jms:incomingData2")
            // put your routing logic here
            .to("XXX");
    };
};

// and so on...

exchange.getContext().addRoutes(rb1);
exchange.getContext().addRoutes(rb2);
// and so on...


But as I mentioned before, you should reconsider such a design...

Best,
Christian

On Fri, Jul 6, 2012 at 11:06 AM, Sri <sr...@googlemail.com> wrote:

> Hi ,
>
> I have used in following way  which works creating routes dynamically.
>
>
> ProducerTemplate template=exchange.getContext().createProducerTemplate();
>
>         Message msg=exchange.getOut();
>         System.err.println("Out msg headers " + msg.getHeaders());
>
>         for(int i=0;i<3;i++){
>                 template.sendBody("jms:incomingData"+i,
> exchange.getIn().getBody());
>         }
>
> may be easy one. How ever I wanted to read the messages from these routes
> and But no clue how to inform this routes the which is going to be
> consumed?
>
> Any Ideas
>
> Sri
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/creating-routes-dynamically-tp5715557p5715595.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: creating routes dynamically

Posted by Sri <sr...@googlemail.com>.
Hi ,

I have used in following way  which works creating routes dynamically.

 
ProducerTemplate template=exchange.getContext().createProducerTemplate();
	 
        Message msg=exchange.getOut();
        System.err.println("Out msg headers " + msg.getHeaders());

        for(int i=0;i<3;i++){
        	template.sendBody("jms:incomingData"+i,
exchange.getIn().getBody());
        }

may be easy one. How ever I wanted to read the messages from these routes
and But no clue how to inform this routes the which is going to be consumed?

Any Ideas

Sri


--
View this message in context: http://camel.465427.n5.nabble.com/creating-routes-dynamically-tp5715557p5715595.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: creating routes dynamically

Posted by Henryk Konsek <he...@gmail.com>.
> You could use a Dynamic Router:

Yeah, I suggest to evaluate Dynamic Router and Recipient List for your
case. In many cases when somebody wants to create routes dynamically
at runtime, she actually needs these two patterns :) .

-- 
Henryk Konsek
http://henryk-konsek.blogspot.com

Re: creating routes dynamically

Posted by James Carman <ja...@carmanconsulting.com>.
You could use a Dynamic Router:

http://camel.apache.org/dynamic-router.html




On Thu, Jul 5, 2012 at 11:03 AM, Sri <sr...@googlemail.com> wrote:
> Hi,
>
> I wanted to create routes dynamically based on the msg header I receive and
> send msg to that route .
>
> This routes can grow to thousands over the period of time. And is it feasble
> to have this kind of architecture?.
>
>
>
> Regards
> Sri
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/creating-routes-dynamically-tp5715557.html
> Sent from the Camel - Users mailing list archive at Nabble.com.