0

I need to cleanup some messages in a JMS queue (ActiveMQ) where some of the message header contains an underscore.

Some example

Message 1: 
    header MyObject=urn:sap:order:ID1234
    body = <some xml>


Message 2: 
    header MyObject=urn:sap:order:ID9834_ABC
    body = <some xml>

My goal is to move the only messages looking like Message 2 (and all similar containing an underscore) and not messages without underscores (like Message 1) from the original queue 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:%&#95;%'" />
        </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>

By using the following posts and because the official ActiveMQ Documentation about selectors says it uses SQL 92 syntax:

I tried all the following combinations:

selector=MyObject+LIKE+'urn:sap:order:%&#95;%'
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]*'

But none of them seems to work. Any thoughts?

рüффп
  • 5,172
  • 34
  • 67
  • 113

1 Answers1

0

Finally I found the solution of my problem: there is a special syntax to define the escaping character which does not seems to be set by default.

By looking on Internet I finally found the following post which clearly shows the underscore must be escaped by e.g. \ then defining the escape character with ESCAPE '\'

If I apply to my cases the following lines:

selector=MyObject+LIKE+'urn:sap:order:%&#95;%' ESCAPE '\'
selector=MyObject+LIKE+'urn:sap:order:%\_%' ESCAPE '\'

will just work fine with the additional ESCAPE '\' at the end of the selector.

рüффп
  • 5,172
  • 34
  • 67
  • 113