【问题标题】:How to get camel-mqtt endpoint to locate (resolving) my ActiveMQ on openshift/fuse如何让 camel-mqtt 端点在 openshift/fuse 上定位(解析)我的 ActiveMQ
【发布时间】:2015-01-06 08:00:46
【问题描述】:

我对此有点陌生,所以我可能错过了显而易见的事情。

我有一个带 jboss fuse 的 openshift 齿轮。我已经启动了一个带有 mqtt 连接器的 ActiveMQ 代理,并创建了一个骆驼路线(使用 OSGi 蓝图),从同一个 openshift 设备上的 ActiveMQ mqtt 连接器消费。当我使用 ip-address:port 到 mqtt 连接器时,一切正常,但这不是我想要做的。我想要一些其他解决方案(解析器),它不需要我在 mqtt 端点中指出一个特定的 IP 地址,这样我就可以在骆驼路由中移动而无需重新配置它。

ActiveMQ 连接器配置:

   <transportConnectors>
        <transportConnector name="openwire" publishedAddressPolicy="#addressPolicy" uri="tcp://${OPENSHIFT_FUSE_IP}:${OPENSHIFT_FUSE_AMQ_PORT}"/>
        <transportConnector name="mqtt"     publishedAddressPolicy="#addressPolicy" uri="mqtt://${OPENSHIFT_FUSE_IP}:1883"/>
    </transportConnectors>

骆驼路线在起作用时:

<camelContext trace="false" id="blueprintContext" xmlns="http://camel.apache.org/schema/blueprint">
  <route id="mqttToLog">
    <from uri="mqtt:iot?host=tcp://127.4.22.139:1883&amp;subscribeTopicName=mytesttopic&amp;userName=admin&amp;password=xxxxxxx" id="iot_endpoint">
      <description>The MQTT endpoint for consuming data sent from the devices.</description>
    </from>
    <log message="The message contains ${body}" loggingLevel="INFO" id="iot_log">
      <description>Logs all the incoming MQTT messages. This is just for verification purpouses.</description>
    </log>
    <to uri="mock:result" id="iot_mock">
      <description>Final sink for the MQTT message flow. Kept for verification.</description>
    </to>
  </route>
</camelContext>

我的 camel-routes 配置文件将 feature-camel 作为父级,并具有 camel 和 camel-mqtt。

那么,我该如何摆脱实际上必须在端点中指定主机,例如使用 mq 组或其他一些注册表(结构)或类似的?

谢谢,

托马斯

【问题讨论】:

    标签: apache-camel openshift jbossfuse fabric8


    【解决方案1】:

    如果您正在运行一个结构,那么 ActiveMQ 集群功能的工作方式如下:代理是所谓的“代理组”的一部分。默认代理是“默认”组的一部分,这意味着有一个名为mq-client-default 的配置文件。此配置文件将在 OSGi 服务注册表中注册一个预先配置的 ActiveMQ ConnectionFactory。它配置为连接到您的代理所在的任何位置,并将自动故障转移到同一组中的其他代理。

    要在 Fuse 6.1 中使用上述内容,请执行以下操作:

    • 创建一个新的子容器
    • 向其中添加 mq-client-default 配置文件
    • 将功能“mq-fabric-camel”添加到 mq-client-default 配置文件。这将安装一个名为“amq”的骆驼组件,该组件自动使用 mq-client-default 配置文件中的 connectionFactory。
    • 部署如下骆驼路线,见证 JBoss Fuse 的精彩:)

    <camelContext xmlns="http://camel.apache.org/schema/blueprint"> <route id="myRoute"> <from uri="timer://foo?fixedRate=true&amp;period=5000"/> <setBody> <simple>Hello from Camel route to ActiveMQ</simple> </setBody> <to uri="amq:queue:timermessages"/> </route> </camelContext>

    无论broker在哪里,骆驼路由在哪里,这条路由产生的消息都会最终到达broker。

    祝你好运!

    附: amq 组件使用 openwire 与代理通信,但任何其他客户端都可以使用您启用的任何协议来消费或生成消息到您的队列。

    【讨论】:

      猜你喜欢
      • 2018-02-06
      • 2018-10-22
      • 1970-01-01
      • 1970-01-01
      • 2013-01-21
      • 2012-02-23
      • 1970-01-01
      • 2020-02-25
      • 1970-01-01
      相关资源
      最近更新 更多