Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Not A Bug
-
3.17.0
-
None
-
None
-
Unknown
Description
I was following the POJO-Producing seciton in the manual in order to have transport agnostic spring beans that produce events. (https://camel.apache.org/manual/pojo-producing.html#_hiding_the_camel_apis_from_your_code)
My setup looks like this:
@Component public class RecorderSender { public static final String ENDPOINT_NAME = "direct:recorderSender?block=true&synchronous=true"; private ProducerEndpoint<byte[]> endpoint; @Produce(RecorderSender.ENDPOINT_NAME) public void setEndpoint(final ProducerEndpoint<byte[]> endpoint) { this.endpoint = endpoint; } public void write(final byte[] payload) { this.endpoint.send(payload); } } @InOnly public interface ProducerEndpoint<T> { void send(T object); }
However once my spring bean is initialized it starts calling RecorderSender.write(byte[]) at a time where the CamelContext is not yet initialized, and I get this exception:
Exception in thread "connector-1" java.lang.IllegalStateException: Producer has not been started: Producer[direct://recorderSender?block=true&synchronous=true] at org.apache.camel.processor.EventNotifierProducer.process(EventNotifierProducer.java:54) at org.apache.camel.impl.engine.DefaultAsyncProcessorAwaitManager.process(DefaultAsyncProcessorAwaitManager.java:83) at org.apache.camel.support.DefaultAsyncProducer.process(DefaultAsyncProducer.java:41) at org.apache.camel.component.bean.AbstractCamelInvocationHandler$1.call(AbstractCamelInvocationHandler.java:189) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) at org.apache.camel.component.bean.AbstractCamelInvocationHandler.doInvoke(AbstractCamelInvocationHandler.java:207) at org.apache.camel.component.bean.AbstractCamelInvocationHandler.invokeProxy(AbstractCamelInvocationHandler.java:169) at org.apache.camel.component.bean.CamelInvocationHandler.doInvokeProxy(CamelInvocationHandler.java:43) at org.apache.camel.component.bean.AbstractCamelInvocationHandler.invoke(AbstractCamelInvocationHandler.java:81) at jdk.proxy2/jdk.proxy2.$Proxy99.send(Unknown Source) at com.example.RecorderSender.write(RecorderSender.java:45) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) at java.base/java.lang.Thread.run(Thread.java:833)
I assumed that the properties block and synchronous would ensure that the call is blocking, regardless of the initialization state of the CamelContext.
I'm not sure whether this is actually a bug, or intentional behavior. But it would be nice to have the POJO Producing guide mentioning this behavior, or hinting at a better solution.