Example usage for javax.jms Message DEFAULT_DELIVERY_MODE

List of usage examples for javax.jms Message DEFAULT_DELIVERY_MODE

Introduction

In this page you can find the example usage for javax.jms Message DEFAULT_DELIVERY_MODE.

Prototype

int DEFAULT_DELIVERY_MODE

To view the source code for javax.jms Message DEFAULT_DELIVERY_MODE.

Click Source Link

Document

The message producer's default delivery mode is PERSISTENT .

Usage

From source file:org.apache.flink.streaming.connectors.jms.JmsQueueSink.java

@Override
public void invoke(final T object) throws Exception {
    try {//from   www.  j  a v  a  2s  . c om
        producer.send(destination, convert(object, session), Message.DEFAULT_DELIVERY_MODE,
                Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);
    } catch (JMSException e) {
        logger.error("Error sending message to [{}]: {}", destination.getQueueName(), e.getLocalizedMessage());
        throw new UncategorizedJmsException(e);
    }
}

From source file:org.apache.flink.streaming.connectors.jms.JmsTopicSink.java

@Override
public void invoke(final T object) throws Exception {
    try {/*from ww  w . jav a  2  s .c  o  m*/
        producer.publish(destination, convert(object, session), Message.DEFAULT_DELIVERY_MODE,
                Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);
    } catch (JMSException e) {
        logger.error("Error sending message to [{}]: {}", destination.getTopicName(), e.getLocalizedMessage(),
                e);
        throw new UncategorizedJmsException(e);
    }
}

From source file:me.norman.maurer.james.queue.HornetQMailQueue.java

@Override
protected void produceMail(Session session, Map<String, Object> props, int msgPrio, Mail mail)
        throws JMSException, MessagingException, IOException {
    MessageProducer producer = null;//from w w w.  ja va 2 s  .  c  om
    try {
        BytesMessage message = session.createBytesMessage();
        Iterator<String> propIt = props.keySet().iterator();
        while (propIt.hasNext()) {
            String key = propIt.next();
            message.setObjectProperty(key, props.get(key));
        }
        // set the stream to read frome
        message.setObjectProperty("JMS_HQ_InputStream",
                new BufferedInputStream(new MimeMessageInputStream(mail.getMessage())));
        Queue q = session.createQueue(queuename);
        producer = session.createProducer(q);
        producer.send(message, Message.DEFAULT_DELIVERY_MODE, msgPrio, Message.DEFAULT_TIME_TO_LIVE);
    } finally {
        if (producer != null) {
            producer.close();
        }
    }
}

From source file:org.apache.james.queue.activemq.ActiveMQMailQueue.java

/**
 * Produce the mail to the JMS Queue/*from   www.jav a  2s.c o m*/
 */
protected void produceMail(Session session, Map<String, Object> props, int msgPrio, Mail mail)
        throws JMSException, MessagingException, IOException {
    MessageProducer producer = null;
    BlobMessage blobMessage = null;
    boolean reuse = false;

    try {

        // check if we should use a blob message here
        if (useBlob) {
            MimeMessage mm = mail.getMessage();
            MimeMessage wrapper = mm;

            ActiveMQSession amqSession = getAMQSession(session);

            /*
             * Remove this optimization as it could lead to problems when the same blob content
             * is shared across different messages. 
             * 
             * I still think it would be a good idea to somehow do this but at the moment it's just 
             * safer to disable it.
             * 
             * TODO: Re-Enable it again once it works!
             * 
             * See JAMES-1240
            if (wrapper instanceof MimeMessageCopyOnWriteProxy) {
            wrapper = ((MimeMessageCopyOnWriteProxy) mm).getWrappedMessage();
            }
                    
            if (wrapper instanceof MimeMessageWrapper) {
            URL blobUrl = (URL) mail.getAttribute(JAMES_BLOB_URL);
            String fromQueue = (String) mail.getAttribute(JAMES_QUEUE_NAME);
            MimeMessageWrapper mwrapper = (MimeMessageWrapper) wrapper;
                    
            if (blobUrl != null && fromQueue != null && mwrapper.isModified() == false) {
                // the message content was not changed so don't need to
                // upload it again and can just point to the url
                blobMessage = amqSession.createBlobMessage(blobUrl);
                reuse = true;
            }
                    
            }*/
            if (blobMessage == null) {
                // just use the MimeMessageInputStream which can read every
                // MimeMessage implementation
                blobMessage = amqSession.createBlobMessage(new MimeMessageInputStream(wrapper));
            }

            // store the queue name in the props
            props.put(JAMES_QUEUE_NAME, queuename);

            Queue queue = session.createQueue(queuename);

            producer = session.createProducer(queue);
            for (Map.Entry<String, Object> entry : props.entrySet()) {
                blobMessage.setObjectProperty(entry.getKey(), entry.getValue());
            }
            producer.send(blobMessage, Message.DEFAULT_DELIVERY_MODE, msgPrio, Message.DEFAULT_TIME_TO_LIVE);

        } else {
            super.produceMail(session, props, msgPrio, mail);
        }
    } catch (JMSException e) {
        if (!reuse && blobMessage != null && blobMessage instanceof ActiveMQBlobMessage) {
            ((ActiveMQBlobMessage) blobMessage).deleteFile();
        }
        throw e;
    } finally {

        try {
            if (producer != null)
                producer.close();
        } catch (JMSException e) {
            // ignore here
        }
    }

}

From source file:org.apache.james.queue.jms.JMSMailQueue.java

/**
 * Produce the mail to the JMS Queue//from   ww w.ja  va2 s  .  c  o m
 */
protected void produceMail(Map<String, Object> props, int msgPrio, Mail mail)
        throws JMSException, MessagingException, IOException {
    ObjectMessage message = session.createObjectMessage();

    for (Map.Entry<String, Object> entry : props.entrySet()) {
        message.setObjectProperty(entry.getKey(), entry.getValue());
    }

    long size = mail.getMessageSize();
    ByteArrayOutputStream out;
    if (size > -1) {
        out = new ByteArrayOutputStream((int) size);
    } else {
        out = new ByteArrayOutputStream();
    }
    mail.getMessage().writeTo(out);

    // store the byte array in a ObjectMessage so we can use a
    // SharedByteArrayInputStream later
    // without the need of copy the day
    message.setObject(out.toByteArray());

    producer.send(message, Message.DEFAULT_DELIVERY_MODE, msgPrio, Message.DEFAULT_TIME_TO_LIVE);
}

From source file:org.apache.qpid.disttest.controller.config.ProducerConfig.java

public ProducerConfig() {
    _deliveryMode = Message.DEFAULT_DELIVERY_MODE;
    _messageSize = 1024;/*from  w  w w  . j a v a2 s.com*/
    _priority = Message.DEFAULT_PRIORITY;
    _timeToLive = Message.DEFAULT_TIME_TO_LIVE;
    _interval = 0;
    _startDelay = 0;
    _messageProviderName = null;
}

From source file:org.apache.rocketmq.jms.RocketMQProducer.java

/**
 * Init the JmsMessage Headers.//from   w  w w .  j a va2  s  . c  om
 * <p/>
 * <P>JMS providers init message's headers. Do not allow user to set these by yourself.
 *
 * @param rmqJmsMsg message
 * @param destination
 * @throws javax.jms.JMSException
 * @see <CODE>Destination</CODE>
 */
private void initJMSHeaders(RocketMQMessage rmqJmsMsg, Destination destination) throws JMSException {

    //JMS_DESTINATION default:"topic:message"
    rmqJmsMsg.setHeader(JMS_DESTINATION, destination);
    //JMS_DELIVERY_MODE default : PERSISTENT
    rmqJmsMsg.setHeader(JMS_DELIVERY_MODE, javax.jms.Message.DEFAULT_DELIVERY_MODE);
    //JMS_TIMESTAMP default : current time
    rmqJmsMsg.setHeader(JMS_TIMESTAMP, System.currentTimeMillis());
    //JMS_EXPIRATION default :  3 days
    //JMS_EXPIRATION = currentTime + time_to_live
    rmqJmsMsg.setHeader(JMS_EXPIRATION, System.currentTimeMillis() + DEFAULT_TIME_TO_LIVE);
    //JMS_PRIORITY default : 4
    rmqJmsMsg.setHeader(JMS_PRIORITY, javax.jms.Message.DEFAULT_PRIORITY);
    //JMS_TYPE default : ons(open notification service)
    rmqJmsMsg.setHeader(JMS_TYPE, DEFAULT_JMS_TYPE);
    //JMS_REPLY_TO,JMS_CORRELATION_ID default : null
    //JMS_MESSAGE_ID is set by sendResult.
    //JMS_REDELIVERED is set by broker.
}

From source file:org.apache.synapse.message.store.impl.jms.JmsProducer.java

private void setJmsProducerProperties(javax.jms.MessageProducer producer, MessageContext synCtx) {
    Object prop = synCtx.getProperty(JMS_PROD_TIME_TO_LIVE);
    long ttl = Message.DEFAULT_TIME_TO_LIVE;
    if (prop instanceof String) {
        ttl = Long.parseLong((String) prop);
    } else if (prop instanceof Long || prop instanceof Integer) {
        ttl = Long.parseLong(prop.toString());
    }/* w  ww .  j av  a 2s .c  om*/
    prop = synCtx.getProperty(JMS_PROD_DISABLE_MSG_TIMESTAMP);
    boolean disableMessageTimestamp = false;
    if (prop instanceof String) {
        disableMessageTimestamp = Boolean.parseBoolean((String) prop);
    } else if (prop instanceof Boolean) {
        disableMessageTimestamp = (Boolean) prop;
    }
    prop = synCtx.getProperty(JMS_PROD_DELIVERY_MODE);
    int deliveryMode = Message.DEFAULT_DELIVERY_MODE;
    if (prop instanceof Integer) {
        deliveryMode = (Integer) prop;
    } else if (prop instanceof String) {
        deliveryMode = Integer.parseInt((String) prop);
    }
    prop = synCtx.getProperty(JMS_PROD_DISABLE_MSG_ID);
    boolean disableMessageId = false;
    if (prop instanceof String) {
        disableMessageId = Boolean.parseBoolean((String) prop);
    } else if (prop instanceof Boolean) {
        disableMessageId = (Boolean) prop;
    }
    prop = synCtx.getProperty(JMS_PROD_PRIORITY);
    int priority = Message.DEFAULT_PRIORITY;
    if (prop instanceof Integer) {
        priority = (Integer) prop;
    } else if (prop instanceof String) {
        priority = Integer.parseInt((String) prop);
    }
    try {
        producer.setTimeToLive(ttl);
        producer.setDisableMessageTimestamp(disableMessageTimestamp);
        producer.setDeliveryMode(deliveryMode);
        producer.setDisableMessageID(disableMessageId);
        producer.setPriority(priority);
    } catch (JMSException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Could not save Producer property: " + e.getLocalizedMessage());
        }
    }
}