Example usage for javax.jms ObjectMessage setJMSDeliveryMode

List of usage examples for javax.jms ObjectMessage setJMSDeliveryMode

Introduction

In this page you can find the example usage for javax.jms ObjectMessage setJMSDeliveryMode.

Prototype


void setJMSDeliveryMode(int deliveryMode) throws JMSException;

Source Link

Document

Sets the DeliveryMode value for this message.

Usage

From source file:com.oneops.daq.jms.SensorPublisher.java

/**
 * Publish message./* w  w  w. j  ava 2  s .  c o  m*/
 *
 * @param event the event
 * @throws JMSException the jMS exception
 */
public void publishMessage(final BasicEvent event) throws JMSException {

    if (System.currentTimeMillis() > lastFailureTimestamp) {
        int shard = (int) (event.getManifestId() % poolsize);
        try {
            producers[shard].send(session -> {
                ObjectMessage message = session.createObjectMessage(event);
                message.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
                message.setLongProperty("ciId", event.getCiId());
                message.setLongProperty("manifestId", event.getManifestId());
                message.setStringProperty("source", event.getSource());
                if (logger.isDebugEnabled()) {
                    logger.debug("Published: ciId:" + event.getCiId() + "; source:" + event.getSource());
                }
                return message;
            });
            lastFailureTimestamp = -1;
        } catch (JmsException exception) {
            logger.warn("There was an error sending a message. Discarding messages for " + mqConnectionThreshold
                    + " ms");
            lastFailureTimestamp = System.currentTimeMillis() + mqConnectionThreshold;
        }
    }
}