JMS Remoting and web services using Spring

4.3.9.RELEASE Spring Framework 677 Accessing the web service is now very easy as we have a bean factory for it that will expose it as AccountService interface. We can wire this up in Spring: bean id = client class = example.AccountClientImpl ... property name = service ref = accountWebService bean From the client code we can access the web service just as if it was a normal class: public class AccountClientImpl { private AccountService service; public void setServiceAccountService service { this .service = service; } public void foo { service.insertAccount...; } } Note The above is slightly simplified in that JAX-WS requires endpoint interfaces and implementation classes to be annotated with WebService , SOAPBinding etc annotations. This means that you cannot easily use plain Java interfaces and implementation classes as JAX-WS endpoint artifacts; you need to annotate them accordingly first. Check the JAX-WS documentation for details on those requirements.

28.6 JMS

It is also possible to expose services transparently using JMS as the underlying communication protocol. The JMS remoting support in the Spring Framework is pretty basic - it sends and receives on the same thread and in the same non-transactional Session , and as such throughput will be very implementation dependent. Note that these single-threaded and non-transactional constraints apply only to Spring’s JMS remoting support. See Chapter 30, JMS Java Message Service for information on Spring’s rich support for JMS-based messaging. The following interface is used on both the server and the client side. package com.foo; public interface CheckingAccountService { public void cancelAccountLong accountId; } The following simple implementation of the above interface is used on the server-side. package com.foo; public class SimpleCheckingAccountService implements CheckingAccountService { public void cancelAccountLong accountId { System.out.println Cancelling account [ + accountId + ] ; } } 4.3.9.RELEASE Spring Framework 678 This configuration file contains the JMS-infrastructure beans that are shared on both the client and server. ?xml version=1.0 encoding=UTF-8? beans xmlns = http:www.springframework.orgschemabeans xmlns:xsi = http:www.w3.org2001XMLSchema-instance xsi:schemaLocation = http:www.springframework.orgschemabeans http:www.springframework.orgschemabeansspring-beans.xsd bean id = connectionFactory class = org.apache.activemq.ActiveMQConnectionFactory property name = brokerURL value = tcp:ep-t43:61616 bean bean id = queue class = org.apache.activemq.command.ActiveMQQueue constructor-arg value = mmm bean beans Server-side configuration On the server, you just need to expose the service object using the JmsInvokerServiceExporter . ?xml version=1.0 encoding=UTF-8? beans xmlns = http:www.springframework.orgschemabeans xmlns:xsi = http:www.w3.org2001XMLSchema-instance xsi:schemaLocation = http:www.springframework.orgschemabeans http:www.springframework.orgschemabeansspring-beans.xsd bean id = checkingAccountService class = org.springframework.jms.remoting.JmsInvokerServiceExporter property name = serviceInterface value = com.foo.CheckingAccountService property name = service bean class = com.foo.SimpleCheckingAccountService property bean bean class = org.springframework.jms.listener.SimpleMessageListenerContainer property name = connectionFactory ref = connectionFactory property name = destination ref = queue property name = concurrentConsumers value = 3 property name = messageListener ref = checkingAccountService bean beans package com.foo; import org.springframework.context.support.ClassPathXmlApplicationContext; public class Server { public static void mainString[] args throws Exception { new ClassPathXmlApplicationContext new String[]{ comfooserver.xml , comfoojms.xml }; } } Client-side configuration The client merely needs to create a client-side proxy that will implement the agreed upon interface CheckingAccountService . The resulting object created off the back of the following bean definition can be injected into other client side objects, and the proxy will take care of forwarding the call to the server-side object via JMS. 4.3.9.RELEASE Spring Framework 679 ?xml version=1.0 encoding=UTF-8? beans xmlns = http:www.springframework.orgschemabeans xmlns:xsi = http:www.w3.org2001XMLSchema-instance xsi:schemaLocation = http:www.springframework.orgschemabeans http:www.springframework.orgschemabeansspring-beans.xsd bean id = checkingAccountService class = org.springframework.jms.remoting.JmsInvokerProxyFactoryBean property name = serviceInterface value = com.foo.CheckingAccountService property name = connectionFactory ref = connectionFactory property name = queue ref = queue bean beans package com.foo; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class Client { public static void mainString[] args throws Exception { ApplicationContext ctx = new ClassPathXmlApplicationContext new String[] { comfooclient.xml , comfoojms.xml }; CheckingAccountService service = CheckingAccountService ctx.getBean checkingAccountService ; service.cancelAccount new Long10; } }

28.7 AMQP