Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

read(MessageConsumer consumer)

The method is called with an already instantiated MessageConsumer object to receive a message from the MQ server. It extracts the value from the Message object as a string representation via the Message objects getText() method. 

Code Block
languagejava
titleread()
linenumberstrue
collapsetrue
private String read(MessageConsumer consumer) {
    TextMessage message = null;
    String textMessage = null;
    try {
        while (true) {
            Message receivedMessage = consumer.receive(1);
            if (receivedMessage != null) {
                if (receivedMessage instanceof TextMessage) {
                    message = (TextMessage) receivedMessage;
                    textMessage = message.getText();
                    LOGGER.info("Reading message: " + textMessage);
                    break;
                } else {
                    break;
                }
            }
        }
    } catch (JMSException e) {
        LOGGER.error("JMSException occurred while trying to read from Destination: ", e);
    }
    return textMessage;
}

...