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"));
}
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"));
}
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"));
}
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"));
}
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;
}
Aggregations