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

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

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

imranrazakhan
This post was updated on .
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") //using repeatCounte=1 so this section get called only once for initialization
        ... *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.
Reply | Threaded
Open this post in threaded view
|

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

Claus Ibsen-2
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 <[hidden email]> 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