简体   繁体   English

连接到Camel- SEDA队列

[英]Connect to Camel- SEDA queue

I am not able to connect to camel route having a SEDA queue. 我无法连接到具有SEDA队列的骆驼路线。 On sever side I have following configuration: 在服务器端,我有以下配置:

<camel:route>
            <camel:from uri="seda:input"/>
            <camel:log  message =">>>>>data is : ${body}"/>
            <camel:inOnly uri="activemq:queue:TESTQUEUE"/>
        </camel:route>

I am trying to hit this route from a standalone client like this: 我正在尝试从这样的独立客户端访问此路由:

public static void main(String[] args) {

        CamelContext context = new DefaultCamelContext();
        producer = context.createProducerTemplate();
            producer.sendBody("seda:input","Hey");

}

But my producer is not able to connect to the seda queue. 但是我的制作人无法连接到seda队列。 Not able to hit queue of my route. 无法到达我的路线队列。 Not able to add camelContext in my bean property. 无法在我的bean属性中添加camelContext。 I am getting "Invalid property 'camelContext' of bean class". 我收到“ bean类的无效属性'camelContext'”。 If I am sending the body to SEDA queue, message is going there but not to the next element of the rout 如果我将尸体发送到SEDA队列,则消息正在发送,但未发送到溃败的下一个元素

As Petter suggested, your client needs to connect to the same Camel Context which the SEDA route is defined in. In your example, it appears that you are creating a new DefaultCamelContext() and trying to send a message through to the route that is defined in another context. 正如Petter所建议的那样,您的客户端需要连接到定义SEDA路由的同一Camel Context。在您的示例中,您似乎正在创建一个新的DefaultCamelContext()并尝试将消息发送到所定义的路由在另一种情况下。

Generally, I define the Camel Context in Spring XML and then inject the context into any classes that need it... 通常,我在Spring XML中定义Camel Context,然后将上下文注入需要它的任何类中。

<camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring">
    <routeBuilder ref="myRouter"/>
</camelContext>

<bean id="myClient" class="com.mycompany.MyClient">
    <property name="camelContext" ref="camelContext"/>
</bean>

Then, your client code would simply need to call the following... 然后,您的客户代码只需要调用以下内容即可...

getCamelContext().createProducerTemplate().sendBody("seda:input","Hey");

That said, if your client code is not in the same JVM or not able to get a handle to the same CamelContext, then your options are to use JMS, REST, HTTP (or any camel component that support remote client interfaces)...instead of or around the SEDA endpoint. 就是说,如果您的客户端代码不在同一JVM中或无法获取同一CamelContext的句柄,那么您的选择是使用JMS,REST,HTTP(或任何支持远程客户端接口的骆驼组件 )...而不是SEDA端点附近。

For example, you could wrap access to your SEDA queue with an HTTP endpoint (via camel-jetty ) like this... 例如,您可以像这样通过HTTP端点(通过camel-jetty )包装对SEDA队列的访问...

from("jetty:http://localhost:9001/input").to("seda:input");

The SEDA component in camel is indended as an asynchrnous internal channel. 骆驼中的SEDA组件旨在作为异步内部通道。 This is very useful if you need to decouple message processing into multiple threads and have a more elastic implementation. 如果您需要将消息处理分离为多个线程并具有更灵活的实现,则此功能非常有用。

In your example, you have an activemq endpoint. 在您的示例中,您有一个activemq端点。 On a conceptual basis, it will do pretty much the same a SEDA component, but with more fetures. 从概念上讲,它将与SEDA组件几乎相同,但功能更多。 I suggest you use activemq or another protocol for clients communicating with Camel. 我建议您对客户端与Camel的通信使用activemq或其他协议。

That said, if your client runs in the same java application as Camel and your client can get hold of the Camel context (which is a design I recommend against in general), you could use ProducerTemplates to send messages to SEDA components. 就是说,如果您的客户端与Camel在同一个Java应用程序中运行,并且您的客户端可以掌握Camel上下文(我通常建议采用这种设计),则可以使用ProducerTemplates将消息发送到SEDA组件。 Look at the VM component, which is pretty much the same as SEDA, but could be used in the same VM instead of the same Camel Context. 看一下VM组件,它与SEDA几乎相同,但是可以在同一VM中使用,而不是在同一Camel Context中使用。 How ProducerTemplate works. ProducerTemplate的工作方式。

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

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