Search in sources :

Example 71 with Message

use of org.springframework.messaging.Message in project spring-integration by spring-projects.

the class GatewayParserTests method testAsyncDisabledGateway.

@Test
public void testAsyncDisabledGateway() throws Exception {
    PollableChannel requestChannel = (PollableChannel) context.getBean("requestChannel");
    MessageChannel replyChannel = (MessageChannel) context.getBean("replyChannel");
    this.startResponder(requestChannel, replyChannel);
    TestService service = context.getBean("asyncOff", TestService.class);
    Future<Message<?>> result = service.async("futureSync");
    Message<?> reply = result.get(10, TimeUnit.SECONDS);
    assertEquals("futureSync", reply.getPayload());
    Object serviceBean = context.getBean("&asyncOff");
    assertNull(TestUtils.getPropertyValue(serviceBean, "asyncExecutor"));
}
Also used : MessageChannel(org.springframework.messaging.MessageChannel) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) TestService(org.springframework.integration.gateway.TestService) PollableChannel(org.springframework.messaging.PollableChannel) Test(org.junit.Test)

Example 72 with Message

use of org.springframework.messaging.Message in project spring-integration by spring-projects.

the class GatewayParserTests method testCustomCompletableNoAsync.

@Test
public void testCustomCompletableNoAsync() 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);
    MyCompletableFuture result = service.customCompletable("flowCustomCompletable");
    String reply = result.get(10, TimeUnit.SECONDS);
    assertEquals("SYNC_CUSTOM_COMPLETABLE", reply);
    assertEquals(Thread.currentThread(), thread.get());
    assertNull(TestUtils.getPropertyValue(context.getBean("&completableNoAsync"), "asyncExecutor"));
}
Also used : MyCompletableFuture(org.springframework.integration.gateway.TestService.MyCompletableFuture) 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) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Example 73 with Message

use of org.springframework.messaging.Message in project spring-integration by spring-projects.

the class GatewayParserTests method testMonoGateway.

@Test
public void testMonoGateway() throws Exception {
    PollableChannel requestChannel = context.getBean("requestChannel", PollableChannel.class);
    MessageChannel replyChannel = context.getBean("replyChannel", MessageChannel.class);
    this.startResponder(requestChannel, replyChannel);
    TestService service = context.getBean("promise", TestService.class);
    Mono<Message<?>> result = service.promise("foo");
    Message<?> reply = result.block(Duration.ofSeconds(1));
    assertEquals("foo", reply.getPayload());
    assertNotNull(TestUtils.getPropertyValue(context.getBean("&promise"), "asyncExecutor"));
}
Also used : MessageChannel(org.springframework.messaging.MessageChannel) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) TestService(org.springframework.integration.gateway.TestService) PollableChannel(org.springframework.messaging.PollableChannel) Test(org.junit.Test)

Example 74 with Message

use of org.springframework.messaging.Message in project spring-integration by spring-projects.

the class GatewayParserTests method testAsyncCompletableNoAsync.

@Test
public void testAsyncCompletableNoAsync() 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);
    CompletableFuture<String> result = service.completable("flowCompletable");
    String reply = result.get(10, TimeUnit.SECONDS);
    assertEquals("SYNC_COMPLETABLE", reply);
    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) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Example 75 with Message

use of org.springframework.messaging.Message in project spring-integration by spring-projects.

the class TestAnnotatedEndpointWithDefaultAggregator method aggregatingMethod.

@Aggregator(inputChannel = "inputChannel")
public Message<?> aggregatingMethod(List<Message<?>> messages) {
    List<Message<?>> sortableList = new ArrayList<>(messages);
    Collections.sort(sortableList, new MessageSequenceComparator());
    StringBuffer buffer = new StringBuffer();
    Object correlationId = null;
    for (Message<?> message : sortableList) {
        buffer.append(message.getPayload().toString());
        if (null == correlationId) {
            correlationId = new IntegrationMessageHeaderAccessor(message).getCorrelationId();
        }
    }
    Message<?> returnedMessage = new GenericMessage<>(buffer.toString());
    this.aggregatedMessages.put(correlationId, returnedMessage);
    return returnedMessage;
}
Also used : IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) GenericMessage(org.springframework.messaging.support.GenericMessage) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) MessageSequenceComparator(org.springframework.integration.aggregator.MessageSequenceComparator) ArrayList(java.util.ArrayList) Aggregator(org.springframework.integration.annotation.Aggregator)

Aggregations

Message (org.springframework.messaging.Message)597 Test (org.junit.Test)423 GenericMessage (org.springframework.messaging.support.GenericMessage)272 QueueChannel (org.springframework.integration.channel.QueueChannel)189 MessageChannel (org.springframework.messaging.MessageChannel)128 ArrayList (java.util.ArrayList)113 BeanFactory (org.springframework.beans.factory.BeanFactory)85 CountDownLatch (java.util.concurrent.CountDownLatch)80 DirectChannel (org.springframework.integration.channel.DirectChannel)69 AtomicReference (java.util.concurrent.atomic.AtomicReference)68 Test (org.junit.jupiter.api.Test)65 MessageHandler (org.springframework.messaging.MessageHandler)58 List (java.util.List)56 PollableChannel (org.springframework.messaging.PollableChannel)56 ErrorMessage (org.springframework.messaging.support.ErrorMessage)52 Matchers.containsString (org.hamcrest.Matchers.containsString)50 MessagingException (org.springframework.messaging.MessagingException)50 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)43 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)41 Assert.assertEquals (org.junit.Assert.assertEquals)40