14

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..

Ernest Hilvano
  • 503
  • 3
  • 8
  • 16

3 Answers3

25

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;
}
Tomasz Janisiewicz
  • 639
  • 1
  • 11
  • 9
12

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.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • Hi Artem, Thanks for response, can you guide mo on how can i add or configure a global poller... Another question, correct me if im wrong, Queue channels are splitter, router and service activator right? if so is it needed for every channel to have its own poll? – Ernest Hilvano Dec 27 '13 at 13:12
  • I see,, so all Queue Channels are those who have an input-channel. thanks a lot sir Artem. i have one remaining problem, it gives me an error -> cvc-complex-type.3.2.2: Attribute 'fixed-delay' is not allowed to appear in element 'int:poller'. – Ernest Hilvano Dec 27 '13 at 15:29
  • Lools like you are using very old version on Spring Integration: http://projects.spring.io/spring-integration ... – Artem Bilan Dec 27 '13 at 15:36
  • Thanks Sir Artem, Im currently using 2.2.3.RELEASE, haha il changed my version then update you once i made it working – Ernest Hilvano Dec 27 '13 at 15:46
  • Suppose your IDE complaints about that attribute, or you have several version within your CLASSPATH at runtime. – Artem Bilan Dec 27 '13 at 15:49
  • Hi Sir Artem, its now working i just changed the version of my spring integration core to 3.0.0.RELEASE .. my code is now running but my ide (eclipse ) is still complaining on fixed-delay – Ernest Hilvano Dec 27 '13 at 16:12
  • Here you are: http://stackoverflow.com/questions/20656424/eclipse-gradle-projects-spring-xml-validation – Artem Bilan Dec 27 '13 at 16:14
  • Thanks its not complaining anymore :), BIG THANKS to you sir Artem.. :) – Ernest Hilvano Dec 27 '13 at 16:20
1

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>
ItamarG3
  • 4,092
  • 6
  • 31
  • 44
amitVerma
  • 41
  • 1