45.9. 示例
在以下路由中,我们使用 SEDA 队列将请求发送到这个 async 队列,以便能够向另一个线程发送 fire-and-forget 消息,并将此线程中的恒定回复返回到原始调用者。
我们发送 Hello World 消息,并期望回复正常。
    @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
        };
    }
				"Hello World"消息将从另一个线程中的 SEDA 队列消耗,以进一步处理。由于这来自单元测试,它将发送到 模拟 端点,在单元测试中我们可以执行断言。