Example usage for org.springframework.integration.endpoint PollingConsumer start

List of usage examples for org.springframework.integration.endpoint PollingConsumer start

Introduction

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

Prototype

@Override
    public final void start() 

Source Link

Usage

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

public static void main(String[] args) {
    ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(
            "polling-consumer.xml");
    applicationContext.start();//from  w ww  .j  a  v a  2s  .c o m

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

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

    // Define the polling consumer
    PollingConsumer ticketConsumer = new PollingConsumer(channel, ticketMessageHandler);
    ticketConsumer.setReceiveTimeout(RECEIVE_TIMEOUT);
    ticketConsumer.setBeanFactory(applicationContext);

    // Setup the poller using periodic trigger
    PeriodicTrigger periodicTrigger = new PeriodicTrigger(1000);
    periodicTrigger.setInitialDelay(5000);
    periodicTrigger.setFixedRate(false);

    PollerMetadata pollerMetadata = new PollerMetadata();
    pollerMetadata.setTrigger(periodicTrigger);
    pollerMetadata.setMaxMessagesPerPoll(3);

    ticketConsumer.setPollerMetadata(pollerMetadata);

    // Starts the polling consumer in the other thread
    ticketConsumer.start();

    // Generates messages and sends to the channel
    List<Ticket> tickets = ticketGenerator.createTickets();
    while (true) {
        for (Ticket ticket : tickets) {
            problemReporter.openTicket(ticket);
        }
    }
}

From source file:nhs.spring.integration.App.java

public static void main(String... args) {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "spring-integration-context.xml");
    GameMessageHandler gameHandler = new GameMessageHandler();
    GameGenerator gameGenerator = context.getBean(GameGenerator.class);

    context.start();//w  w w  .j a  v a  2 s  .  c  o m

    //MessageChannel input = context.getBean("input-channel", MessageChannel.class);
    //PollableChannel output = context.getBean("output-channel", PollableChannel.class);
    QueueChannel qChannel = context.getBean("game-channel", QueueChannel.class);

    PollingConsumer gameConsumer = new PollingConsumer(qChannel, gameHandler);
    gameConsumer.setReceiveTimeout(RECEIVE_TIMEOUT);
    gameConsumer.setBeanFactory(context);

    // Set up the poller using periodic trigger
    PeriodicTrigger periodicTrigger = new PeriodicTrigger(1000);
    periodicTrigger.setInitialDelay(5000);
    periodicTrigger.setFixedRate(false);

    PollerMetadata pollerMetadata = new PollerMetadata();
    pollerMetadata.setTrigger(periodicTrigger);
    pollerMetadata.setMaxMessagesPerPoll(3);

    gameConsumer.setPollerMetadata(pollerMetadata);

    // Starts the polling consumer in the other thread
    gameConsumer.start();

    Date today = new Date();

    // Generates messages and sends to the channel
    Game game = gameGenerator.generateGame("League of legend", "Riot Games", today, "Tom", "Michael", "AOS");

    qChannel.send(MessageBuilder.withPayload(game).build());

    /*
    PublishSubscribeChannel pubsubChannel = null;
            
    pubsubChannel.subscribe(gameHandler);
            
    input.send(MessageBuilder.withPayload("Spring Integration / Hello NHS").build());
    Message<?> reply = output.receive();
            
    System.out.println("Received :" + reply);
    */
}