简体   繁体   English

Apache Camel动态消费者

[英]Apache Camel Dynamic Consumers

I have created this Camel routes 我创建了这个Camel路线

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(*, ${headers})")
            .bean(PageManager.class, "persist(*, ${headers})")
            .bean(PageManager.class, "cleanUp(${headers})")
            .to("seda:pageImposition");

            from("seda:pageImposition")
            .bean(PageManager.class, "extractImposition(*, ${headers})")
            .to("seda:printQueue");

At the end, the seda:printQueue has no consumers, sending a message in a route like this apparently works fine. 最后,seda:printQueue没有消费者,在这样的路线中发送消息显然工作正常。 Now I want to introduce a new consumer after the routes have been initialized, I thought it would be possible to create a Spring bean programmatically and let Camel pick up the bean using the @Consume(uri="seda:printQueue") annotation, but as soon as I create the consumer Camel complains 现在我想在路由初始化之后引入一个新的消费者,我认为可以用编程方式创建一个Spring bean,让Camel使用@Consume(uri="seda:printQueue")注释来获取bean,但是一旦我创建消费者,Camel就会抱怨

org.apache.camel.RuntimeCamelException: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named '4965d710-b5c7-41cf-97e9-a42bdfcea894' is defined]

Any thoughts? 有什么想法吗?

[UPDATE] [UPDATE]

I have traced back the error to the class where this new consumer is created, I'm instantiating the PrintQueue class and then integrating it to the Spring context using an AutowireCapableBeanFactory doing a factory.autowireBean(printQueueInstance) followed by factory.initializeBean(printQueueInstance, id) where id is the 4965d710-b5c7-41cf-97e9-a42bdfcea894 that appears in the exception above, so I think this has to be some kind of context scope problem, may be I am creating this bean in the main or web Spring context and it can't be access by the Camel context, is this possible? 我已经将错误追溯到创建这个新消费者的类,我正在实例化PrintQueue类,然后使用AutowireCapableBeanFactory将它集成到Spring上下文中,执行factory.autowireBean(printQueueInstance)然后是factory.initializeBean(printQueueInstance, id)其中id4965d710-b5c7-41cf-97e9-a42bdfcea894 ,它出现在上面的异常中,所以我认为这必须是某种上下文范围问题,可能是我在main或web Spring上创建这个bean并且它无法通过Camel上下文访问,这可能吗?

Since this route is invoked synchronously via use of the "direct:" component, it does not appear to require "seda:" for asynchronous invocation of another bean. 由于通过使用“direct:”组件同步调用此路由,因此对于另一个bean的异步调用似乎不需要“seda:”。 In this situation, it would appear simplest to invoke a bean with Camel's bean methods for the Java DSL. 在这种情况下,使用Camel的bean方法为Java DSL调用bean似乎最简单。 As an example shown in the Camel bean documentation at: 作为Camel bean文档中显示的示例:

http://camel.apache.org/bean.html http://camel.apache.org/bean.html

I would simply do: 我会这样做:

// Send message to the bean endpoint
// and invoke given method.
from("direct:start")
  // do other stuff in your route
   .beanRef("beanName", "methodName");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM