以下のルートでは、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
Hello World メッセージは、さらに処理するために別のスレッドから SEDA キューから消費されます。これはユニットテストからのものであるため、ユニットテストでアサーションを実行できる モック エンドポイントに送信されます。