0

I'm new to Camel and am trying to setup a very simple app to get used to it with, i'm running the following code:

CamelContext cc = (CamelContext)ac.getBean("testCamelContext");
ProducerTemplate template = cc.createProducerTemplate();
System.out.println("Sending Message Body");
template.sendBody("seda:testProducer", "hello");
System.out.println("Sent");

Which runs fine but my consumer never seems to pick up the message, I get the following on console:

[                          main] SpringCamelContext             INFO  Apache Camel 2.10.2 (CamelContext: testCamelContext) is starting
[                          main] ManagementStrategyFactory      INFO  JMX enabled.
[                          main] DefaultTypeConverter           INFO  Loaded 172 type converters
[                          main] SpringCamelContext             INFO  Route: route1 started and consuming from: Endpoint[seda://testProducer]
[                          main] ultManagementLifecycleStrategy INFO  StatisticsLevel at All so enabling load performance statistics
[                          main] SpringCamelContext             INFO  Total 1 routes, of which 1 is started.
[                          main] SpringCamelContext             INFO  Apache Camel 2.10.2 (CamelContext: testCamelContext) started in 0.373 seconds
Init Context
SendingMessage
Sending Message Body
Sent

Using the following camel context:

<camel:camelContext id="testCamelContext">
    <camel:routeBuilder ref="testCamelRouteBuilder"/>
</camel:camelContext>

And RouteBuilder rule:

from("seda:testProducer").beanRef("testConsumer","consumeMessage");

And the following consumer bean:

public class TestConsumer {
    public void consumeMessage(String msg)
    {
        System.out.println("Message: " + msg);
    }
}

All the beans are fine and camel seems to detect the rule ok so I'm not sure what I've done wrong. I'm obviously not using something correctly?

James
  • 1,237
  • 4
  • 22
  • 43

1 Answers1

1

Realised mistake; because seda is asynchronous, the main thread was finishing before the consumer thread had a chance to receive the message. Added a thread.sleep() and it was working perfectly.

James
  • 1,237
  • 4
  • 22
  • 43