Java – Apache camel dynamic consumer
I created this camel route
from("direct:pageExtraction") .bean(PageManager.class,"setProperties(*,${headers})") .filter().method(PageManager.class,"exists").to("seda:pagePostProcessing").end() .to("seda:pageImposition"); from("seda:pagePostProcessing") .bean(PageManager.class,"extractThumbnail(*,${headers})") .bean(PageManager.class,"extractCMYKSeparation(*,"persist(*,"cleanUp(${headers})") .to("seda:pageImposition"); from("seda:pageImposition") .bean(PageManager.class,"extractImposition(*,${headers})") .to("seda:printQueue");
Finally, Seda: printqueue has no consumers, and sending messages in such a route obviously works well Now I want to introduce a new consumer after route initialization. I think I can create a spring bean programmatically and let camel use @ consume (URI = "Seda: printqueue") annotation to get the bean. However, once I create a consumer, camel will complain
org.apache.camel.RuntimeCamelException: org.springframework.beans.factory.NoSuchBeanDeFinitionException: No bean named '4965d710-b5c7-41cf-97e9-a42bdfcea894' is defined]
Any ideas?
[UPDATE]
I have traced the error back to the class that created the new consumer. I am instantiating the printqueue class and then integrating it into the spring context using autowirecapablebeanfactory to execute the factory Autowirebean (printqueueinstance), then factory Initializebean (printqueueinstance, ID), where id is 4965d710-b5c7-41cf-97e9-a42bdfcea894, which appears in the above exception, so I think this must be a context scope problem. It may be that I create this bean on main or web spring and it cannot be accessed through the camel context. Is this possible?
Solution
Since this route is invoked synchronously by using the "direct:" component, "Seda:" does not appear to be required for asynchronous calls to another bean In this case, using camel's bean method to call beans for Java DSL seems the easiest As an example shown in the camel bean document:
http://camel.apache.org/bean.html
I will do this:
// Send message to the bean endpoint // and invoke given method. from("direct:start") // do other stuff in your route .beanRef("beanName","methodName");