【问题标题】:How to use camel between to server and client's activemq如何在服务器和客户端的activemq之间使用骆驼
【发布时间】:2015-06-08 06:31:42
【问题描述】:

我能够将消息从一个队列发送到同一 activemq 服务器中的另一个队列。 但我的要求是: a)将有两个主机-我的系统(作为服务器)和虚拟机(作为客户端)。 b)两者都有自己的activemq队列和camel。

现在的问题是—— 如何使用服务器的骆驼将消息从服​​务器的队列发送到客户端的队列? 反之亦然。

请帮帮我。任何解决方案将不胜感激。非常感谢

【问题讨论】:

    标签: jakarta-ee jms apache-camel activemq


    【解决方案1】:

    从 Camel 实例连接到不同的服务器是一个非常基本的概念。但是,它在一定程度上取决于您如何配置/部署它。假设您的 Camel 在 ActiveMQ 内的 Spring 中运行,您可以简单地设置两个 camel-activemq 组件。您需要提供正确的代理 URL、队列名称等。

    <bean id="localamq" class="org.apache.activemq.camel.component.ActiveMQComponent" >
            <property name="connectionFactory">
              <bean class="org.apache.activemq.ActiveMQConnectionFactory">
                <property name="brokerURL" value="vm://localhost?create=false"/>
                <property name="userName" value="${activemq.username}"/>
                <property name="password" value="${activemq.password}"/>
              </bean>
            </property>
        </bean>
    
    <bean id="remoteamq" class="org.apache.activemq.camel.component.ActiveMQComponent" >
            <property name="connectionFactory">
              <bean class="org.apache.activemq.ActiveMQConnectionFactory">
                <property name="brokerURL" value="tcp://otherserver:61616"/>
              </bean>
            </property>
        </bean>
    
    
      <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
            <route>
                <from uri="localamq:some.queue"/>
                <to uri="remoteamq:some.other.queue"/>
            </route>
        </camelContext>
    

    【讨论】:

    • 您好,petter,感谢您的回答。但我没有使用弹簧。有可能我 servlet 吗?
    • 当然,无论您如何配置 Camel,请务必启动两个 org.apache.activemq.camel.component.ActiveMQComponent,每个都指向它自己的 ActiveMQConnectionFactory,并将 brokerURL 设置为每个代理。
    • 谢谢彼得。如果你能给我一个 servlet 中的 activemq 和 camel 的例子,我将非常感激。谢谢
    • 不,我没有这样的例子,如果你想要 cmets,请用不起作用的代码更新问题。但是,我的 spring 示例应该很容易转换为您想要的任何配置方法。
    猜你喜欢
    • 1970-01-01
    • 2015-05-05
    • 2014-11-04
    • 1970-01-01
    • 2023-03-12
    • 2011-02-10
    • 1970-01-01
    • 2017-04-15
    • 2020-10-08
    相关资源
    最近更新 更多