Example usage for javax.jms TextMessage toString

List of usage examples for javax.jms TextMessage toString

Introduction

In this page you can find the example usage for javax.jms TextMessage toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:com.oneops.inductor.MessagePublisher.java

@Override
protected boolean process(MessageHolder holder) {
    Map<String, String> event = holder.getMap();
    try {/*from   w ww.  j  a v  a2  s.  co m*/
        TextMessage message = session.createTextMessage(event.get("body"));
        message.setJMSCorrelationID(event.get("correlationID"));

        for (Map.Entry<String, String> kv : event.entrySet()) {
            if (!kv.getKey().equals("body")) {
                message.setStringProperty(kv.getKey(), kv.getValue());
            }
        }

        MessageProducer producer = regularProducer;
        if ("high".equals(event.get("priority"))) {
            producer = priorityProducer;
            logger.debug("using priority producer to publish message");
        }

        producer.send(message);
        logger.debug("Published: " + message.toString());
        return true;
    } catch (NullPointerException npe) {
        // happens when amq session is null
        logger.warn("caught NullPointerException - reconnecting to broker");
        waitSome();
        init();
        return false;

    } catch (IllegalStateException e) {
        // this happens when connection is hosed - lets re-init
        logger.warn("caught IllegalStateException - reconnecting to broker");
        init();
        return false;

    } catch (JMSException e) {
        logger.error(e.getMessage());
        logger.debug(e.getMessage(), e);
        return false;
    }
}