Camel路由中使用的ActiveMQ递归通配符

时间:2015-04-23 15:50:33

标签: apache-camel activemq wildcard jms-topic

例如,Apache ActiveMQ支持像Camel路由中的主题/队列这样的源的通配符。

The documentation表明有可能递归地匹配这样的模式:

PRICE.STOCK.> 

匹配

PRICE.STOCK.FR.SOUTH
PRICE.STOCK.FR
PRICE.STOCK.UK.NORTH.MANCHESTER

依旧......

然而,在我的例子中,我必须匹配类似的东西,但以特定的单词结尾。

package org.ruffp.camel.quartz;

import org.apache.activemq.camel.component.ActiveMQComponent;
import org.apache.camel.CamelContext;
import org.apache.camel.EndpointInject;
import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;

    public class FromWildcardRouteTest extends CamelTestSupport {

        @Produce(uri = "activemq:topic:TEST.START.NB.1.Mirrored")
        private ProducerTemplate start1;

        @Produce(uri = "activemq:topic:TEST_START.Mirrored")
        private ProducerTemplate start2;

        @EndpointInject(uri = "mock:DEST")
        private MockEndpoint end;

        @Test
        public void testRoute() throws Exception {

            resetMocks();

            end.expectedMessageCount(2);

            start1.sendBody("test-1");
            start2.sendBody("test-2");

            assertMockEndpointsSatisfied();

        }

        @Override
        protected RouteBuilder createRouteBuilder() throws Exception {

            return new RouteBuilder() {

                @Override
                public void configure() throws Exception {

                    //@formatter:off
                    from("activemq:topic:*(.>).Mirrored").routeId("mirrored")
                        .setProperty("TEST_DESC").body()
                        .to(end);
                    //@formatter:on
                }
            };

        }

        @Override
        protected CamelContext createCamelContext() throws Exception {
            CamelContext context = super.createCamelContext();
            String amqUrl = "vm://localhost?broker.persistent=false";

            log.info("Creating Camel Context for AMQ: '{}'", amqUrl);
            context.addComponent("activemq",
                    ActiveMQComponent.activeMQComponent(amqUrl));
            return context;
        }
    }

我想要捕捉的主题包含零个或多个点.一个或多个下划线_,并按.Mirrored结束。

一些示例(所有前缀均为activemq:topic:):

 - TEST_INBOUND.Mirrored            -> catched
 - UK.NORTH.TEST_INBOUND.Mirrored   -> catched
 - FR.SOUTH.TEST_INBOUND.Mirrored   -> catched
 - CH.TEST_INBOUND.Mirrored         -> catched
 - TEST_INBOUND                     -> not catched
 - TEST_INBOUND_Mirrored            -> not catched

1 个答案:

答案 0 :(得分:0)

您无法通过复杂模式进行匹配,例如您尝试,只有文档说明队列名称的起始可以匹配,然后使用>或*作为通配符。这就是它的支持。