Search in sources :

Example 81 with MessagingException

use of org.springframework.messaging.MessagingException in project spring-cloud-consul by spring-cloud.

the class TestConsumer method run.

@Override
public void run(ApplicationArguments args) throws Exception {
    logger.info("Consumer running with binder {}", binder);
    SubscribableChannel consumerChannel = new ExecutorSubscribableChannel();
    consumerChannel.subscribe(new MessageHandler() {

        @Override
        public void handleMessage(Message<?> message) throws MessagingException {
            messagePayload = (String) message.getPayload();
            logger.info("Received message: {}", messagePayload);
        }
    });
    String group = null;
    if (args.containsOption("group")) {
        group = args.getOptionValues("group").get(0);
    }
    binder.bindConsumer(ConsulBinderTests.BINDING_NAME, group, consumerChannel, new ConsumerProperties());
    isBound = true;
}
Also used : ExecutorSubscribableChannel(org.springframework.messaging.support.ExecutorSubscribableChannel) MessageHandler(org.springframework.messaging.MessageHandler) MessagingException(org.springframework.messaging.MessagingException) SubscribableChannel(org.springframework.messaging.SubscribableChannel) ExecutorSubscribableChannel(org.springframework.messaging.support.ExecutorSubscribableChannel) ConsumerProperties(org.springframework.cloud.stream.binder.ConsumerProperties)

Example 82 with MessagingException

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

the class GmailInboundImapIdleAdapterTestApp method main.

public static void main(String[] args) throws Exception {
    @SuppressWarnings("resource") ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("/META-INF/spring/integration/gmail-imap-idle-config.xml");
    DirectChannel inputChannel = ac.getBean("receiveChannel", DirectChannel.class);
    inputChannel.subscribe(new MessageHandler() {

        @Override
        public void handleMessage(Message<?> message) throws MessagingException {
            logger.info("Message: " + message);
        }
    });
}
Also used : MessageHandler(org.springframework.messaging.MessageHandler) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DirectChannel(org.springframework.integration.channel.DirectChannel) MessagingException(org.springframework.messaging.MessagingException)

Example 83 with MessagingException

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

the class GmailInboundPop3AdapterTestApp method main.

public static void main(String[] args) throws Exception {
    @SuppressWarnings("resource") ApplicationContext ac = new ClassPathXmlApplicationContext("/META-INF/spring/integration/gmail-pop3-config.xml");
    DirectChannel inputChannel = ac.getBean("receiveChannel", DirectChannel.class);
    inputChannel.subscribe(new MessageHandler() {

        @Override
        public void handleMessage(Message<?> message) throws MessagingException {
            logger.info("Message: " + message);
        }
    });
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) MessageHandler(org.springframework.messaging.MessageHandler) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DirectChannel(org.springframework.integration.channel.DirectChannel) MessagingException(org.springframework.messaging.MessagingException)

Example 84 with MessagingException

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

the class StreamListenerHandlerMethodTests method testMethodWithMultipleInputParameters.

@Test
public void testMethodWithMultipleInputParameters() throws Exception {
    ConfigurableApplicationContext context = SpringApplication.run(TestMethodWithMultipleInputParameters.class, "--server.port=0", "--spring.jmx.enabled=false");
    Processor processor = context.getBean(Processor.class);
    StreamListenerTestUtils.FooInboundChannel1 inboundChannel2 = context.getBean(StreamListenerTestUtils.FooInboundChannel1.class);
    final CountDownLatch latch = new CountDownLatch(2);
    ((SubscribableChannel) processor.output()).subscribe(new MessageHandler() {

        @Override
        public void handleMessage(Message<?> message) throws MessagingException {
            Assert.isTrue(message.getPayload().equals("footesting") || message.getPayload().equals("BARTESTING"), "Assert failed");
            latch.countDown();
        }
    });
    processor.input().send(MessageBuilder.withPayload("{\"foo\":\"fooTESTing\"}").setHeader("contentType", "application/json").build());
    inboundChannel2.input().send(MessageBuilder.withPayload("{\"bar\":\"bartestING\"}").setHeader("contentType", "application/json").build());
    assertThat(latch.await(1, TimeUnit.SECONDS));
    context.close();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) Processor(org.springframework.cloud.stream.messaging.Processor) MessageHandler(org.springframework.messaging.MessageHandler) MessagingException(org.springframework.messaging.MessagingException) CountDownLatch(java.util.concurrent.CountDownLatch) SubscribableChannel(org.springframework.messaging.SubscribableChannel) Test(org.junit.Test)

Example 85 with MessagingException

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

the class TestSupportBinder method bindProducer.

/**
 * Registers a single subscriber to the channel, that enqueues messages for later
 * retrieval and assertion in tests.
 */
@Override
public Binding<MessageChannel> bindProducer(String name, MessageChannel outboundBindTarget, ProducerProperties properties) {
    final BlockingQueue<Message<?>> queue = messageCollector.register(outboundBindTarget, properties.isUseNativeEncoding());
    ((SubscribableChannel) outboundBindTarget).subscribe(new MessageHandler() {

        @Override
        public void handleMessage(Message<?> message) throws MessagingException {
            queue.add(message);
        }
    });
    this.messageChannels.put(name, outboundBindTarget);
    return new TestBinding(outboundBindTarget, messageCollector);
}
Also used : Message(org.springframework.messaging.Message) MessageHandler(org.springframework.messaging.MessageHandler) MessagingException(org.springframework.messaging.MessagingException) SubscribableChannel(org.springframework.messaging.SubscribableChannel)

Aggregations

MessagingException (org.springframework.messaging.MessagingException)143 Test (org.junit.Test)60 IOException (java.io.IOException)25 Message (org.springframework.messaging.Message)23 QueueChannel (org.springframework.integration.channel.QueueChannel)22 ErrorMessage (org.springframework.messaging.support.ErrorMessage)21 CountDownLatch (java.util.concurrent.CountDownLatch)17 BeanFactory (org.springframework.beans.factory.BeanFactory)15 MessageChannel (org.springframework.messaging.MessageChannel)15 MessageHandlingException (org.springframework.messaging.MessageHandlingException)15 GenericMessage (org.springframework.messaging.support.GenericMessage)15 MessageHandler (org.springframework.messaging.MessageHandler)14 File (java.io.File)12 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)12 Matchers.containsString (org.hamcrest.Matchers.containsString)12 DirectChannel (org.springframework.integration.channel.DirectChannel)12 ArrayList (java.util.ArrayList)11 PollableChannel (org.springframework.messaging.PollableChannel)11 Lock (java.util.concurrent.locks.Lock)8 MessageDeliveryException (org.springframework.messaging.MessageDeliveryException)8