Search in sources :

Example 1 with MyCompletableMessageFuture

use of org.springframework.integration.gateway.TestService.MyCompletableMessageFuture in project spring-integration by spring-projects.

the class GatewayParserTests method startResponder.

private void startResponder(final PollableChannel requestChannel, final MessageChannel replyChannel) {
    Executors.newSingleThreadExecutor().execute(() -> {
        Message<?> request = requestChannel.receive(60000);
        assertNotNull("Request not received", request);
        Message<?> reply = MessageBuilder.fromMessage(request).setCorrelationId(request.getHeaders().getId()).build();
        Object payload = null;
        if (request.getPayload().equals("futureSync")) {
            payload = new AsyncResult<Message<?>>(reply);
        } else if (request.getPayload().equals("flowCompletable")) {
            payload = CompletableFuture.<String>completedFuture("SYNC_COMPLETABLE");
        } else if (request.getPayload().equals("flowCustomCompletable")) {
            MyCompletableFuture myCompletableFuture1 = new MyCompletableFuture();
            myCompletableFuture1.complete("SYNC_CUSTOM_COMPLETABLE");
            payload = myCompletableFuture1;
        } else if (request.getPayload().equals("flowCompletableM")) {
            payload = CompletableFuture.<Message<?>>completedFuture(reply);
        } else if (request.getPayload().equals("flowCustomCompletableM")) {
            MyCompletableMessageFuture myCompletableFuture2 = new MyCompletableMessageFuture();
            myCompletableFuture2.complete(reply);
            payload = myCompletableFuture2;
        }
        if (payload != null) {
            reply = MessageBuilder.withPayload(payload).copyHeaders(reply.getHeaders()).build();
        }
        replyChannel.send(reply);
    });
}
Also used : MyCompletableFuture(org.springframework.integration.gateway.TestService.MyCompletableFuture) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) MyCompletableMessageFuture(org.springframework.integration.gateway.TestService.MyCompletableMessageFuture)

Example 2 with MyCompletableMessageFuture

use of org.springframework.integration.gateway.TestService.MyCompletableMessageFuture in project spring-integration by spring-projects.

the class GatewayParserTests method testCustomCompletableNoAsyncMessage.

@Test
public void testCustomCompletableNoAsyncMessage() throws Exception {
    QueueChannel requestChannel = (QueueChannel) context.getBean("requestChannel");
    final AtomicReference<Thread> thread = new AtomicReference<>();
    requestChannel.addInterceptor(new ChannelInterceptorAdapter() {

        @Override
        public Message<?> preSend(Message<?> message, MessageChannel channel) {
            thread.set(Thread.currentThread());
            return super.preSend(message, channel);
        }
    });
    MessageChannel replyChannel = (MessageChannel) context.getBean("replyChannel");
    this.startResponder(requestChannel, replyChannel);
    TestService service = context.getBean("completableNoAsync", TestService.class);
    MyCompletableMessageFuture result = service.customCompletableReturnsMessage("flowCustomCompletableM");
    Message<?> reply = result.get(10, TimeUnit.SECONDS);
    assertEquals("flowCustomCompletableM", reply.getPayload());
    assertEquals(Thread.currentThread(), thread.get());
    assertNull(TestUtils.getPropertyValue(context.getBean("&completableNoAsync"), "asyncExecutor"));
}
Also used : ChannelInterceptorAdapter(org.springframework.messaging.support.ChannelInterceptorAdapter) QueueChannel(org.springframework.integration.channel.QueueChannel) MessageChannel(org.springframework.messaging.MessageChannel) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) TestService(org.springframework.integration.gateway.TestService) MyCompletableMessageFuture(org.springframework.integration.gateway.TestService.MyCompletableMessageFuture) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Aggregations

MyCompletableMessageFuture (org.springframework.integration.gateway.TestService.MyCompletableMessageFuture)2 Message (org.springframework.messaging.Message)2 GenericMessage (org.springframework.messaging.support.GenericMessage)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Test (org.junit.Test)1 QueueChannel (org.springframework.integration.channel.QueueChannel)1 TestService (org.springframework.integration.gateway.TestService)1 MyCompletableFuture (org.springframework.integration.gateway.TestService.MyCompletableFuture)1 MessageChannel (org.springframework.messaging.MessageChannel)1 ChannelInterceptorAdapter (org.springframework.messaging.support.ChannelInterceptorAdapter)1