Example usage for javax.jms Message DEFAULT_TIME_TO_LIVE

List of usage examples for javax.jms Message DEFAULT_TIME_TO_LIVE

Introduction

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

Prototype

long DEFAULT_TIME_TO_LIVE

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

Click Source Link

Document

The message producer's default time to live is unlimited; the message never expires.

Usage

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

@Override
public void invoke(final T object) throws Exception {
    try {//from   w w  w .  ja  v  a  2  s .c  o  m
        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  w w w .  j av  a2s.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.  j  a  v a 2  s .  com*/
    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   w ww  .jav a 2 s .  co 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:net.timewalker.ffmq4.admin.RemoteAdministrationThread.java

@Override
public void run() {
    log.info("Starting remote administration thread ...");

    try {//from  w  w  w . j av a2  s  . co  m
        LocalQueue inputQueue = engine.getLocalQueue(FFMQConstants.ADM_REQUEST_QUEUE);
        LocalQueue outputQueue = engine.getLocalQueue(FFMQConstants.ADM_REPLY_QUEUE);

        conn = new LocalQueueConnection(engine, null, null);
        session = conn.createQueueSession(true, Session.SESSION_TRANSACTED);
        receiver = session.createReceiver(inputQueue);
        sender = session.createSender(outputQueue);

        conn.start();

        // Flush input queue on startup
        inputQueue.purge(null);
        outputQueue.purge(null);

        // Enter listening loop
        notifyStartup();
        while (!stopRequired) {
            Message message = receiver.receive();
            if (message == null)
                break; // Interrupted
            log.debug("Received message " + message);

            try {
                // Process the command
                String errorMsg = process(message);

                // Build response message
                Message response = session.createMessage();
                response.setJMSCorrelationID(message.getJMSMessageID());
                if (errorMsg != null)
                    response.setStringProperty(FFMQAdminConstants.ADM_HEADER_ERRMSG, errorMsg);

                sender.send(response, DeliveryMode.NON_PERSISTENT, Message.DEFAULT_PRIORITY,
                        Message.DEFAULT_TIME_TO_LIVE);
            } catch (JMSException e) {
                log.error("Cannot process admin command", e);
            } finally {
                session.commit();
            }
        }

        log.debug("Remote administration thread has stopped");
    } catch (Throwable e) {
        log.fatal("Administration thread failed", e);
        notifyStartup();
    } finally {
        try {
            if (sender != null)
                sender.close();
        } catch (JMSException e) {
            ErrorTools.log(e, log);
        }

        try {
            if (receiver != null)
                receiver.close();
        } catch (JMSException e) {
            ErrorTools.log(e, log);
        }

        try {
            if (session != null)
                session.close();
        } catch (JMSException e) {
            ErrorTools.log(e, log);
        }

        try {
            if (conn != null)
                conn.close();
        } catch (JMSException e) {
            ErrorTools.log(e, log);
        }
    }
}

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

/**
 * Produce the mail to the JMS Queue//  w w  w. ja va  2 s  . co 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 . ja  v a2  s .c o  m*/
    _priority = Message.DEFAULT_PRIORITY;
    _timeToLive = Message.DEFAULT_TIME_TO_LIVE;
    _interval = 0;
    _startDelay = 0;
    _messageProviderName = null;
}

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 w w .  j  a va  2s.c  o m*/
    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());
        }
    }
}

From source file:org.mule.transport.jms.Jms11Support.java

public void send(MessageProducer producer, Message message, boolean topic, ImmutableEndpoint endpoint)
        throws JMSException {
    send(producer, message, connector.isPersistentDelivery(), Message.DEFAULT_PRIORITY,
            Message.DEFAULT_TIME_TO_LIVE, topic, endpoint);
}

From source file:org.mule.transport.jms.Jms11Support.java

public void send(MessageProducer producer, Message message, Destination dest, boolean topic,
        ImmutableEndpoint endpoint) throws JMSException {
    send(producer, message, dest, connector.isPersistentDelivery(), Message.DEFAULT_PRIORITY,
            Message.DEFAULT_TIME_TO_LIVE, topic, endpoint);
}