• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Ejb3.0 Zejb3 Asynch Queue
 

Ejb3.0 Zejb3 Asynch Queue

on

  • 450 views

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

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

Statistics

Views

Total Views
450
Views on SlideShare
449
Embed Views
1

Actions

Likes
0
Downloads
2
Comments
0

1 Embed 1

http://www.linkedin.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Ejb3.0 Zejb3 Asynch Queue Ejb3.0 Zejb3 Asynch Queue Presentation Transcript

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