JMS 选择器,用于带有 Camel 和 Blueprint 的 header 下划线的消息
JMS Selector for messages having an underscore in one header with Camel and Blueprint
我需要清理 JMS
queue (ActiveMQ) 中的一些消息,其中一些消息 header 包含下划线。
一些例子
Message 1:
header MyObject=urn:sap:order:ID1234
body = <some xml>
Message 2:
header MyObject=urn:sap:order:ID9834_ABC
body = <some xml>
我的目标是从原始 queue 中移动唯一看起来像 Message 2
的消息(以及所有包含下划线的类似消息)而不是不带下划线的消息(例如 Message 1
)MY_ORDERS
.
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd
http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.1.0.xsd">
<cm:property-placeholder persistent-id="com.mycompany.order-temp" update-strategy="reload">
<cm:default-properties>
<cm:property name="amq.url" value="tcp://localhost:61616" />
<cm:property name="queue.to.dump" value="activemq:queue:MY_ORDERS?selector=MyObject+LIKE+'urn:order:%_%'" />
</cm:default-properties>
</cm:property-placeholder>
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<onException useOriginalMessage="true">
<exception>java.lang.Exception</exception>
<handled>
<constant>true</constant>
</handled>
<to uri="activemq:queue:MY_ORDERS_DLQ?preserveMessageQos=true" />
</onException>
<route id="route-orders-to-temp">
<from uri="{{queue.to.dump}}" />
<to uri="activemq:queue:MY_ORDERS_TEMP" />
</route>
</camelContext>
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="brokerURL" value="${amq.url}" />
</bean>
</blueprint>
通过使用以下帖子,因为关于选择器的官方 ActiveMQ Documentation 说它使用 SQL 92 syntax
:
我尝试了以下所有组合:
selector=MyObject+LIKE+'urn:sap:order:%_%'
selector=MyObject+LIKE+'urn:sap:order:%_%'
selector=MyObject+LIKE+'urn:sap:order:%\_%'
selector=MyObject+LIKE+'urn:sap:order:%[_]%'
selector=MyObject+LIKE+'urn:sap:order:[a-Z0-9]*_[a-Z0-9]*'
但其中 none 似乎有效。有什么想法吗?
最后我找到了问题的解决方案:有一种特殊的语法来定义转义字符,默认情况下似乎没有设置。
通过在互联网上查找,我终于找到了following post,它清楚地表明下划线必须通过例如转义。 \
然后用 ESCAPE '\'
定义转义字符
如果我将以下几行应用于我的案例:
selector=MyObject+LIKE+'urn:sap:order:%_%' ESCAPE '\'
selector=MyObject+LIKE+'urn:sap:order:%\_%' ESCAPE '\'
将与选择器末尾的附加 ESCAPE '\'
一起正常工作。
我需要清理 JMS
queue (ActiveMQ) 中的一些消息,其中一些消息 header 包含下划线。
一些例子
Message 1:
header MyObject=urn:sap:order:ID1234
body = <some xml>
Message 2:
header MyObject=urn:sap:order:ID9834_ABC
body = <some xml>
我的目标是从原始 queue 中移动唯一看起来像 Message 2
的消息(以及所有包含下划线的类似消息)而不是不带下划线的消息(例如 Message 1
)MY_ORDERS
.
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd
http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.1.0.xsd">
<cm:property-placeholder persistent-id="com.mycompany.order-temp" update-strategy="reload">
<cm:default-properties>
<cm:property name="amq.url" value="tcp://localhost:61616" />
<cm:property name="queue.to.dump" value="activemq:queue:MY_ORDERS?selector=MyObject+LIKE+'urn:order:%_%'" />
</cm:default-properties>
</cm:property-placeholder>
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<onException useOriginalMessage="true">
<exception>java.lang.Exception</exception>
<handled>
<constant>true</constant>
</handled>
<to uri="activemq:queue:MY_ORDERS_DLQ?preserveMessageQos=true" />
</onException>
<route id="route-orders-to-temp">
<from uri="{{queue.to.dump}}" />
<to uri="activemq:queue:MY_ORDERS_TEMP" />
</route>
</camelContext>
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="brokerURL" value="${amq.url}" />
</bean>
</blueprint>
通过使用以下帖子,因为关于选择器的官方 ActiveMQ Documentation 说它使用 SQL 92 syntax
:
我尝试了以下所有组合:
selector=MyObject+LIKE+'urn:sap:order:%_%'
selector=MyObject+LIKE+'urn:sap:order:%_%'
selector=MyObject+LIKE+'urn:sap:order:%\_%'
selector=MyObject+LIKE+'urn:sap:order:%[_]%'
selector=MyObject+LIKE+'urn:sap:order:[a-Z0-9]*_[a-Z0-9]*'
但其中 none 似乎有效。有什么想法吗?
最后我找到了问题的解决方案:有一种特殊的语法来定义转义字符,默认情况下似乎没有设置。
通过在互联网上查找,我终于找到了following post,它清楚地表明下划线必须通过例如转义。 \
然后用 ESCAPE '\'
如果我将以下几行应用于我的案例:
selector=MyObject+LIKE+'urn:sap:order:%_%' ESCAPE '\'
selector=MyObject+LIKE+'urn:sap:order:%\_%' ESCAPE '\'
将与选择器末尾的附加 ESCAPE '\'
一起正常工作。