-2

How do I use a custom bean as a producer endpoint in a camel and then wire it to processing beans or/and consumer beans.

For example I would like to use one of the bean methods to consume data from database and then pass on the results to another method of the same bean or to a another bean to process the data and then pass to a jms queue.

I would like to do something like following but the flow never goes to patstat service

public void configure() throws Exception {
        from("direct:start").bean("patstatService", "getTestData")
        .bean("patstatExtractorAutmn","generatRSSFromData")
        .to("activemq:patstat:test");
    }
burbak
  • 95
  • 1
  • 3
  • 10
  • 1. Are you pushing something to `direct:start` ? 2. Do you have a bean with name `patstatService` ? – pvpkiran Mar 22 '18 at 14:01
  • Spend a bit more time learning Camel and study the examples. The direct endpoint on the consumer, does nothing by default. You need to send a message to it, either from another route, or via something like the `ProducerTemplate`. – Claus Ibsen Mar 22 '18 at 14:18

2 Answers2

1

I could not find a direct way to consume from bean. For my usecase scheduling to consume from the bean every second might work. So for now the following does the work but I hope that there is a way to directly consume from the bean as this a valid use case and in my opinion quite useful.

public void configure() throws Exception {
         from("timer:patstat?period=1s").bean("patstatService", "getTestData")
        .bean("patstatExtractorAutmn","generatRSSFromData")
        .to("activemq:patstat:test");
    }
burbak
  • 95
  • 1
  • 3
  • 10
0

Another solution could be to invoke the bean just once when the route starts and put the processing logic in the bean as follows:

from("timer:patstat?repeatCount=1").threads().bean("patstatService", "getData").routeId(""+startYear);
burbak
  • 95
  • 1
  • 3
  • 10