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

-----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.doInAsyncProducer(
> DefaultProducerCache.java:300)
> >               at
> >
> org.apache.camel.processor.SendDynamicProcessor.process(SendDynamicPro
> cessor.java:182)
> >               at
> >
> org.apache.camel.processor.errorhandler.RedeliveryErrorHandler$SimpleT
> ask.run(RedeliveryErrorHandler.java:477)
> >               at
> >
> org.apache.camel.impl.engine.DefaultReactiveExecutor$Worker.executeFro
> mQueue(DefaultReactiveExecutor.java:212)
> >               at
> >
> org.apache.camel.impl.engine.DefaultReactiveExecutor.executeFromQueue(
> DefaultReactiveExecutor.java:77)
> >               at
> >
> org.apache.camel.impl.engine.DefaultAsyncProcessorAwaitManager.await(D
> efaultAsyncProcessorAwaitManager.java:96)
> >               at
> >
> org.apache.camel.impl.engine.DefaultAsyncProcessorAwaitManager.process
> (DefaultAsyncProcessorAwaitManager.java:85)
> >               at
> >
> org.apache.camel.impl.engine.SharedCamelInternalProcessor.process(Shar
> edCamelInternalProcessor.java:108)
> >               at
> >
> org.apache.camel.support.cache.DefaultProducerCache.send(DefaultProduc
> erCache.java:199)
> >               at
> >
> org.apache.camel.impl.engine.DefaultProducerTemplate.send(DefaultProdu
> cerTemplate.java:176)
> >               at
> >
> org.apache.camel.impl.engine.DefaultProducerTemplate.send(DefaultProdu
> cerTemplate.java:172)
> >               at
> >
> org.apache.camel.impl.engine.DefaultProducerTemplate.send(DefaultProdu
> cerTemplate.java:158)
> >               at
> > org.apache.camel.impl.engine.DefaultProducerTemplate.sendBodyAndHead
> > 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

Reply via email to