This sample(samples\java_first_jms) demonstrates how to connect to web services across JMS transport, instead of HTTP as in the previous examples.
Web Service Contract – jms_greeter.wsdl
The wsdl:binding contains the important information that this sample will operate on JMS –
Finally the wsdl:port definition defines the JMS Queue properties –
[sourcecode lang=”xml”] <wsdl:service name="JMSGreeterService">The implementation classes can be generated through the maven wsdl2java task.
Service Implementation
GreeterJMSImpl implements the JMSGreeterPortType interface –
[sourcecode lang=”java”] @javax.jws.WebService(portName = &quot;GreeterPort&quot;,Client
The Client class demonstrates how simple it is to call a JMS service using the wsdl URI –
[sourcecode lang=”java”] JMSGreeterService service = new JMSGreeterService(wsdl.toURI().toURL(), SERVICE_NAME);System.out.println(&quot;Invoking sayHi…&quot;);
System.out.println(&quot;server responded with: &quot; + greeter.sayHi());
System.out.println();
System.out.println(&quot;Invoking greetMe…&quot;);
System.out.println(&quot;server responded with: &quot; + greeter.greetMe(System.getProperty(&quot;user.name&quot;)));
System.out.println();
System.out.println(&quot;Invoking greetMeOneWay…&quot;);
greeter.greetMeOneWay(System.getProperty(&quot;user.name&quot;));
System.out.println(&quot;No response from server as method is OneWay&quot;);
System.out.println();
[/sourcecode]
ActiveMQ
The demonstration stores the message queue in Memory –
[sourcecode lang=”java”] public final class EmbeddedBroker { public static void main(String[] args) throws Exception {
BrokerService broker = new BrokerService();
broker.setPersistenceAdapter(new MemoryPersistenceAdapter());
broker.setDataDirectory(&quot;target/activemq-data&quot;);
broker.addConnector(&quot;tcp://localhost:61616&quot;);
broker.start();
System.out.println(&quot;JMS broker ready …&quot;);
Thread.sleep(125 * 60 * 1000);
System.out.println(&quot;JMS broker exiting&quot;);
broker.stop();
System.exit(0);
}
}
[/sourcecode]
Running The Example
mvn install (this will build the demo)
In separate command windows/shells:
mvn -Pjms.broker
mvn -Pserver
mvn -Pclient
With the output –
[sourcecode] INFO: Creating Service {http://cxf.apache.org/jms_greeter}JMSGreeterService fromInvoking greetMe…
server responded with: Hello Martin
Invoking greetMeOneWay…
No response from server as method is OneWay
Invoking sayHi with JMS Context information …
server responded with: Bonjour
Received expected contents in response context
[/sourcecode]