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

334

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

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

  • Be the first to like this

No Downloads
Views
Total Views
334
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. EJB3.0 PatternsAsynchronous EJB3.1 Web Services using JMS Queues Michael Mountrakis mountrakis@uit.gr Unified IT Services http:www.uit.gr
  • 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. 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. 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. 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. 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. Unified IT Services http:www.uit.gr
  • 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. 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. 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. 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. 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

×