Your SlideShare is downloading. ×
Ejb3.0 Zejb3 Asynch Queue
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.

Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Ejb3.0 Zejb3 Asynch Queue


Published on

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

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

  • Be the first to comment

  • Be the first to like this

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

No notes for slide


  • 1. EJB3.0 PatternsAsynchronous EJB3.1 Web Services using JMS Queues Michael Mountrakis Unified IT Services
  • 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
  • 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
  • 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
  • 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
  • 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
  • 7. Unified IT Services
  • 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
  • 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
  • 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
  • 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
  • 12. QUEUE Deployment Descriptor for JBOSS File: queue-example-service.xml<?xml version="1.0" encoding="UTF-8"?><server> <mbean code="" name=",name=tutorial"> <attribute name="JNDIName">queue/tutorial/example</attribute> <depends optional-attribute-name="DestinationManager"></depends> </mbean></server> This must be deployed once to the JBOSS deployment directory Unified IT Services