Example usage for org.springframework.integration.endpoint EventDrivenConsumer EventDrivenConsumer

List of usage examples for org.springframework.integration.endpoint EventDrivenConsumer EventDrivenConsumer

Introduction

In this page you can find the example usage for org.springframework.integration.endpoint EventDrivenConsumer EventDrivenConsumer.

Prototype

public EventDrivenConsumer(SubscribableChannel inputChannel, MessageHandler handler) 

Source Link

Usage

From source file:com.apress.prospringintegration.endpoints.eventdrivenconsumer.Main.java

public static void main(String[] args) {
    ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(
            "event-driven-consumer.xml");
    applicationContext.start();/*from   ww  w  .jav  a 2s.  com*/

    ProblemReporter problemReporter = applicationContext.getBean(ProblemReporter.class);
    TicketGenerator ticketGenerator = applicationContext.getBean(TicketGenerator.class);
    TicketMessageHandler ticketMessageHandler = applicationContext.getBean(TicketMessageHandler.class);

    DirectChannel channel = applicationContext.getBean("ticketChannel", DirectChannel.class);

    EventDrivenConsumer eventDrivenConsumer = new EventDrivenConsumer(channel, ticketMessageHandler);
    eventDrivenConsumer.start();

    List<Ticket> tickets = ticketGenerator.createTickets();

    int count = 0;
    while (count++ < 5) {
        for (Ticket ticket : tickets) {
            problemReporter.openTicket(ticket);
        }
    }
}

From source file:io.spring.batch.configuration.IntegrationConfiguration.java

@Bean
protected EventDrivenConsumer statusConsumer(SubscribableChannel statusTweets) {
    return new EventDrivenConsumer(statusTweets, statusHandler());
}

From source file:io.jmnarloch.spring.cloud.stream.binder.hermes.HermesClientBinder.java

private EventDrivenConsumer createConsumer(String name, SubscribableChannel channel, MessageHandler handler) {
    EventDrivenConsumer consumer = new EventDrivenConsumer(channel, handler);
    consumer.setBeanFactory(getBeanFactory());
    consumer.setBeanName(String.format(BEAN_NAME_TEMPLATE, name));
    consumer.afterPropertiesSet();/*from w  ww . j  av a2 s  . c o  m*/
    return consumer;
}

From source file:com.nayidisha.slowglow.config.SpringMessagingConfig.java

/**
 * Default endpoint/*w  w  w.ja v a  2 s .  c om*/
 * 
 * @return
 */
@Bean(destroyMethod = "stop")
public EventDrivenConsumer eventDrivenConsumer() {
    EventDrivenConsumer consumer = new EventDrivenConsumer(webSocketInputChannel(), loggingHandler());
    consumer.setAutoStartup(true);

    return consumer;
}

From source file:org.springframework.flex.messaging.integration.IntegrationAdapter.java

/**
 * {@inheritDoc}// w w  w. j  a v a  2 s.c o m
 */
public void afterPropertiesSet() {
    Assert.notNull(this.messageChannel, "MessageChannel must not be null");
    if (this.messageChannel instanceof PollableChannel) {
        this.consumerEndpoint = new PollingConsumer((PollableChannel) this.messageChannel, this);
    } else if (this.messageChannel instanceof SubscribableChannel) {
        this.consumerEndpoint = new EventDrivenConsumer((SubscribableChannel) this.messageChannel, this);
    }
}

From source file:org.springframework.integration.config.annotation.AbstractMethodAnnotationPostProcessor.java

protected AbstractEndpoint doCreateEndpoint(MessageHandler handler, MessageChannel inputChannel,
        List<Annotation> annotations) {
    AbstractEndpoint endpoint;/*from  w  ww  .  j  av a2 s. co m*/
    if (inputChannel instanceof PollableChannel) {
        PollingConsumer pollingConsumer = new PollingConsumer((PollableChannel) inputChannel, handler);
        configurePollingEndpoint(pollingConsumer, annotations);
        endpoint = pollingConsumer;
    } else {
        Poller[] pollers = MessagingAnnotationUtils.resolveAttribute(annotations, "poller", Poller[].class);
        Assert.state(ObjectUtils.isEmpty(pollers), "A '@Poller' should not be specified for Annotation-based "
                + "endpoint, since '" + inputChannel + "' is a SubscribableChannel (not pollable).");
        if (inputChannel instanceof Publisher) {
            endpoint = new ReactiveConsumer(inputChannel, handler);
        } else {
            endpoint = new EventDrivenConsumer((SubscribableChannel) inputChannel, handler);
        }
    }
    return endpoint;
}

From source file:org.springframework.integration.config.ConsumerEndpointFactoryBean.java

private void initializeEndpoint() throws Exception {
    synchronized (this.initializationMonitor) {
        if (this.initialized) {
            return;
        }//from   w w  w  . j  a  va  2  s . c  o  m
        MessageChannel channel = null;
        if (StringUtils.hasText(this.inputChannelName)) {
            Assert.isTrue(this.beanFactory.containsBean(this.inputChannelName), "no such input channel '"
                    + this.inputChannelName + "' for endpoint '" + this.beanName + "'");
            channel = this.beanFactory.getBean(this.inputChannelName, MessageChannel.class);
        }
        if (this.inputChannel != null) {
            channel = this.inputChannel;
        }
        Assert.state(channel != null, "one of inputChannelName or inputChannel is required");
        if (channel instanceof SubscribableChannel) {
            Assert.isNull(this.pollerMetadata, "A poller should not be specified for endpoint '" + this.beanName
                    + "', since '" + channel + "' is a SubscribableChannel (not pollable).");
            this.endpoint = new EventDrivenConsumer((SubscribableChannel) channel, this.handler);
        } else if (channel instanceof PollableChannel) {
            PollingConsumer pollingConsumer = new PollingConsumer((PollableChannel) channel, this.handler);
            if (this.pollerMetadata == null) {
                this.pollerMetadata = PollerMetadata.getDefaultPollerMetadata(this.beanFactory);
                Assert.notNull(this.pollerMetadata, "No poller has been defined for endpoint '" + this.beanName
                        + "', and no default poller is available within the context.");
            }
            pollingConsumer.setTaskExecutor(this.pollerMetadata.getTaskExecutor());
            pollingConsumer.setTrigger(this.pollerMetadata.getTrigger());
            pollingConsumer.setAdviceChain(this.pollerMetadata.getAdviceChain());
            pollingConsumer.setMaxMessagesPerPoll(this.pollerMetadata.getMaxMessagesPerPoll());

            pollingConsumer.setErrorHandler(this.pollerMetadata.getErrorHandler());

            pollingConsumer.setReceiveTimeout(this.pollerMetadata.getReceiveTimeout());
            pollingConsumer.setTransactionSynchronizationFactory(
                    this.pollerMetadata.getTransactionSynchronizationFactory());
            pollingConsumer.setBeanClassLoader(beanClassLoader);
            pollingConsumer.setBeanFactory(beanFactory);
            this.endpoint = pollingConsumer;
        } else {
            throw new IllegalArgumentException("unsupported channel type: [" + channel.getClass() + "]");
        }
        this.endpoint.setBeanName(this.beanName);
        this.endpoint.setBeanFactory(this.beanFactory);
        this.endpoint.setAutoStartup(this.autoStartup);
        this.endpoint.afterPropertiesSet();
        this.initialized = true;
    }
}

From source file:org.springframework.integration.handler.AsyncHandlerTests.java

@Test
public void testGateway() throws Exception {
    this.whichTest = 0;
    GatewayProxyFactoryBean gpfb = new GatewayProxyFactoryBean(Foo.class);
    gpfb.setBeanFactory(mock(BeanFactory.class));
    DirectChannel input = new DirectChannel();
    gpfb.setDefaultRequestChannel(input);
    gpfb.setDefaultReplyTimeout(10000L);
    gpfb.afterPropertiesSet();//  w w w. ja  va 2s  .  co  m
    Foo foo = (Foo) gpfb.getObject();
    this.handler.setOutputChannel(null);
    EventDrivenConsumer consumer = new EventDrivenConsumer(input, this.handler);
    consumer.afterPropertiesSet();
    consumer.start();
    this.latch.countDown();
    String result = foo.exchange("foo");
    assertEquals("reply", result);
}

From source file:org.springframework.integration.handler.AsyncHandlerTests.java

@Test
public void testGatewayWithException() throws Exception {
    this.whichTest = 0;
    GatewayProxyFactoryBean gpfb = new GatewayProxyFactoryBean(Foo.class);
    gpfb.setBeanFactory(mock(BeanFactory.class));
    DirectChannel input = new DirectChannel();
    gpfb.setDefaultRequestChannel(input);
    gpfb.setDefaultReplyTimeout(10000L);
    gpfb.afterPropertiesSet();/*  www. j  av a  2s.co m*/
    Foo foo = (Foo) gpfb.getObject();
    this.handler.setOutputChannel(null);
    EventDrivenConsumer consumer = new EventDrivenConsumer(input, this.handler);
    consumer.afterPropertiesSet();
    consumer.start();
    this.latch.countDown();
    try {
        foo.exchange("foo");
    } catch (MessagingException e) {
        assertThat(e.getClass().getSimpleName(), equalTo("RuntimeException"));
        assertThat(e.getMessage(), equalTo("foo"));
    }
}

From source file:org.springframework.integration.x.gemfire.GemFireMessageBus.java

private void doRegisterProducer(final String name, MessageChannel moduleOutputChannel, MessageHandler handler) {
    Assert.isInstanceOf(SubscribableChannel.class, moduleOutputChannel);
    EventDrivenConsumer consumer = new EventDrivenConsumer((SubscribableChannel) moduleOutputChannel, handler);
    consumer.setBeanName("outbound." + name);
    consumer.afterPropertiesSet();//  w w  w. ja v  a  2  s  .c  o  m
    addBinding(Binding.forProducer(moduleOutputChannel, consumer));
    consumer.start();
}