git.net

[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


Btw mind that in very latest Camel releases we have optimised the http
endpoints to try to auto-detect the dynamic aspects of the
context-path and optimise themselves.
So in that case you may not need to use the header. But I cannot
recall without looking in the source, whether we allowed this
optimisation to happen on producer template level too (in routes it
would do it)
On Mon, Dec 3, 2018 at 7:18 PM Claus Ibsen <claus.ibsen@xxxxxxxxx> wrote:
>
> 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



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