Hi Claus

Oh, yes, that makes everything more easy!
Thank you so much for your super quick response and your great help!!!

By the way: I love Camel (not the cigarette). Thanks for that great product!

Reto

-----Original Message-----
From: Claus Ibsen <claus.ib...@gmail.com> 
Sent: Friday, 11 August 2023 23:13
To: users@camel.apache.org
Subject: Re: Issue with ProducerTemplate (processor not started)

On Fri, Aug 11, 2023 at 5:08 PM Reto Peter <reto.pe...@advanceit.ch> wrote:

> Hi Claus
>
> You mean I should just change my executeQuery route this way, from 
> dynamic to static?
>
> OLD
> from("direct:executeQuery")
> .toD("sql:${header.sqlquery}")
>
> NEW
> from("direct:executeQuery")
> .setHeader("CamelSqlQuery", simple("${header.sqlquery}"
> .to("sql:SELECT")
>
> Correct?
> But the bean class does still have the injected producerTemplate. The 
> only change is the static call to the sql component
>
>
Yes correct and you can also just set the header from the template and avoid 
the .setHeader in the route

result = producer.requestBodyAndHeader("direct:executeQuery", "", 
"CamelSqlQuery", query);

And since you route is just from direct to sql, you can also call it directly 
from template, and not have that route

result = producer.requestBodyAndHeader("sql:SELECT", "", "CamelSqlQuery", 
query);


> -----Original Message-----
> From: Claus Ibsen <claus.ib...@gmail.com>
> Sent: Friday, 11 August 2023 22:54
> To: users@camel.apache.org
> Subject: Re: Issue with ProducerTemplate (processor not started)
>
> Hi
>
> Its much better to use a header with the dynamic query (key =
> SqlConstants.SQL_QUERY)
> https://camel.apache.org/components/3.21.x/sql-component.html#_message
> _headers
>
> and use a static "to" endpoint then you dont have the overhead of 
> creating a new endpoint/producer per SQL query combination.
>
>
>
>
> On Fri, Aug 11, 2023 at 4:39 PM Reto Peter <reto.pe...@advanceit.ch>
> wrote:
>
> > Hi Claus
> >
> > Thanks for fast response.
> > The call is to an SQL query:
> > result = producer.requestBodyAndHeader("direct:executeQuery", "", 
> > "sqlquery", query);
> >
> > and the route looks like this:
> > from("direct:executeQuery")
> > .routeId("Execute resolvement query")
> > .toD("sql:${header.sqlquery}")
> > ;
> >
> > -----Original Message-----
> > From: Claus Ibsen <claus.ib...@gmail.com>
> > Sent: Friday, 11 August 2023 22:29
> > To: users@camel.apache.org
> > Subject: Re: Issue with ProducerTemplate (processor not started)
> >
> > What endpoint do you send to with the producer template
> >
> > On Fri, Aug 11, 2023 at 4:15 PM Reto Peter <reto.pe...@advanceit.ch>
> > wrote:
> >
> > > Hi
> > >
> > > I got an issue with the ProducerTemplate used inside a bean The 
> > > Bean class called Resolvement.class injects the ProducerTemplate 
> > > as
> > > follows:
> > >
> > >
> > > @EndpointInject
> > >
> > > private ProducerTemplate producer;
> > >
> > > inside the bean resolve() method, I do then use this producer like
> this:
> > >
> > > producer.requestBodyAndHeader(...)
> > >
> > > The method of the bean class is called by a camel route as follows:
> > >
> > > .split(simple("${body}"), new CSVFileAggregator())
> > >
> > > .parallelProcessing()
> > >
> > > .bean(Resolvement.class, "resolve")
> > >
> > > That normally works fine!
> > > But in some cases, I get an error like this:
> > > Caused by: java.lang.IllegalStateException: No producer, this 
> > > processor has not been started: ProducerCache for source: toD20,
> > capacity: 1000
> > >               at
> > >
> > org.apache.camel.support.cache.DefaultProducerCache.doInAsyncProduce
> > r(
> > DefaultProducerCache.java:300)
> > >               at
> > >
> > org.apache.camel.processor.SendDynamicProcessor.process(SendDynamicP
> > ro
> > cessor.java:182)
> > >               at
> > >
> > org.apache.camel.processor.errorhandler.RedeliveryErrorHandler$Simpl
> > eT
> > ask.run(RedeliveryErrorHandler.java:477)
> > >               at
> > >
> > org.apache.camel.impl.engine.DefaultReactiveExecutor$Worker.executeF
> > ro
> > mQueue(DefaultReactiveExecutor.java:212)
> > >               at
> > >
> > org.apache.camel.impl.engine.DefaultReactiveExecutor.executeFromQueu
> > e(
> > DefaultReactiveExecutor.java:77)
> > >               at
> > >
> > org.apache.camel.impl.engine.DefaultAsyncProcessorAwaitManager.await
> > (D
> > efaultAsyncProcessorAwaitManager.java:96)
> > >               at
> > >
> > org.apache.camel.impl.engine.DefaultAsyncProcessorAwaitManager.proce
> > ss
> > (DefaultAsyncProcessorAwaitManager.java:85)
> > >               at
> > >
> > org.apache.camel.impl.engine.SharedCamelInternalProcessor.process(Sh
> > ar
> > edCamelInternalProcessor.java:108)
> > >               at
> > >
> > org.apache.camel.support.cache.DefaultProducerCache.send(DefaultProd
> > uc
> > erCache.java:199)
> > >               at
> > >
> > org.apache.camel.impl.engine.DefaultProducerTemplate.send(DefaultPro
> > du
> > cerTemplate.java:176)
> > >               at
> > >
> > org.apache.camel.impl.engine.DefaultProducerTemplate.send(DefaultPro
> > du
> > cerTemplate.java:172)
> > >               at
> > >
> > org.apache.camel.impl.engine.DefaultProducerTemplate.send(DefaultPro
> > du
> > cerTemplate.java:158)
> > >               at
> > > org.apache.camel.impl.engine.DefaultProducerTemplate.sendBodyAndHe
> > > ad
> > > er
> > > (DefaultProducerTemplate.java:229)
> > >
> > > That means for me, in some situations the Producer is not properly 
> > > initialized.
> > >
> > > My question is:
> > > How can I make sure the producer is initialized properly?
> > > Is this a synchronization issue cause I do use parallelProcessing 
> > > and I must use some synchronizing strategies?
> > > Or what could be the problem or the method to help for this issue?
> > >
> > > Camel Version: 3.20.6
> > > Java: 17
> > > Sping Boot 2.7.12
> > >
> >
> >
> > --
> > Claus Ibsen
> > -----------------
> > @davsclaus
> > Camel in Action 2: https://www.manning.com/ibsen2
> >
>
>
> --
> Claus Ibsen
> -----------------
> @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2
>


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

Reply via email to