Announcement Announcement Module
No announcement yet.
Service activator not called when message is put in init method of bean Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Service activator not called when message is put in init method of bean

    I have a very simple use case where when a Si message is put into channel in init method - the service activator is not getting called.

    Is it a known issue ?

    I initially assumed that it could be because, the service activator is not getting instantiated. But i cannot also give a 'depends on' for the service activator bean.

    The same code with configuration works fine if i put the code which publishes into the cahnnel in @scheduled

        // @Scheduled(fixedDelay = 5000)
        public void init() {
            System.out.println("init method called");
            channel.send(MessageBuilder.withPayload(new Object()).build());
            System.out.println("channel send compalte");


    <int:publish-subscribe-channel id="testChannel"/>
    <bean id="dummyHandler" class="com.test.sitest.DummyHandler" depends-on="testChannel"/>
    <int:service-activator input-channel="testChannel" ref="dummyHandler" method="handle"/>
    <bean id="testBean" class="com.test.sitest.DummyBean" init-method="init" depends-on="dummyHandler">
      <property name="channel" ref="testChannel"/>
    Last edited by sudheerk84; Mar 3rd, 2011, 04:26 AM.

  • #2

    The issue is with the beans lifecycle. EventDrivenConsumer (which wraps ServiceActivatingHandler) is a Lifecycle bean which has to be started. It is started by default however start() method is invoked in the last phase of bean lifecycle which follows post-processing (initialization) phase.
    Remember the class - 1)load bean definitions -> 2)post-process bean definitions ->3) create bean instances -> 4)post-process bean instances (that is your init phase) -> lifecycle (start() method)

    Could you please explain your use case? Why do you need to send Message during the Init phase? Hopefully we can come up with a different solution


    • #3
      Hi Oleg

      Its really nice to hear from you.

      I remember the bean lifecyle phases. Understanding that has helped me solve lots of issues , when dealing with transactions, proxies etc.

      My usecase is as follows.

      As part of a recovery process for the platform we are building , when the server starts up it has to load some data from the database and publish it into one of the channels which does asynchronous processing.

      Just thought of using the init method has it.

      Can i trigger the start of the activator inside my init method ? (since service activator doesnt have a id not sure how i can get a reference to it)


      • #4
        Yes, look at Application Event support. You can trigger based on 'context refresh' event. Sorr


        • #5
          Thanks Oleg it worked when listening to the contextRefresh event.

          Just on curiosity , is there any specific reason the activator or channel adaptor doesnt have a id attribute ?