SlideShare une entreprise Scribd logo
1  sur  12
Télécharger pour lire hors ligne
EJB3.0 Patterns




Asynchronous EJB3.1 Web Services using JMS
                 Queues
          Michael Mountrakis mountrakis@uit.gr




              Unified IT Services http:www.uit.gr
The problem
My company decided to migrate to EJB an old legacy
asynchronous 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 Service
Clients 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 Service
This Web Service is called when the JMS queue
finishes with a request. This web service has remote
interface:
@Local
public 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 = new
HashMap<Integer,String>();




                    Unified IT Services http:www.uit.gr
Implementation: JMS Queue

public 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") int
jobId,
                            @WebParam(name = "results") String
results) {
      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</d
epends>
   </mbean>

</server>



  This must be deployed once to the JBOSS deployment directory


                             Unified IT Services http:www.uit.gr

Contenu connexe

Similaire à Ejb3.0 Zejb3 Asynch Queue

May 2010 - RestEasy
May 2010 - RestEasyMay 2010 - RestEasy
May 2010 - RestEasyJBug Italy
 
DDD Framework for Java: JdonFramework
DDD Framework for Java: JdonFrameworkDDD Framework for Java: JdonFramework
DDD Framework for Java: JdonFrameworkbanq jdon
 
4Developers: Dominik Przybysz- Message Brokers
4Developers: Dominik Przybysz- Message Brokers4Developers: Dominik Przybysz- Message Brokers
4Developers: Dominik Przybysz- Message BrokersPROIDEA
 
Mobile webapplication development
Mobile webapplication developmentMobile webapplication development
Mobile webapplication developmentGanesh Gembali
 
Hazelcast and MongoDB at Cloud CMS
Hazelcast and MongoDB at Cloud CMSHazelcast and MongoDB at Cloud CMS
Hazelcast and MongoDB at Cloud CMSuzquiano
 
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)Red Hat Developers
 
Rapid prototyping using azure functions - A walk on the wild side
Rapid prototyping using azure functions - A walk on the wild sideRapid prototyping using azure functions - A walk on the wild side
Rapid prototyping using azure functions - A walk on the wild sideSamrat Saha
 
Scaling asp.net websites to millions of users
Scaling asp.net websites to millions of usersScaling asp.net websites to millions of users
Scaling asp.net websites to millions of usersoazabir
 
nodejs_at_a_glance.ppt
nodejs_at_a_glance.pptnodejs_at_a_glance.ppt
nodejs_at_a_glance.pptWalaSidhom1
 
Bt0083 server side programing
Bt0083 server side programing Bt0083 server side programing
Bt0083 server side programing Techglyphs
 
Engage 2023: Taking Domino Apps to the next level by providing a Rest API
Engage 2023: Taking Domino Apps to the next level by providing a Rest APIEngage 2023: Taking Domino Apps to the next level by providing a Rest API
Engage 2023: Taking Domino Apps to the next level by providing a Rest APISerdar Basegmez
 
Web Technologies - forms and actions
Web Technologies -  forms and actionsWeb Technologies -  forms and actions
Web Technologies - forms and actionsAren Zomorodian
 

Similaire à Ejb3.0 Zejb3 Asynch Queue (20)

RESTEasy
RESTEasyRESTEasy
RESTEasy
 
May 2010 - RestEasy
May 2010 - RestEasyMay 2010 - RestEasy
May 2010 - RestEasy
 
DDD Framework for Java: JdonFramework
DDD Framework for Java: JdonFrameworkDDD Framework for Java: JdonFramework
DDD Framework for Java: JdonFramework
 
4Developers: Dominik Przybysz- Message Brokers
4Developers: Dominik Przybysz- Message Brokers4Developers: Dominik Przybysz- Message Brokers
4Developers: Dominik Przybysz- Message Brokers
 
Mobile webapplication development
Mobile webapplication developmentMobile webapplication development
Mobile webapplication development
 
Hazelcast and MongoDB at Cloud CMS
Hazelcast and MongoDB at Cloud CMSHazelcast and MongoDB at Cloud CMS
Hazelcast and MongoDB at Cloud CMS
 
AD102 - Break out of the Box
AD102 - Break out of the BoxAD102 - Break out of the Box
AD102 - Break out of the Box
 
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
 
ITI006En-AJAX
ITI006En-AJAXITI006En-AJAX
ITI006En-AJAX
 
Rapid prototyping using azure functions - A walk on the wild side
Rapid prototyping using azure functions - A walk on the wild sideRapid prototyping using azure functions - A walk on the wild side
Rapid prototyping using azure functions - A walk on the wild side
 
Scaling asp.net websites to millions of users
Scaling asp.net websites to millions of usersScaling asp.net websites to millions of users
Scaling asp.net websites to millions of users
 
WCF Fundamentals
WCF Fundamentals WCF Fundamentals
WCF Fundamentals
 
AJppt.pptx
AJppt.pptxAJppt.pptx
AJppt.pptx
 
nodejs_at_a_glance.ppt
nodejs_at_a_glance.pptnodejs_at_a_glance.ppt
nodejs_at_a_glance.ppt
 
Ajax
AjaxAjax
Ajax
 
Meet with Meteor
Meet with MeteorMeet with Meteor
Meet with Meteor
 
Bt0083 server side programing
Bt0083 server side programing Bt0083 server side programing
Bt0083 server side programing
 
Engage 2023: Taking Domino Apps to the next level by providing a Rest API
Engage 2023: Taking Domino Apps to the next level by providing a Rest APIEngage 2023: Taking Domino Apps to the next level by providing a Rest API
Engage 2023: Taking Domino Apps to the next level by providing a Rest API
 
my accadanic project ppt
my accadanic project pptmy accadanic project ppt
my accadanic project ppt
 
Web Technologies - forms and actions
Web Technologies -  forms and actionsWeb Technologies -  forms and actions
Web Technologies - forms and actions
 

Ejb3.0 Zejb3 Asynch Queue

  • 1. EJB3.0 Patterns Asynchronous EJB3.1 Web Services using JMS Queues Michael Mountrakis mountrakis@uit.gr Unified IT Services http:www.uit.gr
  • 2. The problem My company decided to migrate to EJB an old legacy asynchronous 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 Service Clients 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 Service This Web Service is called when the JMS queue finishes with a request. This web service has remote interface: @Local public 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 = new HashMap<Integer,String>(); Unified IT Services http:www.uit.gr
  • 10. Implementation: JMS Queue public 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") int jobId, @WebParam(name = "results") String results) { 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</d epends> </mbean> </server> This must be deployed once to the JBOSS deployment directory Unified IT Services http:www.uit.gr