Setting up the Service Consumer
The CXF endpoint that listens for notifications should be defined on the consumer side. Here is how it looks like in Spring configuration file:
Setting up consumer side
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:cxf="http://cxf.apache.org/core"
xmlns:p="http://www.springframework.org/schema/p" xmlns:library="http://services.talend.org/demos/Library/1.0"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<!-- CXF 3 JMS configuration style -->
<import resource="classpath:META-INF/tesb/tesb-cxf-transport-jms.xml" />
<jaxws:endpoint xmlns:library="http://services.talend.org/demos/Library/1.0"
id="LibraryNotificationReceiver"
address="jms:jndi-topic:dynamicTopics/newBooksTopic.topic?jndiInitialContextFactory=org.apache.activemq.jndi.ActiveMQInitialContextFactory&
;jndiConnectionFactoryName=ConnectionFactory&jndiURL=tcp://localhost:61616"
serviceName="library:LibraryProvider" endpointName="library:LibraryTopicPort"
implementor="org.talend.services.demos.client.LibraryNotificationReceiverImpl">
<jaxws:features>
<bean class="org.apache.cxf.ws.addressing.WSAddressingFeature" />
</jaxws:features>
</jaxws:endpoint>
</beans>
The following is an example of the implementation of the notification-receiving service:
Consumer side notification receiver
@@WebServiceProvider
public class LibraryNotificationReceiverImpl implements Library {
@Resource
private WebServiceContext wsContext;
...
@Override
public void newBooks(Date listDate, List<BookType> book) {
System.out.println("****************************************************");
System.out.println("*** newBooks notification is received **************");
System.out.println("****************************************************");
System.out.println("New books notification:");
// Business logic here
}
}