3

I would like to create the from(URI) at runtime. I am using the twitter-component to fetch the tweets of the timeline of a user. The username of the user i would like to get from the body of the incoming message.

from("direct:twitterinternal")   // body contains username as string
    .from("twitter://timeline/user?type=direct&user=" + "${body}")

Does camel offer the possibility to create URIs at runtime?

Interfaced
  • 124
  • 3
  • 10

2 Answers2

2

I generally use the recipientList pattern and the simple expression language for dynamic producer routes...

from("direct:twitterinternal")
    .recipientList(simple("twitter://timeline/user?type=direct&user=" + "${body}"))

otherwise, for dynamic consuming, you have 2 options:

Community
  • 1
  • 1
Ben ODay
  • 20,784
  • 9
  • 45
  • 68
  • thanks for the answer!! when i use the recipientList as you explained, the twitter component acts as a producer and posts the body as tweet on the own timeline. – Interfaced May 17 '15 at 20:26
  • yep, this is for producing...if you want a consumer that uses a message to trigger it, then you'll need to use the content enricher – Ben ODay May 18 '15 at 05:38
  • in the [documentation of the Content Enricher](http://camel.apache.org/content-enricher.html) i found the following statement: _pollEnrich does not access any data from the current Exchange which means when polling it cannot use any of the existing headers you may have set on the Exchange. For example you cannot set a filename in the Exchange.FILE_NAME header and use pollEnrich to consume only that file. For that you must set the filename in the endpoint URI._ As i far as i understand it, dynamic uris are not supported (because they are generated when the code is compiled). Am i correct? – Interfaced May 18 '15 at 12:19
  • the enrich() API can use data from the exchange...but not for dynamic URIs (not yet anyways, see https://issues.apache.org/jira/browse/CAMEL-4596)...I think you are stuck with a polling consumer (http://camel.apache.org/polling-consumer.html) and building the URI dynamically there... – Ben ODay May 18 '15 at 16:31
  • otherwise, you can always add/remove routes at runtime programmatically based on user input, etc... – Ben ODay May 18 '15 at 16:33
-1

Camel 2.16 or higher? Try toD.

http://camel.apache.org/message-endpoint.html

rapt
  • 11,810
  • 35
  • 103
  • 145