아래 경로에서 SEDA 대기열을 사용하여 다른 스레드에서 추가 처리를 위해 fire-and-forget 메시지를 보낼 수 있도록 이 비동기 대기열에 요청을 보내고 이 스레드의 지속적인 응답을 원래 호출자로 반환합니다.
@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
추가 처리를 위해 다른 스레드의 SEDA 대기열에서 "Hello World" 메시지가 사용됩니다. 이는 단위 테스트에서이므로 단위 테스트에서 어설션을 수행할 수 있는 mock
엔드포인트로 전송됩니다.