A CXF client should be set up on the provider side to send messages to the consumer.
Spring-based client set up via Spring
<?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:jaxws="http://cxf.apache.org/jaxws" xmlns:context="http://www.springframework.org/schema/context" xmlns:soap="http://cxf.apache.org/bindings/soap" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/bindings/soap http://cxf.apache.org/schemas/configuration/soap.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.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"/> <!-- CXF client that sends notifications --> <jaxws:client xmlns:library="http://services.talend.org/demos/Library/1.0" id="publisherClient" serviceName="library:LibraryProvider" endpointName="library:LibraryTopicPort" address="jms:jndi-topic:dynamicTopics/newBooksTopic.topic?jndiInitialContextFactory=org.apache.activemq.jndi.ActiveMQInitialContextFactory& ;jndiConnectionFactoryName=ConnectionFactory&jndiURL=tcp://localhost:61616" serviceClass="org.talend.services.demos.library._1_0.Library"> <jaxws:features> <bean class="org.apache.cxf.ws.addressing.WSAddressingFeature"/> </jaxws:features> </jaxws:client> <bean id="libraryPublisher" class="org.talend.services.demos.server.LibraryPublisher"> <property name="library" ref="publisherClient"/> </bean> </beans>
Here is an example of how notification-sending method in LibraryPublisher class may be implemented:
Notification sender
public class LibraryPublisher { /** The Library proxy will be injected either by spring or by a direct call to the setter */ Library library; public Library getLibrary() { return library; } public void setLibrary(Library library) { this.library = library; } public void publishNewBooksNotifications() throws InterruptedException { List<BookType> newBooks = new LinkedList<BookType>(); BookType book = new BookType(); newBooks.add(book); PersonType author = new PersonType(); book.getAuthor().add(author); author.setFirstName("Jack"); author.setLastName("Icebear"); Calendar dateOfBirth = new GregorianCalendar(101, Calendar.JANUARY, 2); author.setDateOfBirth(dateOfBirth.getTime()); book.getTitle().add("More About Survival in the Arctic - Volume " + ndx); book.getPublisher().add("Frosty Edition"); book.setYearPublished("2011"); library.newBooks(new Date(), newBooks); } }
Here, the library object is injected via Spring.