PDA

View Full Version : @Publisher does not work from Service Activator



Selva
Feb 17th, 2010, 11:09 PM
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.PojoBasedEventPublisher"/>

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.

Mark Fisher
Feb 18th, 2010, 07:33 AM
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"?

Selva
Feb 19th, 2010, 08:21 PM
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.

rajeshgheware
Nov 2nd, 2010, 10:04 AM
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=:payload[valid],
status=:payload[status], comments=:payload[comments],
last_modified=CURRENT_TIMESTAMP where
emailID=:payload[email]
</si-jdbc:query>
</si-jdbc:outbound-channel-adapter>

<beans:bean class="org.springframework.integration.aop.PublisherAnnot ationBeanPostProcessor"/>
<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">
<si:poller task-executor="pool" receive-timeout="10" fixed-rate="1000">
</si:poller>
</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

Mark Fisher
Nov 2nd, 2010, 10:21 AM
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

oleg.zhurakousky
Nov 2nd, 2010, 11:34 AM
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

rajeshgheware
Nov 2nd, 2010, 01:50 PM
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/maven/bundles/release
http://s3.amazonaws.com/maven.springframework.org/snapshot
http://s3.amazonaws.com/maven.springframework.org/releases

Regards,
Rajesh
http://rajeshg.info

rajeshgheware
Nov 2nd, 2010, 02:03 PM
In fact, I used following repoS:

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

Mark Fisher
Nov 2nd, 2010, 02:11 PM
There is no longer a spring-integration-adapter module in RC1. You should be able to remove that from your POM.

rajeshgheware
Nov 2nd, 2010, 02:31 PM
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

Mark Fisher
Nov 2nd, 2010, 02:36 PM
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

rajeshgheware
Nov 2nd, 2010, 02:56 PM
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=:payload[valid],
status=:payload[status], comments=:payload[comments],
last_modified=CURRENT_TIMESTAMP where
emailID=:payload[email]
</si-jdbc:query>
</si-jdbc:outbound-channel-adapter>

<beans:bean class="org.springframework.integration.aop.PublisherAnnot ationBeanPostProcessor"/>
<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">
<si:poller task-executor="pool" receive-timeout="10" fixed-rate="1000">
</si:poller>
</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