1
Apache ActiveMQ支持例如駱駝路線中的主題/隊列等通配符的通配符。駱駝路線中使用的ActiveMQ遞歸通配符
The documentation顯示有遞歸matche這樣的模式的可能性:
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