아래 경로에서 SEDA 대기열을 사용하여 다른 스레드에서 추가 처리를 위한 fire-and-forget 메시지를 전송하고 이 스레드의 상수 응답을 원래 호출자에게 반환할 수 있도록 이 async 큐에 요청을 보냅니다.
@Test
public void testSendAsync() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Hello World");
// START SNIPPET: e2
Object out = template.requestBody("direct:start", "Hello World");
assertEquals("OK", out);
// END SNIPPET: e2
assertMockEndpointsSatisfied();
}
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
// START SNIPPET: e1
public void configure() throws Exception {
from("direct:start")
// send it to the seda queue that is async
.to("seda:next")
// return a constant response
.transform(constant("OK"));
from("seda:next").to("mock:result");
}
// END SNIPPET: e1
};
}
@Test
public void testSendAsync() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Hello World");
// START SNIPPET: e2
Object out = template.requestBody("direct:start", "Hello World");
assertEquals("OK", out);
// END SNIPPET: e2
assertMockEndpointsSatisfied();
}
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
// START SNIPPET: e1
public void configure() throws Exception {
from("direct:start")
// send it to the seda queue that is async
.to("seda:next")
// return a constant response
.transform(constant("OK"));
from("seda:next").to("mock:result");
}
// END SNIPPET: e1
};
}
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
"Hello World" 메시지는 추가 처리를 위해 다른 스레드의 SEDA 대기열에서 사용됩니다. 이는 단위 테스트에서 수행되므로 단위 테스트에서 어설션을 수행할 수 있는 모
크 엔드포인트로 전송됩니다.