You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Imran Raza Khan <im...@gmail.com> on 2019/11/05 11:59:20 UTC

Design Suggestions: Add camel consumer routes dynamically once the application context has already initialized

Consider a situation where our requirement is to listen ActiveMQ Topics and
details of those Topics suppose to be evaluate on base of configuration and
database keeps changing.

Use Case:
1. A initial route start and call External config files and Database to
evaluate topics names.

2. Add the camel consumer routes for above Topic now where application
context already started.

I tried to use pollEnrich but it only pick one message and end the route

        final Main main = new Main();
        main.addRouteBuilder(new MyRoute());
        main.run();

MYRoute:

        from("timer://ipc?repeatCount=1")
        ... *some logic to evaluate topic name* ...
        .setHeader("topic_no",simple("{{env:HOSTNAME}}"))

       .pollEnrich().simple("mqtt:foo?host=tcp://0.0.0.0:1883
        &subscribeTopicNames=${header.topic_no}/status&clientId=ipc")
            .to("log:my?showAll=true&multiline=true");

*** I am not using SpringBoot/Spring so cant use some DI, So looking for
suggestion in JavaDSL.

Re: Design Suggestions: Add camel consumer routes dynamically once the application context has already initialized

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

The CamelContext has API to add new routes at runtime. You can just use that.

On Tue, Nov 5, 2019 at 12:59 PM Imran Raza Khan <im...@gmail.com> wrote:
>
> Consider a situation where our requirement is to listen ActiveMQ Topics and
> details of those Topics suppose to be evaluate on base of configuration and
> database keeps changing.
>
> Use Case:
> 1. A initial route start and call External config files and Database to
> evaluate topics names.
>
> 2. Add the camel consumer routes for above Topic now where application
> context already started.
>
> I tried to use pollEnrich but it only pick one message and end the route
>
>         final Main main = new Main();
>         main.addRouteBuilder(new MyRoute());
>         main.run();
>
> MYRoute:
>
>         from("timer://ipc?repeatCount=1")
>         ... *some logic to evaluate topic name* ...
>         .setHeader("topic_no",simple("{{env:HOSTNAME}}"))
>
>        .pollEnrich().simple("mqtt:foo?host=tcp://0.0.0.0:1883
>         &subscribeTopicNames=${header.topic_no}/status&clientId=ipc")
>             .to("log:my?showAll=true&multiline=true");
>
> *** I am not using SpringBoot/Spring so cant use some DI, So looking for
> suggestion in JavaDSL.



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2