Example usage for javax.jms TopicPublisher send

List of usage examples for javax.jms TopicPublisher send

Introduction

In this page you can find the example usage for javax.jms TopicPublisher send.

Prototype


void send(Message message) throws JMSException;

Source Link

Document

Sends a message using the MessageProducer 's default delivery mode, priority, and time to live.

Usage

From source file:org.grouter.common.jms.TopicListenerDestination.java

/**
 * <br>//from   w ww  . ja  v  a 2  s .  co  m
 */
public void sendReplyToTemporaryDestination(Message request) {
    TemporaryTopic replyTopic = null;
    TopicPublisher tempsender = null;
    String temporaryDestinationName = null;
    try {
        if (request.getJMSReplyTo() == null) {
            throw new IllegalStateException("The sender of this message has not entered a JMSReplyTo field - "
                    + "impossible to send reply on temporary destination!!");
        }
        temporaryDestinationName = request.getJMSReplyTo().toString();
        request.setJMSCorrelationID(request.getJMSMessageID());
        logger.debug("JMSCorrelationID was set!!!" + request.getJMSCorrelationID());
        replyTopic = (TemporaryTopic) request.getJMSReplyTo();
        tempsender = topicSession.createPublisher(replyTopic);
        logger.debug("Created a tempsender and sending reply to " + replyTopic);
        tempsender.send(request);
    } catch (JMSException ex) {
        //ignore
        logger.warn("Failed sending reply on temporary destination : " + temporaryDestinationName);
    } finally {
        try {
            if (tempsender != null) {
                tempsender.close();
            }
            if (replyTopic != null) {
                replyTopic.delete();
            }
        } catch (JMSException ex1) {
            //ignore
        }
    }
}

From source file:org.nuxeo.ecm.core.event.jms.JmsEventForwarder.java

protected void produceJMSMessage(SerializableEventBundle message) throws JMSBusNotActiveException {
    InitialContext ctx;/*from w w  w .  j  av a  2s.co m*/
    Topic nuxeoTopic;
    try {
        ctx = new InitialContext();
        nuxeoTopic = (Topic) ctx.lookup(NUXEO_JMS_TOPIC);
    } catch (NamingException e) {
        jmsBusIsActive = false;
        throw new JMSBusNotActiveException(e);
    }

    TopicConnection nuxeoTopicConnection = null;
    TopicSession nuxeoTopicSession = null;
    TopicPublisher nuxeoMessagePublisher = null;
    try {
        TopicConnectionFactory factory = (TopicConnectionFactory) ctx.lookup("TopicConnectionFactory");
        nuxeoTopicConnection = factory.createTopicConnection();
        nuxeoTopicSession = nuxeoTopicConnection.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE);

        ObjectMessage jmsMessage = nuxeoTopicSession.createObjectMessage(message);

        // add Headers for JMS message
        jmsMessage.setStringProperty("BundleEvent", message.getEventBundleName());

        nuxeoMessagePublisher = nuxeoTopicSession.createPublisher(nuxeoTopic);

        nuxeoMessagePublisher.send(jmsMessage);
        log.debug("Event bundle " + message.getEventBundleName() + " forwarded to JMS topic");

    } catch (Exception e) {
        log.error("Error during JMS forwarding", e);
    } finally {
        if (nuxeoTopicSession != null) {
            try {
                if (nuxeoMessagePublisher != null) {
                    nuxeoMessagePublisher.close();
                }
                nuxeoTopicConnection.close();
                nuxeoTopicSession.close();
            } catch (JMSException e) {
                log.error("Error during JMS cleanup", e);
            }
        }
    }
}