Spring Integration No poller has been defined for endpoint

22.7k views Asked by At

Hi i am having a hard time solving my xml configuration,

here's my spring integration config xml:

<context:annotation-config />
    <context:component-scan base-package="hk.com.test.spring.integration" />

    <int:channel id="orders" />
    <int:channel id="drinks" />

    <int:channel id="hotDrink">
        <int:queue capacity="5" />
    </int:channel>

    <int:channel id="coldDrink">
        <int:queue capacity="10" />
    </int:channel>

    <bean id="drinkRouter" class="hk.com.test.spring.integration.DrinkRouter" />
    <bean id="orderSplitter" class="hk.com.test.spring.integration.OrderSplitter" />
    <bean id="barista" class="hk.com.test.spring.integration.Barista" />

    <int:gateway id="cafe" service-interface="hk.com.test.spring.integration.Cafe" />

    <int:splitter input-channel="orders" ref="orderSplitter"
        method="split" output-channel="drinks" />

    <int:router input-channel="drinks" ref="drinkRouter" method="resolveItemChannel" />


    <int:service-activator input-channel="coldDrink"
        ref="barista" method="prepareColdDrink" />

    <int:service-activator input-channel="hotDrink"
        ref="barista" method="preparehotDrink" />

here is my main class::

public class Main {

    public static void main(String args[]) {
        System.out.println("Hello");

        // load the Spring context
        ApplicationContext context = new ClassPathXmlApplicationContext(
                "spring-config2.xml");
        Cafe cafe = (Cafe) context.getBean("cafe");
        for (int i = 1; i <= 100; i++) {
            Order order = new Order(i);
            order.addItem(DrinkType.LATTE, false);
            order.addItem(DrinkType.MOCHA, true);
            cafe.placeOrder(order);
        }

    }
}

Im just simply running it using a main class, i am receiving this exception::

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.integration.config.ConsumerEndpointFactoryBean#2': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: No poller has been defined for endpoint 'org.springframework.integration.config.ConsumerEndpointFactoryBean#2', and no default poller is available within the context.
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1486)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:524)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:589)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    at hk.com.novare.spring.integration.main.Main.main(Main.java:16)
Caused by: java.lang.IllegalArgumentException: No poller has been defined for endpoint 'org.springframework.integration.config.ConsumerEndpointFactoryBean#2', and no default poller is available within the context.
    at org.springframework.util.Assert.notNull(Assert.java:112)
    at org.springframework.integration.config.ConsumerEndpointFactoryBean.initializeEndpoint(ConsumerEndpointFactoryBean.java:220)
    at org.springframework.integration.config.ConsumerEndpointFactoryBean.afterPropertiesSet(ConsumerEndpointFactoryBean.java:175)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1545)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1483)
    ... 12 more

i am just new on learning spring integration, i dont know how to fix my configuration also..

3

There are 3 answers

8
Artem Bilan On BEST ANSWER

You have several queue channels. To receive Messages from them you should configure <poller>: global one, or for each component, which are subscribed to those queues: Poller Configuration, Poller sample

UPDATE:

Global poller:

<int:poller default="true" fixed-delay="50"/>

Queue channels are splitter, router and service activator right?

No, channels are channels and they don't do anything with messages, from big height, of course. Messages are gotten from channels by Endpoints. In case of queue it should be PollingConsumer and the exception says exactly it. So, you have to: or add global poller, but in this case all endpoints will poll messages via the same rules, or configure <poller> for each endpoint. In your case they are components who have those queues as input-channel.

0
Tomasz Janisiewicz On

Annotation alternative for defining global default pooler:

@Bean(name = PollerMetadata.DEFAULT_POLLER)
public PollerMetadata defaultPoller() {

    PollerMetadata pollerMetadata = new PollerMetadata();
    pollerMetadata.setTrigger(new PeriodicTrigger(10));
    return pollerMetadata;
}
0
amitVerma On

The problem is resolved by below steps-

  1. Right click on your project in eclipse.
  2. Then Maven > Update Project.

Note: Make sure you have xsd and jar in place as well.

<int-stream:stdin-channel-adapter id="producer" channel="messageChannel" >
    <int:poller id="defaultPoller" default="true" fixed-rate="200" />
</int-stream:stdin-channel-adapter>