EJB3.0 PatternsAsynchronous EJB3.1 Web Services using JMS                 Queues          Michael Mountrakis mountrakis@ui...
The problemMy company decided to migrate to EJB an old legacyasynchronous application. The requirements are:●   Re – use l...
Comply with EJB3.0 standards●   Use J2EE annotations instead of XML    deployment descriptors●   Do not use threads●   Do ...
Design Synopsis●   Design a Web Service to offer clients the ability to:    to create requests and monitor request status●...
Interfaces – Requests Web ServiceClients can order jobs and monitor their request @Remote public interface RequestProxyRem...
Interfaces – Results Web ServiceThis Web Service is called when the JMS queuefinishes with a request. This web service has...
Unified IT Services http:www.uit.gr
Implementation: Requests Web               Service@Stateless@Remote(RequestProxyRemote.class)@WebService@SOAPBinding(style...
Implementation: JMS Queue@MessageDriven(activationConfig = {@ActivationConfigProperty(propertyName = "destinationType",pro...
Implementation: JMS Queuepublic void onMessage(Message msg) {      StreamMessage Smsg = null;      try {         Smsg = (S...
Implementation: Results Service@Stateless@Remote(ResultsProxyRemote.class)@RemoteBinding(jndiBinding=ResultsProxyWS.JNDI_R...
QUEUE Deployment Descriptor for                  JBOSS     File: queue-example-service.xml<?xml version="1.0" encoding="UT...
Upcoming SlideShare
Loading in …5
×

Ejb3.0 Zejb3 Asynch Queue

556 views

Published on

A simple pattern for implementing Asynchronous Jobs using JMS queues on JBoss

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
556
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Ejb3.0 Zejb3 Asynch Queue

  1. 1. EJB3.0 PatternsAsynchronous EJB3.1 Web Services using JMS Queues Michael Mountrakis mountrakis@uit.gr Unified IT Services http:www.uit.gr
  2. 2. The problemMy company decided to migrate to EJB an old legacyasynchronous application. The requirements are:● Re – use legacy code from the application● Define EJB3 design that : ● Employ Jboss Web Service calls to order requests and monitor their status ● Employ a JMS Queue that will handle and process requests on a strict order ● Employ a Jboss service to receive a callback from the JMS queue when processing is finished. Unified IT Services http:www.uit.gr
  3. 3. Comply with EJB3.0 standards● Use J2EE annotations instead of XML deployment descriptors● Do not use threads● Do not use I/O● Benefit from EJB3.0 offered Jboss resources, like Pojo Services, JMX platform.... Unified IT Services http:www.uit.gr
  4. 4. Design Synopsis● Design a Web Service to offer clients the ability to: to create requests and monitor request status● Design a Jboss JMS Queue that will process WS calls and handle the processing status. Processing is taking place in strict order.● Design a Web Service that will be called from the JMS queue when request processing is finished. Unified IT Services http:www.uit.gr
  5. 5. Interfaces – Requests Web ServiceClients can order jobs and monitor their request @Remote public interface RequestProxyRemote { int processAsynch(String inData); String processStatus(int jobId); } Unified IT Services http:www.uit.gr
  6. 6. Interfaces – Results Web ServiceThis Web Service is called when the JMS queuefinishes with a request. This web service has remoteinterface:@Localpublic interface ResultsProxyRemote {void processResults(int jobId, String results);} Unified IT Services http:www.uit.gr
  7. 7. Unified IT Services http:www.uit.gr
  8. 8. Implementation: Requests Web Service@Stateless@Remote(RequestProxyRemote.class)@WebService@SOAPBinding(style = Style.RPC)public class RequestsProxyWS implements ProxyLocal,RequestProxyRemote { @Resource private SessionContext jndiContext; private ConnectionFactory connectionFactory = null; private Connection connection = null; private Session session = null; private MessageProducer producer = null; private Queue queue = null; private StreamMessage OutgoingMsg = null; Unified IT Services http:www.uit.gr
  9. 9. Implementation: JMS Queue@MessageDriven(activationConfig = {@ActivationConfigProperty(propertyName = "destinationType",propertyValue = "javax.jms.Queue"),@ActivationConfigProperty(propertyName = "destination",propertyValue = RequestsProcessorMDB.QUEUE_NAME) })public class RequestsProcessorMDB implements MessageListener { public static final String QUEUE_NAME ="queue/tutorial/example";private static HashMap<Integer,String> map = newHashMap<Integer,String>(); Unified IT Services http:www.uit.gr
  10. 10. Implementation: JMS Queuepublic void onMessage(Message msg) { StreamMessage Smsg = null; try { Smsg = (StreamMessage) msg; /* Acknowledge message */ msg.acknowledge(); Integer key = Smsg.readInt(); String data = Smsg.readString(); Cntext jndiContext = new InitialContext(); ResultsProxyRemote resultsRemote = (ResultsProxyRemote)jndiContext.lookup(ResultsProxyWS.JNDI_REMOTE); resultsRemote.processResults(key, results); } catch (Throwable te) { }} Unified IT Services http:www.uit.gr
  11. 11. Implementation: Results Service@Stateless@Remote(ResultsProxyRemote.class)@RemoteBinding(jndiBinding=ResultsProxyWS.JNDI_REMOTE)@WebService@SOAPBinding(style = Style.RPC)public class ResultsProxyWS implements ProxyLocal,ResultsProxyRemote { public static final String JNDI_NAME = "ResultsProxyWS"; public static final String JNDI_REMOTE = JNDI_NAME +"/remote"; @WebMethod @Override public void processResults(@WebParam(name = "jobId") intjobId, @WebParam(name = "results") Stringresults) { System.out.println("processResults() -> got result:" +results); }} Unified IT Services http:www.uit.gr
  12. 12. QUEUE Deployment Descriptor for JBOSS File: queue-example-service.xml<?xml version="1.0" encoding="UTF-8"?><server> <mbean code="org.jboss.mq.server.jmx.Queue" name="jboss.mq.destination:service=Queue,name=tutorial"> <attribute name="JNDIName">queue/tutorial/example</attribute> <depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager</depends> </mbean></server> This must be deployed once to the JBOSS deployment directory Unified IT Services http:www.uit.gr

×