camel过滤json格式消息

来源:互联网 发布:韩国idol和演员 知乎 编辑:程序博客网 时间:2024/05/17 20:30

格式数据

{    "data": {        "2-6": 1.1    },    "id": "yf-1",    "c": 2}

camel配置文件如下

<?xml version="1.0" encoding="UTF-8"?><blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"           xsi:schemaLocation="      http://www.osgi.org/xmlns/blueprint/v1.0.0      http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"><camelContext xmlns="http://camel.apache.org/schema/blueprint">       <route autoStartup="true"><from uri="mqtt:adv?host=tcp://127.0.0.1:1883&amp;userName=hnyfadmin&amp;password=hnyfadmin&amp;subscribeTopicNames=Samples"/>                      <filter>                    <jsonpath>$.[?(@.c == 2)]</jsonpath>    <to uri="activemq:topic:did?username=hnyfadmin&amp;password=hnyfadmin"/>                </filter>                <filter>                    <jsonpath>$.data[?(@.2-6 == 1.1)]</jsonpath>    <to uri="activemq:topic:data?username=hnyfadmin&amp;password=hnyfadmin"/>                </filter>        </route>    </camelContext></blueprint>

第一个是只取c=2的消息
第二个是取data下面的’2-6’作为过滤条件
这里可以写多个filter,消息来了,会往每个filter都发送一份消息,是同步的

具体的jsonPath表达式参考 http://goessner.net/articles/JsonPath/

camel代码参考 http://camel.apache.org/jsonpath.html

原创粉丝点击