Mykhaylo Adamovych
Mykhaylo Adamovych

Reputation: 20956

create ProducerTemplate for dynamic uri

Common ProducerTemplate usage is to declare a member and annotate with @Produce

@Produce(uri = "direct:start")
protected ProducerTemplate template;

and use as simple as

    String response = (String) template.requestBody(MESSAGE_BODY);

what if my uri is not known at compile time, how could I create ProducerTemplate?

Upvotes: 0

Views: 1051

Answers (2)

soilworker
soilworker

Reputation: 1327

I think you mean something like:

ProducerTemplate template = context.createProducerTemplate();
template.requestBody("direct:start",MESSAGE_BODY);

Upvotes: 2

Ray
Ray

Reputation: 4869

When you send a message using the ProducerTemplate, you can either rely on a default endpoint (specified in the annotation), or you can specify an endpoint directly.

So your example might look like:

String response = template.requestBody("direct:start", MESSAGE_BODY, String.class);

Upvotes: 1

Related Questions