Search in sources :

Example 6 with Processor

use of org.springframework.cloud.stream.messaging.Processor in project spring-cloud-stream by spring-cloud.

the class StreamListenerGenericFluxInputOutputArgsWithMessageTests method sendMessageAndValidate.

private static void sendMessageAndValidate(ConfigurableApplicationContext context) throws InterruptedException {
    Processor processor = context.getBean(Processor.class);
    String sentPayload = "hello " + UUID.randomUUID().toString();
    processor.input().send(MessageBuilder.withPayload(sentPayload).setHeader("contentType", "text/plain").build());
    MessageCollector messageCollector = context.getBean(MessageCollector.class);
    Message<String> result = (Message<String>) messageCollector.forChannel(processor.output()).poll(1000, TimeUnit.MILLISECONDS);
    assertThat(result).isNotNull();
    assertThat(result.getPayload()).isEqualTo(sentPayload.toUpperCase());
}
Also used : Processor(org.springframework.cloud.stream.messaging.Processor) Message(org.springframework.messaging.Message) MessageCollector(org.springframework.cloud.stream.test.binder.MessageCollector)

Example 7 with Processor

use of org.springframework.cloud.stream.messaging.Processor in project spring-cloud-stream by spring-cloud.

the class StreamListenerReactiveMethodWithReturnTypeTests method sendMessageAndValidate.

@SuppressWarnings("unchecked")
private static void sendMessageAndValidate(ConfigurableApplicationContext context) throws InterruptedException {
    Processor processor = context.getBean(Processor.class);
    String sentPayload = "hello " + UUID.randomUUID().toString();
    processor.input().send(MessageBuilder.withPayload(sentPayload).setHeader("contentType", "text/plain").build());
    MessageCollector messageCollector = context.getBean(MessageCollector.class);
    Message<String> result = (Message<String>) messageCollector.forChannel(processor.output()).poll(1000, TimeUnit.MILLISECONDS);
    assertThat(result).isNotNull();
    assertThat(result.getPayload()).isEqualTo(sentPayload.toUpperCase());
}
Also used : Processor(org.springframework.cloud.stream.messaging.Processor) Message(org.springframework.messaging.Message) MessageCollector(org.springframework.cloud.stream.test.binder.MessageCollector)

Example 8 with Processor

use of org.springframework.cloud.stream.messaging.Processor in project spring-cloud-stream by spring-cloud.

the class StreamListenerReactiveReturnWithFailureTests method sendFailingMessage.

private static void sendFailingMessage(ConfigurableApplicationContext context) throws InterruptedException {
    Processor processor = context.getBean(Processor.class);
    processor.input().send(MessageBuilder.withPayload("fail").setHeader("contentType", "text/plain").build());
}
Also used : Processor(org.springframework.cloud.stream.messaging.Processor)

Example 9 with Processor

use of org.springframework.cloud.stream.messaging.Processor in project spring-cloud-stream by spring-cloud.

the class StreamListenerReactiveReturnWithMessageTests method sendMessageAndValidate.

@SuppressWarnings("unchecked")
private static void sendMessageAndValidate(ConfigurableApplicationContext context) throws InterruptedException {
    Processor processor = context.getBean(Processor.class);
    String sentPayload = "hello " + UUID.randomUUID().toString();
    processor.input().send(MessageBuilder.withPayload(sentPayload).setHeader("contentType", "text/plain").build());
    MessageCollector messageCollector = context.getBean(MessageCollector.class);
    Message<String> result = (Message<String>) messageCollector.forChannel(processor.output()).poll(1000, TimeUnit.MILLISECONDS);
    assertThat(result).isNotNull();
    assertThat(result.getPayload()).isEqualTo(sentPayload.toUpperCase());
}
Also used : Processor(org.springframework.cloud.stream.messaging.Processor) Message(org.springframework.messaging.Message) MessageCollector(org.springframework.cloud.stream.test.binder.MessageCollector)

Example 10 with Processor

use of org.springframework.cloud.stream.messaging.Processor in project spring-cloud-stream by spring-cloud.

the class AggregateWithMainTest method testAggregateApplication.

@SuppressWarnings("unchecked")
@Test
public void testAggregateApplication() throws InterruptedException {
    // emulate a main method
    ConfigurableApplicationContext context = new AggregateApplicationBuilder(MainConfiguration.class).web(false).from(UppercaseProcessor.class).namespace("upper").to(SuffixProcessor.class).namespace("suffix").run("--spring.cloud.stream.bindings.input.contentType=text/plain", "--spring.cloud.stream.bindings.output.contentType=text/plain");
    AggregateApplication aggregateAccessor = context.getBean(AggregateApplication.class);
    MessageCollector messageCollector = context.getBean(MessageCollector.class);
    Processor uppercaseProcessor = aggregateAccessor.getBinding(Processor.class, "upper");
    Processor suffixProcessor = aggregateAccessor.getBinding(Processor.class, "suffix");
    uppercaseProcessor.input().send(MessageBuilder.withPayload("Hello").build());
    Message<String> receivedMessage = (Message<String>) messageCollector.forChannel(suffixProcessor.output()).poll(1, TimeUnit.SECONDS);
    assertThat(receivedMessage).isNotNull();
    assertThat(receivedMessage.getPayload()).isEqualTo("HELLO WORLD!");
    context.close();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) Processor(org.springframework.cloud.stream.messaging.Processor) Message(org.springframework.messaging.Message) MessageCollector(org.springframework.cloud.stream.test.binder.MessageCollector) AggregateApplicationBuilder(org.springframework.cloud.stream.aggregate.AggregateApplicationBuilder) AggregateApplication(org.springframework.cloud.stream.aggregate.AggregateApplication) Test(org.junit.Test)

Aggregations

Processor (org.springframework.cloud.stream.messaging.Processor)26 Message (org.springframework.messaging.Message)20 MessageCollector (org.springframework.cloud.stream.test.binder.MessageCollector)19 Test (org.junit.Test)14 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)12 CountDownLatch (java.util.concurrent.CountDownLatch)2 MessageHandler (org.springframework.messaging.MessageHandler)2 MessagingException (org.springframework.messaging.MessagingException)2 SubscribableChannel (org.springframework.messaging.SubscribableChannel)2 Field (java.lang.reflect.Field)1 Map (java.util.Map)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 AggregateApplication (org.springframework.cloud.stream.aggregate.AggregateApplication)1 AggregateApplicationBuilder (org.springframework.cloud.stream.aggregate.AggregateApplicationBuilder)1 BindableProxyFactory (org.springframework.cloud.stream.binding.BindableProxyFactory)1 Source (org.springframework.cloud.stream.messaging.Source)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1