1
當前我正在使用choice()
來確定竊聽隊列的切換是否打開。在駱駝中有更好的方法嗎?切換駱駝竊聽隊列
這是我的代碼:
package routes;
import org.apache.camel.builder.RouteBuilder;
public class MyRoute extends RouteBuilder{
private String inQueue;
private String outQueue;
private String wiretapQueue;
private Boolean shouldWiretap;
@Override
public void configure(){
from(inQueue)
.choice()
.when(constant(shouldWiretap))
.wireTap(wiretapQueue)
.end()
.end()
.to(outQueue);
}
public void setInQueue(String inQueue) {
this.inQueue = inQueue;
}
public void setOutQueue(String outQueue) {
this.outQueue = outQueue;
}
public void setWiretapQueue(String wiretapQueue) {
this.wiretapQueue = wiretapQueue;
}
public void setShouldWiretap(boolean shouldWiretap) {
this.shouldWiretap = shouldWiretap;
}
}
我也寫了一個簡單的測試:
package routes;
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 MyRouteTest extends CamelTestSupport {
protected RouteBuilder[] createRouteBuilders() throws Exception {
MyRoute route= new MyRoute();
route.setInQueue("direct:in");
route.setOutQueue("mock:out");
route.setWiretapQueue("mock:wiretap");
route.setShouldWiretap(false);
return new RouteBuilder[] {route};
}
@Test
public void testRouteWithoutWiretap() throws InterruptedException {
template.sendBody("direct:in", "test");
MockEndpoint mockOut = getMockEndpoint("mock:out");
mockOut.expectedMessageCount(1);
mockOut.assertIsSatisfied();
MockEndpoint mockWiretap = getMockEndpoint("mock:wiretap");
mockWiretap.expectedMessageCount(0);
mockWiretap.assertIsSatisfied();
}
}
首先,謝謝。在這種情況下,當souldWiretp標誌爲false時,消息不會進入出隊列。 – panagdu
對不起,當然需要雙重結局。請參閱我的上次編輯 – cslysy
感謝您的回覆和更新。現在看起來不錯:) – panagdu