How To Have A Synchronous Jms Message

This tutorial requires that you lot bring glassfish installed in addition to followed the next previous two tutorials:

https://ngeblognow.blogspot.com//search?q=how-to-setup-set-jms-factory-and-queue
https://ngeblognow.blogspot.com//search?q=how-to-setup-set-jms-factory-and-queue

For simplicity, nosotros volition simply extend the JMSSender aeroplane that nosotros bring defined from the previous tutorial in addition to add together the ff method:

public void getMessages() throws JMSException {  ObjectMessage objectMessage;   QueueConnection connexion = null;  QueueSession session = null;  QueueReceiver queueReceiver = null;  boolean goodByeReceived = false;  motility {   connexion = openQueueConnection();   session = connection.createQueueSession(transacted,     QueueSession.AUTO_ACKNOWLEDGE);   queueReceiver = session.createReceiver(queue);   connection.start();   spell (!goodByeReceived) {    log.debug("[xxx-commons] Waiting for messages...");    objectMessage = (ObjectMessage) queueReceiver.receive();    MessageDTO message = MessageDTOHelper      .deserialize(objectMessage);    if (message != null) {     log.debug("[xxx-commons] Received the next message: ");     log.debug("[xxx-commons] message: " + message.toString()       + " : " + message.getRequestId());    }    if (message.getRequestId() != goose egg      && message.getRequestId().equals("7d")) {     goodByeReceived = true;    }   }   log.debug("[xxx-commons] jms have done");  } live {   closeQueueReceiver(queueReceiver);   closeSession(session);   closeConnection(connection);  } } 
This method volition read from the queue that nosotros bring defined. Note that queueReceiver.receive() without parameter volition block until there's a jms message inward queue.

 Tip you lot tin practise a generic jms receiver aeroplane that you lot tin extend for unlike DTOs.
Next
Previous
Click here for Comments

0 komentar:

Please comment if there are any that need to be asked.