codehaus


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how could I get multiple different ProducerTemplate instances with Auto-Configured Producer Templates


Hi

No you can use the same template to send to multiple endpoints.

Just beware that sending to unlimited number of endpoints uris is not
a good practice as an endpoint / producer takes up resource. So in
your case with the HTTP endpoint, then its better to use a static uri
for the hostname and then a header with the dynamic context-path, then
you reuse the same endpoint / producer when doing network connection
to the remote http server.


On Thu, Nov 29, 2018 at 12:42 AM Wang Yan <stewchicken@xxxxxxxxx> wrote:
>
> If I use the auto configured ProducerTemplate, how could I get multiple
> different ProducerTemplate instances?
>
> for example I need use producer template send different exchanges to
> different endpoints
> in this case, Do i need different producer template instances? if yes how ?
> Auto-Configured Consumer and Producer Templates
>
> Camel auto-configuration provides pre-configured *ConsumerTemplate* and
> *ProducerTemplate* instances. You can simply inject them into your
> Spring-managed beans:
>
> @Component
> public class InvoiceProcessor {
>
>   @Autowired
>   private ProducerTemplate producerTemplate;
>
>   @Autowired
>   private ConsumerTemplate consumerTemplate;
>   public void processNextInvoice() {
>     Invoice invoice = consumerTemplate.receiveBody("jms:invoices",
> Invoice.class);
>     ...
>     producerTemplate.sendBody("netty-http:http://invoicing.com/received/";
> + invoice.id());
>   }
> }



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2