Terracotta clustered Camel

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Terracotta clustered Camel

Taylor Gautier
Hi.  

I was inspired by this blog post to learn more about camel, and ultimately I implemented a clustered Component.

Essentially, I wrote a Component which creates endpoints that can be accessed across VMs - something like the VM Component, except the Queues that are created are clustered via Terracotta clustering.

Example code looks like:

Main:
    public static void main(String[] args) throws Exception
    {
        CamelContext context = new DefaultCamelContext();
 
        CamelTemplate template = new CamelTemplate(context);
        context.start();
        for(int i=0;i<10;i++) {
            template.sendBody("tc:input","Test Message: "+i);
        }
        Thread.sleep(1000);
        context.stop();
    }

Main2:
    public static void main(String[] args) throws Exception
    {
        CamelContext context = new DefaultCamelContext();
       
        context.addRoutes(new RouteBuilder() {
            public void configure() {
                from("tc:input").process(new Processor() {
                    public void process(Exchange e) {
                        System.out.println("tc:input " + e.getIn().getBody());
                    }
                });
            }
        });

        System.out.println("Starting camel context");
        context.start();
        Thread.currentThread().join();
    }

And the output running Main2 and then Main looks like:

Starting camel context
tc:input Test Message: 0
tc:input Test Message: 1
tc:input Test Message: 2
tc:input Test Message: 3
tc:input Test Message: 4
tc:input Test Message: 5
tc:input Test Message: 6
tc:input Test Message: 7
tc:input Test Message: 8
tc:input Test Message: 9

If you think this is interesting let me know and I can work out making the project available for broader consumption (it's a very early POC, so it's not really ready for public consumption as I only spent an hour or two figuring out camel)

Taylor