如何让camel-mqtt端点在openshift / fuse上定位(解析)我的ActiveMQ

时间:2015-01-06 08:00:47

标签: apache-camel openshift jbossfuse fabric8

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

我有一个装有jboss保险丝的openhift装备。我已经启动了一个带有mqtt连接器的ActiveMQ代理,并在相同的openhift设备上创建了一个使用ActiveMQ mqtt连接器消耗的驼峰路径(使用OSGi蓝图)。当我使用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>

Camel-Route工作时:

<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组,或其他一些注册表(结构)或类似的?

谢谢,

托马斯

1 个答案:

答案 0 :(得分:0)

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

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

  • 创建新的子容器
  • 将mq-client-default配置文件添加到其中
  • 将功能“mq-fabric-camel”添加到mq-client-default配置文件中。这将安装一个名为“amq”的camel组件,它自动使用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>

此路由生成的消息将终止于经纪人,无论经纪人在哪里,或者是骆驼路线的位置。

祝你好运!

P.S。 amq组件使用openwire与代理进行通信,但任何其他客户端都可以使用您启用的任何协议来消耗或向队列生成消息。

相关问题