Announcement Announcement Module
Collapse
No announcement yet.
@Publisher does not work from Service Activator Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @Publisher does not work from Service Activator

    Hi,
    I have been working on creating a few POC's to check the viability of SI for a new project.
    While trying to publish from a method which also happens to be Service Activator end point, does not work. Rest of the configurations should be fine as I am able to get the bean from Spring context and call the method which has the @Publisher annotation, this works fine. But the issue is when this bean is configured as a Service Activator.

    SI version is 2.0.0.m2

    <channel id="eventInitiate"/>

    <service-activator input-channel="eventInitiate" ref="publishEvent" method="publishMessage"/>

    <beans:bean id="publishEvent" class="com.boa.localbus.event.PojoBasedEventPublis her"/>

    public class PojoBasedEventPublisher {
    @Publisher(value="#return", channel="localBus", headers="eventName='odin.local.event'")
    public String publishMessage(String message) {
    System.out.println("publishing event");

    return message + " published";
    }

    }

    Thanks for your response.

  • #2
    I think you're missing the <annotation-config/> element to enable the @Publisher annotation proxy generator.

    Just out of curiosity, why are you using @Publisher on a service-activator rather than simply relying on the service-activator's "output-channel"?

    Comment


    • #3
      Yes I did not put<annotation-config/> thanks for that.

      @ServiceActivator annotation does not provide for setting / updating message headers. Whereas @Publisher allows. This keeps my business method neat without any manipulation of header map. At the same time I did not want to add a transformer for this purpose.
      The design is to have several subsribers to a p/s channel, where each Subsciber is a chain wherein the first componet is a filter and the last component is a handler. The filter acts on a message header value. The handlers are Service Activators. I did not want to manpulate header's in my SA's method body.

      Let me know if I am missing something. I did not find @Subscriber annotation in 2.0.0.m2 release.

      Comment


      • #4
        @Publisher does not work

        Hi Mark,

        I am using 2.0.0.Build snapshot and following is the snippet in my context.xml:
        <si:annotation-config/>
        <si:channel id="validatedEmails">
        <si:queue />
        </si:channel>
        <si-jdbc:outbound-channel-adapter
        channel="validatedEmails" data-source="dataSource">
        <si-jdbc:query>update emails set isValid=ayload[valid],
        status=ayload[status], comments=ayload[comments],
        last_modified=CURRENT_TIMESTAMP where
        emailID=ayload[email]
        </si-jdbc:query>
        </si-jdbc:outbound-channel-adapter>

        <beans:bean class="org.springframework.integration.aop.Publish erAnnotationBeanPostProcessor"/>
        <si:annotation-config default-publisher-channel="validatedEmails"/>

        <beans:bean id="emailValidator" class="com.habuma.si.example.EmailValidator">
        </beans:bean>
        <si:service-activator id="transformer" input-channel="emailsOut"
        ref="emailValidator" method="validateEmailPre">
        <sioller task-executor="pool" receive-timeout="10" fixed-rate="1000">
        </sioller>
        </si:service-activator>
        <task:executor id="pool" pool-size="5-10" keep-alive="10" queue-capacity="100"/>

        And my method in EmailValidatorRunnable is:
        @Publisher(channel="validatedEmails")
        public Message<?> validateEmail(Message<?> msg) {...}

        The issue is, there are no messages published to the validatedEmails channel though all other things work perfectly... multi-threaded executor...multi-threaded handlers to actually process the request...

        Other relevant piece of code is:
        public class EmailValidator {
        private static final Logger log = Logger.getLogger(EmailValidator.class);
        public void validateEmailPre(Message<?> msg) {
        log.info(Thread.currentThread().getName()+"#"+this +":" + (String)msg.getPayload());
        Thread t = new Thread(new EmailValidatorRunnable(msg));
        t.start();
        }

        }

        Please help.

        Rajesh Gheware
        http://rajeshg.info

        Comment


        • #5
          I noticed that you have 2 different of 'annotation-config' elements as well as an explicit definition of the PublisherAnnotationBeanPostProcessor.

          Can you try again with just a single 'annotation-config' element?

          If it turns out that there is interference between those, then maybe there is an issue to be opened.

          Thanks,
          Mark

          Comment


          • #6
            Also, I noticed you are using 2.0.M2 which is 6 releases behind the current RC1 so I would suggest to upgrade as well

            Comment


            • #7
              Hi Oleg,

              I tried upgrading to RC1 however could not get following artefact:
              org.springframework.integration:spring-integration-adapter:jar:2.0.0.RC1

              Repos that I am using are:
              http://repository.springsource.com/m...undles/release
              http://s3.amazonaws.com/maven.spring...k.org/snapshot
              http://s3.amazonaws.com/maven.spring...k.org/releases

              Regards,
              Rajesh
              http://rajeshg.info

              Comment


              • #8
                In fact, I used following repoS:

                central (http://repo1.maven.org/maven2),
                springsource-external (http://repository.springsource.com/m...ndles/snapshot),
                java.net (http://download.java.net/maven/2),
                spring-milestone (http://s3.amazonaws.com/maven.spring....org/milestone),
                spring-snapshot (http://s3.amazonaws.com/maven.spring...k.org/snapshot),
                springsource-release (http://repository.springsource.com/m...undles/release),
                springsource-milestone2 (http://maven.springframework.org/milestone),
                spring-releases (http://s3.amazonaws.com/maven.spring...k.org/releases),
                jboss (http://repository.jboss.com/maven2/),
                springsource-milestone (http://repository.springsource.com/m...dles/milestone)

                Comment


                • #9
                  There is no longer a spring-integration-adapter module in RC1. You should be able to remove that from your POM.

                  Comment


                  • #10
                    Hi Mark,

                    Thanks. I did remove adapter module. I also removed the extra annotation tag: <si:annotation-config/> and retested my code. And I still could not see messages being published to the channel 'validatedEmails'.

                    What could be the issue?

                    FYI - I did upgrade spring integration to 2.0.0.RC1 and I have spring version 3.0.5.RELEASE

                    - Rajesh Gheware
                    http://rajeshg.info

                    Comment


                    • #11
                      Could you please post the revised configuration? It might be easier to troubleshoot than looking at the earlier version and considering what has been removed.

                      Thanks,
                      Mark

                      Comment


                      • #12
                        Hi Mark,

                        Here is the latest piece of xml config:
                        <si:channel id="validatedEmails">
                        <si:queue />
                        </si:channel>
                        <si-jdbc:outbound-channel-adapter
                        channel="validatedEmails" data-source="dataSource">
                        <si-jdbc:query>update emails set isValid=ayload[valid],
                        status=ayload[status], comments=ayload[comments],
                        last_modified=CURRENT_TIMESTAMP where
                        emailID=ayload[email]
                        </si-jdbc:query>
                        </si-jdbc:outbound-channel-adapter>

                        <beans:bean class="org.springframework.integration.aop.Publish erAnnotationBeanPostProcessor"/>
                        <si:annotation-config default-publisher-channel="validatedEmails"/>

                        <beans:bean id="emailValidator" class="info.rajeshg.validator.EmailValidator">
                        </beans:bean>
                        <si:service-activator id="validationService" input-channel="emailsOut"
                        ref="emailValidator" method="validateEmailPre">
                        <sioller task-executor="pool" receive-timeout="10" fixed-rate="1000">
                        </sioller>
                        </si:service-activator>
                        <task:executor id="pool" pool-size="5-10" keep-alive="10" queue-capacity="100"/>

                        Service activator (EmailValidator) code:
                        public void validateEmailPre(Message<?> msg) {
                        log.info(Thread.currentThread().getName()+"#"+this +":" + (String)msg.getPayload());
                        Thread t = new Thread(new EmailValidatorRunnable(msg));
                        t.start();
                        }

                        EmailValidatorRunnable code:
                        public class EmailValidatorRunnable implements Runnable{

                        private static final Logger log = Logger.getLogger(EmailValidatorRunnable.class);
                        private Message<?> msg;
                        public EmailValidatorRunnable(Message<?> msg){
                        this.msg = msg;
                        }
                        public Message<?> getMsg() {
                        return msg;
                        }
                        public void run() {
                        //...Main piece of logic being processed here. Commented here for reading convenience.
                        }
                        }

                        Let me know if any critical info that I have missed.

                        - Rajesh Gheware
                        http://rajeshg.info

                        Comment

                        Working...
                        X