Example usage for javax.jms Message getJMSMessageID

List of usage examples for javax.jms Message getJMSMessageID

Introduction

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

Prototype


String getJMSMessageID() throws JMSException;

Source Link

Document

Gets the message ID.

Usage

From source file:org.codehaus.stomp.jms.StompSession.java

public void sendToJms(StompFrame command)
        throws JMSException, ProtocolException, NamingException, UnsupportedEncodingException {
    Map headers = command.getHeaders();
    String destinationName = (String) headers.remove(Stomp.Headers.Send.DESTINATION);
    Message message = convertFrame(command);
    Destination destination = convertDestination(destinationName, false);

    int deliveryMode = getDeliveryMode(headers);
    int priority = getPriority(headers);
    long timeToLive = getTimeToLive(headers);

    producer.send(destination, message, deliveryMode, priority, timeToLive);
    log.debug("Sent to HQ: " + message.getJMSMessageID());
}

From source file:org.codehaus.stomp.jms.StompSession.java

protected void copyStandardHeadersFromMessageToFrame(Message message, StompFrame command) throws JMSException {
    final Map headers = command.getHeaders();
    headers.put(Stomp.Headers.Message.DESTINATION, convertDestination(message.getJMSDestination()));
    headers.put(Stomp.Headers.Message.MESSAGE_ID, message.getJMSMessageID());

    if (message.getJMSCorrelationID() != null) {
        headers.put(Stomp.Headers.Message.CORRELATION_ID, message.getJMSCorrelationID());
    }//  www.  ja  v  a 2  s  .c  o  m
    headers.put(Stomp.Headers.Message.EXPIRATION_TIME, "" + message.getJMSExpiration());

    if (message.getJMSRedelivered()) {
        headers.put(Stomp.Headers.Message.REDELIVERED, "true");
    }
    headers.put(Stomp.Headers.Message.PRORITY, "" + message.getJMSPriority());

    if (message.getJMSReplyTo() != null) {
        headers.put(Stomp.Headers.Message.REPLY_TO, convertDestination(message.getJMSReplyTo()));
    }
    headers.put(Stomp.Headers.Message.TIMESTAMP, "" + message.getJMSTimestamp());

    if (message.getJMSType() != null) {
        headers.put(Stomp.Headers.Message.TYPE, message.getJMSType());
    }

    // now lets add all the message headers
    Enumeration names = message.getPropertyNames();
    while (names.hasMoreElements()) {
        String name = (String) names.nextElement();
        Object value = message.getObjectProperty(name);
        headers.put(name, value);
    }
}

From source file:org.codehaus.stomp.jms.StompSubscription.java

public void onMessage(Message message) {

    String destinationName = (String) headers.get(Stomp.Headers.Subscribe.DESTINATION);
    try {//from w  w w .j a  va 2  s .  c o  m
        log.debug("Received from HQ: " + message.getJMSMessageID());
        log.debug("received: " + destinationName + " for: " + message.getObjectProperty("messagereplyto"));
    } catch (JMSException e) {
        log.warn("received: " + destinationName + " with trouble getting the message properties");
    }
    if (message != null) {
        log.debug("Locking session to send a message");
        // Lock the session so that the connection cannot be started before
        // the acknowledge is done
        synchronized (session) {
            // Send the message to the server
            log.debug("Sending message: " + session);
            try {
                session.sendToStomp(message, subscriptionId);
                try {
                    session.wait();
                } catch (InterruptedException e) {
                    log.error("Could not wait to be woken", e);
                }
                // Acknowledge the message for this connection as we know
                // the server has received it now
                try {
                    log.debug("Acking message: " + message.getJMSMessageID());
                    message.acknowledge();
                    log.debug("Acked message: " + message.getJMSMessageID());
                } catch (JMSException e) {
                    log.error("Could not acknowledge the message: " + e, e);
                }
            } catch (IOException e) {
                log.warn("Could not send to stomp: " + e, e);
                try {
                    session.recover();
                } catch (JMSException e1) {
                    log.fatal("Could not recover the session, possible lost message: " + e, e);
                }
            } catch (JMSException e) {
                log.warn("Could not convert message to send to stomp: " + e, e);
                try {
                    session.recover();
                } catch (JMSException e1) {
                    log.fatal("Could not recover the session, possible lost message: " + e, e);
                }
            }
        }
    }
}

From source file:org.eurekastreams.server.search.indexing.MDBSearchController.java

/**
 * Log that we received the message.//w w w  . ja v a  2s. c om
 * 
 * @param inMessage
 *            the message captured
 */
public void onMessage(final Message inMessage) {
    if (logger.isDebugEnabled()) {
        try {
            logger.debug("Picked up message with JMS Message ID: " + inMessage.getJMSMessageID());
        } catch (JMSException e) {
            // do nothing
            int i = 0;
            i++;
        }
    }
    super.onMessage(inMessage);
}

From source file:org.exist.messaging.JmsMessageSender.java

/**
 * Create messaging results report//from  w  ww.  ja v  a 2  s  . c  o m
 * 
 * TODO shared code
 */
private NodeImpl createReport(Message message, XQueryContext xqcontext) {

    MemTreeBuilder builder = xqcontext.getDocumentBuilder();

    // start root element
    int nodeNr = builder.startElement("", "JMS", "JMS", null);

    try {
        String txt = message.getJMSMessageID();
        if (txt != null) {
            builder.startElement("", "MessageID", "MessageID", null);
            builder.characters(message.getJMSMessageID());
            builder.endElement();
        }
    } catch (JMSException ex) {
        LOG.error(ex);
    }

    try {
        String txt = message.getJMSCorrelationID();
        if (txt != null) {
            builder.startElement("", "CorrelationID", "CorrelationID", null);
            builder.characters(message.getJMSCorrelationID());
            builder.endElement();
        }
    } catch (JMSException ex) {
        LOG.error(ex);
    }

    try {
        String txt = message.getJMSType();
        if (txt != null) {
            builder.startElement("", "Type", "Type", null);
            builder.characters(message.getJMSType());
            builder.endElement();
        }
    } catch (JMSException ex) {
        LOG.error(ex);
    }

    // finish root element
    builder.endElement();

    // return result
    return ((DocumentImpl) builder.getDocument()).getNode(nodeNr);

}

From source file:org.exist.replication.jms.obsolete.FileSystemListener.java

@Override
public void onMessage(Message message) {
    try {/*from  w  w w.  j ava  2  s.c om*/
        LOG.info("JMSMessageID=" + message.getJMSMessageID());

        StringBuilder sb = new StringBuilder();

        // Write properties
        Enumeration names = message.getPropertyNames();
        for (Enumeration<?> e = names; e.hasMoreElements();) {
            String key = (String) e.nextElement();
            sb.append("'" + key + "='" + message.getStringProperty(key) + "' ");
        }
        LOG.info(sb.toString());

        // Handle message
        if (message instanceof TextMessage) {
            LOG.info(((TextMessage) message).getText());

        } else if (message instanceof BytesMessage) {

            BytesMessage bm = (BytesMessage) message;

            eXistMessage em = convertMessage(bm);

            switch (em.getResourceType()) {
            case DOCUMENT:
                handleDocument(em);
                break;
            case COLLECTION:
                handleCollection(em);
                break;
            default:
                LOG.error("Unknown resource type");
                break;
            }

        }

    } catch (JMSException ex) {
        LOG.error(ex);
    }

}

From source file:org.fcrepo.indexer.IndexerGroup.java

/**
 * Handle a JMS message representing an object update or deletion event.
 **///from   w w w. j  a v  a2s.com
@Override
public void onMessage(final Message message) {
    try {
        LOGGER.debug("Received message: {}", message.getJMSMessageID());
    } catch (final JMSException e) {
        LOGGER.error("Received unintelligible message: {}", e);
        propagate(e);
    }
    try {
        // get id and eventType from message
        final String eventType = message.getStringProperty(EVENT_TYPE_HEADER_NAME);
        final String id = message.getStringProperty(IDENTIFIER_HEADER_NAME);
        String baseURL = message.getStringProperty(BASE_URL_HEADER_NAME);

        LOGGER.debug("Discovered id: {} in message.", id);
        LOGGER.debug("Discovered event type: {} in message.", eventType);
        LOGGER.debug("Discovered baseURL: {} in message.", baseURL);
        LOGGER.debug("Discovered properties: {} in message.",
                message.getStringProperty(PROPERTIES_HEADER_NAME));

        // Trim trailing '/'
        while (!Strings.isNullOrEmpty(baseURL) && baseURL.endsWith("/")) {
            baseURL = baseURL.substring(0, baseURL.length() - 1);
        }

        index(new URI(baseURL + id), eventType);
    } catch (final URISyntaxException e) {
        LOGGER.error("Error creating URI", e);
    } catch (final JMSException e) {
        LOGGER.error("Error processing JMS event!", e);
    }
}

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

/**
 * <br>//from  w ww. j a va2s  .  c  o 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.jbpm.bpel.integration.jms.RequestListener.java

public static String messageToString(Message message) throws JMSException {
    StringBuffer result = new StringBuffer();
    // ID & destination
    result.append("id=").append(message.getJMSMessageID()).append(", destination=")
            .append(message.getJMSDestination());
    // replyTo & correlationID
    Destination replyTo = message.getJMSReplyTo();
    if (replyTo != null) {
        result.append(", replyTo=").append(replyTo).append(", correlationId=")
                .append(message.getJMSCorrelationID());
    }//from  w ww  .  j av  a2  s . co m
    // properties
    Enumeration propertyNames = message.getPropertyNames();
    while (propertyNames.hasMoreElements()) {
        String propertyName = (String) propertyNames.nextElement();
        result.append(", ").append(propertyName).append('=').append(message.getObjectProperty(propertyName));
    }
    return result.toString();
}

From source file:org.jbpm.ejb.CommandListenerBean.java

public void onMessage(Message message) {
    try {/*from w  w  w.j  a  va 2 s.c  o  m*/
        // extract command from message
        Command command = extractCommand(message);
        // a null return value means the message did not carry a valid command
        // warnings were logged already; just swallow the message and return 
        if (command == null)
            return;

        // execute command via local command executor bean
        Object result;
        try {
            if (log.isDebugEnabled()) {
                log.debug("executing " + command);
            }
            result = commandService.execute(command);

            if (log.isTraceEnabled()) {
                log.trace(command + " completed successfully, committing");
            }
        } catch (RuntimeException e) {
            // if this is a locking exception, keep it quiet
            if (DbPersistenceService.isLockingException(e)) {
                StaleObjectLogConfigurer.getStaleObjectExceptionsLog()
                        .error(message + " failed to execute " + command, e);
            } else {
                log.error(message + " failed to execute " + command, e);
            }
            // MDBs are not supposed to throw exceptions
            messageDrivenContext.setRollbackOnly();
            return;
        }

        // send a response back if a "reply to" destination is set
        Destination replyTo;
        if (jmsConnectionFactory != null && (replyTo = message.getJMSReplyTo()) != null
                && (result instanceof Serializable || result == null)) {
            sendResult((Serializable) result, replyTo, message.getJMSMessageID());
        }
    } catch (JMSException e) {
        messageDrivenContext.setRollbackOnly();
        log.error("failed to process message " + message, e);
    }
}