Discussions

EJB design: Examples of architecture using JMS

  1. Examples of architecture using JMS (4 messages)

    Could please anyone give advantages of using JMS and Message-Driven Beans in architecture of distributed applications
    Thanks
     

    Threaded Messages (4)

  2. Examples of architecture using JMS[ Go to top ]

    JMS and MDBs provide the ability to fire off asynchronous, fire and forget logic. One of the biggest areas I see JMS/MDBs taking off is B2B integration. With this new 1-2 punch combo, when an XML file is received via a Servlet, an MDB can be invoked, and the next file coming in can be handled. This allows the processing of the messages to be queued up, and a more responsive reception of the incoming message results.

    Another example is file manipulation, again along the lines of B2B. Let's say we receive a well-known XML file format via a Servlet, but the company runs a proprietary, home-grown ERP system that expects files in a particular format. Developers could easily write a small JMS/MDB app that handles such things. The XML file format is identified, and then dispatched to an appropriate MDB for the appropriate translating into the proprietary format, asynchronously.

    Finally, consider reporting. Someone could request a report. The app server takes the details about the report (report args, etc.) from a stateless session bean and fires off an MDB. When that MDB is completed (i.e. the report has been printed) it fires off another MDB that alerts the user that their print job has just completed.

    Hope this gives you some ideas about what JMS/MDB is capable of.

    Jason Weiss
    Internet Applications Division
    Sybase, Inc.
  3. Examples of architecture using JMS[ Go to top ]

    hi
    Jason

    i really appriciate if u can provide some good urls
    and live code examples on MDBs.
    i like to know on which application server u r working with.
    Thanx in advance.

    Manoj Sharma



     
  4. Examples of architecture using JMS[ Go to top ]

    Manoj,
    Here are samples and a brief info. about JMS. Hope this helps.
    Ajeet

    ``````````````````````````````````````````````````````````

    JMS - Java message service helps to simulate a MOM (message oriented middleware) protocol.


    Advantages:-


    1) Asynchronous message transportation.


    2) Fault-tolerant delivery


    3) Point-to-point (QUEUE MESSAGES) or Publish-Subscriber (TOPIC MESSAGES) messaging capability.


    4) IBM's MQSeries that currently has a wide market for MOM is also givingJMS extensions apart from it's regular Java API. In short, JMS is going to become astandard akin to JNDI in the J2EE world.


    5) Since JMS is a standard API all your senders and receivers will remain the same (except for arguments tomethods) even if the servers migrate from Weblogic to a WebSphere or vice-versa.


    Dis-advantages:-


    1) Slow due to extra middleware.


    2) Needs additional interface to incorporate JMS services.


    Message driven beans are basicly EJB bean (components) message routers that help you inteface with the J2EE-JMS server that comes with Web Logic or JRUN etc. Essentially a sender could look up the JNDI contexts for a QueueConnectionFactory or TopicConnectionFactory defined by WebLogic or JRUN. With this factory you could create a connection.


    //STEP 1 JRUN SAMPLE


     final QueueConnectionFactory factory = (QueueConnectionFactory)_context.lookup(QueueConnectionFactory.class.getName());


    _connection = factory.createQueueConnection();


    Next get the session, either QueueSession or TopicSession from the connection


    //STEP2


    _session = _connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);


    Next both queues and topics, applications typically obtain the appropriate object via JNDI or they create it dynamically:


    //STEP3


    _queue = _session.createQueue("QUEUE_NAME")


    or


     public static final String QUEUE = "QUEUE_NAME";


     queue = (Queue) context.lookup(QUEUE);


    Next use the appropriate sender and/or receiver objects from the session:


    //STEP4


    _message = _session.createTextMessage();


    _sender = _session.createSender(Queue);


    As for messages JMS provides the unifying base interface Message, and five interface specializations:-


    A)BytesMessage - for a raw stream of bytes


    B)StreamMessage - for a stream of Java primitive values


    C)ObjectMessage - for a single serializable Java object


    D)MapMessage - for name-value pairs where names are strings and values are Java primitives


    E)TextMessage - for a single string value, which could be, for example, an HTML or XML stream


    Note: For subscribers to be notified about a TOPIC they have to register with queue withthe topic of interest.


    On the receiver front to simulate an Asynchronous receiver all you need to do isimplement a MessageListener. Which will force your class to implement the onMessage(Message msg)method.


    Similarily,on the receiver front to simulate a Synchronous receiver all you need to do isimplement a receiver.receive() method.


    Regards


    Ajeet Koru
  5. Examples of architecture using JMS[ Go to top ]

    Advantages:-


    1) Synchronous and Asynchronous message transportation.

    oops...sorry
    Ajeet