Example usage for javax.jms Destination toString

List of usage examples for javax.jms Destination toString

Introduction

In this page you can find the example usage for javax.jms Destination toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:com.fusesource.examples.activemq.SimpleConsumer.java

public static void main(String args[]) {
    Connection connection = null;

    try {//from  w w  w .j a va2 s. co m
        // JNDI lookup of JMS Connection Factory and JMS Destination
        Context context = new InitialContext();
        ConnectionFactory factory = (ConnectionFactory) context.lookup(CONNECTION_FACTORY_NAME);
        Destination destination = (Destination) context.lookup(DESTINATION_NAME);

        connection = factory.createConnection();
        connection.start();

        Session session = connection.createSession(NON_TRANSACTED, Session.AUTO_ACKNOWLEDGE);
        MessageConsumer consumer = session.createConsumer(destination);

        LOG.info("Start consuming messages from " + destination.toString() + " with "
                + MESSAGE_TIMEOUT_MILLISECONDS + "ms timeout");

        // Synchronous message consumer
        int i = 1;
        while (true) {
            Message message = consumer.receive(MESSAGE_TIMEOUT_MILLISECONDS);
            if (message != null) {
                if (message instanceof TextMessage) {
                    String text = ((TextMessage) message).getText();
                    LOG.info("Got " + (i++) + ". message: " + text);
                }
            } else {
                break;
            }
        }

        consumer.close();
        session.close();
    } catch (Throwable t) {
        LOG.error(t);
    } finally {
        // Cleanup code
        // In general, you should always close producers, consumers,
        // sessions, and connections in reverse order of creation.
        // For this simple example, a JMS connection.close will
        // clean up all other resources.
        if (connection != null) {
            try {
                connection.close();
            } catch (JMSException e) {
                LOG.error(e);
            }
        }
    }
}

From source file:com.fusesource.examples.activemq.SimpleProducer.java

public static void main(String args[]) {
    Connection connection = null;

    try {//ww w.  jav  a2s . co m
        // JNDI lookup of JMS Connection Factory and JMS Destination
        Context context = new InitialContext();
        ConnectionFactory factory = (ConnectionFactory) context.lookup(CONNECTION_FACTORY_NAME);
        Destination destination = (Destination) context.lookup(DESTINATION_NAME);

        connection = factory.createConnection();
        connection.start();

        Session session = connection.createSession(NON_TRANSACTED, Session.AUTO_ACKNOWLEDGE);
        MessageProducer producer = session.createProducer(destination);

        producer.setTimeToLive(MESSAGE_TIME_TO_LIVE_MILLISECONDS);

        for (int i = 1; i <= NUM_MESSAGES_TO_BE_SENT; i++) {
            TextMessage message = session.createTextMessage(i + ". message sent");
            LOG.info("Sending to destination: " + destination.toString() + " this text: '" + message.getText());
            producer.send(message);
            Thread.sleep(MESSAGE_DELAY_MILLISECONDS);
        }

        // Cleanup
        producer.close();
        session.close();
    } catch (Throwable t) {
        LOG.error(t);
    } finally {
        // Cleanup code
        // In general, you should always close producers, consumers,
        // sessions, and connections in reverse order of creation.
        // For this simple example, a JMS connection.close will
        // clean up all other resources.
        if (connection != null) {
            try {
                connection.close();
            } catch (JMSException e) {
                LOG.error(e);
            }
        }
    }
}

From source file:org.sample.TimeController.java

@RequestMapping(method = RequestMethod.GET, value = { "/tick" })
public ModelAndView get() throws Exception {
    Connection connection = jmsFactory.createConnection();
    Session jmsSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    SecureRandom srandom = new SecureRandom();
    String rand = new BigInteger(176, srandom).toString(32);
    String q = Long.toString(System.currentTimeMillis()) + "-" + rand;
    Destination destination = jmsSession.createQueue(q);

    Timer timer = new Timer();
    long delay = 1 * 1000;
    timer.schedule(new TickTask(jmsSession, destination), 0, delay);

    ModelAndView mav = new ModelAndView("client");
    mav.addObject("queue", destination.toString());
    return mav;/*w  w  w  .  jav  a2s .com*/
}

From source file:ru.anr.base.tests.TestJmsOperations.java

/**
 * {@inheritDoc}/*from   w ww.jav a 2 s. c o m*/
 */
@Override
public Object receiveAndConvert(Destination destination) {

    Assert.notNull(destination);
    return receiveAndConvert(destination.toString());
}

From source file:ru.anr.base.tests.TestJmsOperations.java

/**
 * {@inheritDoc}//  ww  w.j  a  va2 s.c o  m
 */
@Override
public void convertAndSend(Destination destination, Object message) {

    Assert.notNull(destination);
    convertAndSend(destination.toString(), message);
}

From source file:org.fatal1t.forexapp.spring.api.adapters.SyncListener.java

private void sendMessage(String message, String CorelId, Destination queue)
        throws JmsException, BeansException {
    MessageCreator messageCreator = (javax.jms.Session session1) -> {
        Message nMessage = session1.createTextMessage(message);
        nMessage.setJMSCorrelationID(CorelId);

        return nMessage;
    };/*from   ww  w .ja  v  a  2 s .c  o m*/

    JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
    log.info("Target queue: " + queue.toString());
    log.info("Sending back: " + CorelId + " " + message.substring(0, 10));
    jmsTemplate.send(queue, messageCreator);
}

From source file:com.alliander.osgp.signing.server.infra.messaging.SigningServerRequestMessageListener.java

@Override
public void onMessage(final Message message) {
    try {//from  w w  w.  ja  v  a  2 s  . c  o m
        final ObjectMessage objectMessage = (ObjectMessage) message;
        final Destination replyToQueue = objectMessage.getJMSReplyTo();
        final RequestMessage requestMessage = (RequestMessage) objectMessage.getObject();
        final UnsignedOslpEnvelopeDto unsignedOslpEnvelopeDto = (UnsignedOslpEnvelopeDto) requestMessage
                .getRequest();
        final String correlationUid = objectMessage.getJMSCorrelationID();
        final String deviceIdentification = objectMessage.getStringProperty(Constants.DEVICE_IDENTIFICATION);

        LOGGER.info("Received message of type: {}, for device: {} with correlationId: {} and replyToQueue: {}",
                objectMessage.getJMSType(), deviceIdentification, correlationUid, replyToQueue.toString());

        LOGGER.debug("-----------------------------------------------------------------------------");
        LOGGER.debug("unsignedOslpEnvelopeDto.getCorrelationUid() : {}",
                unsignedOslpEnvelopeDto.getCorrelationUid());
        LOGGER.debug("unsignedOslpEnvelopeDto.getDeviceId() : {}", unsignedOslpEnvelopeDto.getDeviceId());
        LOGGER.debug("unsignedOslpEnvelopeDto.getDomain() : {}", unsignedOslpEnvelopeDto.getDomain());
        LOGGER.debug("unsignedOslpEnvelopeDto.getDomainVersion() : {}",
                unsignedOslpEnvelopeDto.getDomainVersion());
        LOGGER.debug("unsignedOslpEnvelopeDto.getIpAddress() : {}", unsignedOslpEnvelopeDto.getIpAddress());
        LOGGER.debug("unsignedOslpEnvelopeDto.getMessageType() : {}", unsignedOslpEnvelopeDto.getMessageType());
        LOGGER.debug("unsignedOslpEnvelopeDto.getOrganisationIdentification() : {}",
                unsignedOslpEnvelopeDto.getOrganisationIdentification());
        LOGGER.debug("unsignedOslpEnvelopeDto.getPayloadMessage() : {}",
                unsignedOslpEnvelopeDto.getPayloadMessage().toString());
        LOGGER.debug("unsignedOslpEnvelopeDto.getRetryCount() : {}", unsignedOslpEnvelopeDto.getRetryCount());
        LOGGER.debug("unsignedOslpEnvelopeDto.getSequenceNumber() : {}",
                unsignedOslpEnvelopeDto.getSequenceNumber());
        LOGGER.debug("unsignedOslpEnvelopeDto.isScheduled() : {}", unsignedOslpEnvelopeDto.isScheduled());
        LOGGER.debug("-----------------------------------------------------------------------------");

        this.signingService.sign(unsignedOslpEnvelopeDto, correlationUid, deviceIdentification, replyToQueue);

    } catch (final JMSException ex) {
        LOGGER.error("Exception: {} ", ex.getMessage(), ex);
    }
}

From source file:nl.nn.adapterframework.extensions.ifsa.jms.PullingIfsaProviderListener.java

/**
 * Extracts ID-string from message obtained from {@link #getRawMessage(Map)}. 
 * Puts also the following parameters  in the threadContext:
 * <ul>//from ww  w . j a  v a  2 s  . co m
 *   <li>id</li>
 *   <li>cid</li>
 *   <li>timestamp</li>
 *   <li>replyTo</li>
 *   <li>messageText</li>
 *   <li>fullIfsaServiceName</li>
 *   <li>ifsaServiceName</li>
 *   <li>ifsaGroup</li>
 *   <li>ifsaOccurrence</li>
 *   <li>ifsaVersion</li>
 * </ul>
 * @return ID-string of message for adapter.
 */
public String getIdFromRawMessage(Object rawMessage, Map threadContext) throws ListenerException {

    IFSAMessage message = null;

    if (rawMessage instanceof IMessageWrapper) {
        return getIdFromWrapper((IMessageWrapper) rawMessage, threadContext);
    }

    try {
        message = (IFSAMessage) rawMessage;
    } catch (ClassCastException e) {
        log.error(getLogPrefix() + "message received was not of type IFSAMessage, but ["
                + rawMessage.getClass().getName() + "]", e);
        return null;
    }
    String mode = "unknown";
    String id = "unset";
    String cid = "unset";
    Date tsSent = null;
    Destination replyTo = null;
    String messageText = null;
    String fullIfsaServiceName = null;
    IFSAServiceName requestedService = null;
    String ifsaServiceName = null, ifsaGroup = null, ifsaOccurrence = null, ifsaVersion = null;
    try {
        if (message.getJMSDeliveryMode() == DeliveryMode.NON_PERSISTENT) {
            mode = "NON_PERSISTENT";
        } else if (message.getJMSDeliveryMode() == DeliveryMode.PERSISTENT) {
            mode = "PERSISTENT";
        }
    } catch (JMSException ignore) {
    }
    // --------------------------
    // retrieve MessageID
    // --------------------------
    try {
        id = message.getJMSMessageID();
    } catch (JMSException ignore) {
    }
    // --------------------------
    // retrieve CorrelationID
    // --------------------------
    try {
        cid = message.getJMSCorrelationID();
        if (cid == null) {
            cid = id;
            log.debug("Setting correlation ID to MessageId");
        }
    } catch (JMSException ignore) {
    }
    // --------------------------
    // retrieve TimeStamp
    // --------------------------
    try {
        long lTimeStamp = message.getJMSTimestamp();
        tsSent = new Date(lTimeStamp);

    } catch (JMSException ignore) {
    }
    // --------------------------
    // retrieve ReplyTo address
    // --------------------------
    try {
        replyTo = message.getJMSReplyTo();

    } catch (JMSException ignore) {
    }
    // --------------------------
    // retrieve message text
    // --------------------------
    try {
        messageText = ((TextMessage) message).getText();
    } catch (Throwable ignore) {
    }
    // --------------------------
    // retrieve ifsaServiceDestination
    // --------------------------
    try {
        fullIfsaServiceName = message.getServiceString();
        requestedService = message.getService();

        ifsaServiceName = requestedService.getServiceName();
        ifsaGroup = requestedService.getServiceGroup();
        ifsaOccurrence = requestedService.getServiceOccurance();
        ifsaVersion = requestedService.getServiceVersion();

    } catch (JMSException e) {
        log.error(getLogPrefix() + "got error getting serviceparameter", e);
    }

    if (log.isDebugEnabled()) {
        log.debug(getLogPrefix() + "got message for [" + fullIfsaServiceName + "] with JMSDeliveryMode=[" + mode
                + "] \n  JMSMessageID=[" + id + "] \n  JMSCorrelationID=[" + cid + "] \n  ifsaServiceName=["
                + ifsaServiceName + "] \n  ifsaGroup=[" + ifsaGroup + "] \n  ifsaOccurrence=[" + ifsaOccurrence
                + "] \n  ifsaVersion=[" + ifsaVersion + "] \n  Timestamp Sent=[" + DateUtils.format(tsSent)
                + "] \n  ReplyTo=[" + ((replyTo == null) ? "none" : replyTo.toString())
                + "] \n  MessageHeaders=[" + displayHeaders(message) + "\n" + "] \n  Message=["
                + message.toString() + "\n]");

    }

    PipeLineSessionBase.setListenerParameters(threadContext, id, cid, null, tsSent);
    threadContext.put("timestamp", tsSent);
    threadContext.put("replyTo", ((replyTo == null) ? "none" : replyTo.toString()));
    threadContext.put("messageText", messageText);
    threadContext.put("fullIfsaServiceName", fullIfsaServiceName);
    threadContext.put("ifsaServiceName", ifsaServiceName);
    threadContext.put("ifsaGroup", ifsaGroup);
    threadContext.put("ifsaOccurrence", ifsaOccurrence);
    threadContext.put("ifsaVersion", ifsaVersion);

    Map udz = (Map) message.getIncomingUDZObject();
    if (udz != null) {
        String contextDump = "ifsaUDZ:";
        for (Iterator it = udz.keySet().iterator(); it.hasNext();) {
            String key = (String) it.next();
            String value = (String) udz.get(key);
            contextDump = contextDump + "\n " + key + "=[" + value + "]";
            threadContext.put(key, value);
        }
        if (log.isDebugEnabled()) {
            log.debug(getLogPrefix() + contextDump);
        }
    }

    return id;
}

From source file:nl.nn.adapterframework.extensions.ifsa.jms.PushingIfsaProviderListener.java

/**
 * Extracts ID-string from message obtained from {@link #getRawMessage(Map)}. 
 * Puts also the following parameters  in the threadContext:
 * <ul>/*w ww.  ja  va 2 s  .  c o  m*/
 *   <li>id</li>
 *   <li>cid</li>
 *   <li>timestamp</li>
 *   <li>replyTo</li>
 *   <li>messageText</li>
 *   <li>fullIfsaServiceName</li>
 *   <li>ifsaServiceName</li>
 *   <li>ifsaGroup</li>
 *   <li>ifsaOccurrence</li>
 *   <li>ifsaVersion</li>
 *   <li>ifsaBifName</li>
 *   <li>ifsaBtcData</li>
 * </ul>
 * @return ID-string of message for adapter.
 */
public String getIdFromRawMessage(Object rawMessage, Map threadContext) throws ListenerException {

    IFSAMessage message = null;

    if (rawMessage instanceof IMessageWrapper) {
        return getIdFromWrapper((IMessageWrapper) rawMessage, threadContext);
    }

    try {
        message = (IFSAMessage) rawMessage;
    } catch (ClassCastException e) {
        log.error(getLogPrefix() + "message received was not of type IFSAMessage, but ["
                + rawMessage.getClass().getName() + "]", e);
        return null;
    }
    String mode = "unknown";
    String id = "unset";
    String cid = "unset";
    Date tsSent = null;
    Destination replyTo = null;
    String messageText = null;
    String fullIfsaServiceName = null;
    IFSAServiceName requestedService = null;
    String ifsaServiceName = null, ifsaGroup = null, ifsaOccurrence = null, ifsaVersion = null;
    try {
        if (message.getJMSDeliveryMode() == DeliveryMode.NON_PERSISTENT) {
            mode = "NON_PERSISTENT";
        } else if (message.getJMSDeliveryMode() == DeliveryMode.PERSISTENT) {
            mode = "PERSISTENT";
        }
    } catch (JMSException ignore) {
    }
    // --------------------------
    // retrieve MessageID
    // --------------------------
    try {
        id = message.getJMSMessageID();
    } catch (JMSException ignore) {
    }
    // --------------------------
    // retrieve CorrelationID
    // --------------------------
    try {
        cid = message.getJMSCorrelationID();
    } catch (JMSException ignore) {
    }
    // --------------------------
    // retrieve TimeStamp
    // --------------------------
    try {
        long lTimeStamp = message.getJMSTimestamp();
        tsSent = new Date(lTimeStamp);

    } catch (JMSException ignore) {
    }
    // --------------------------
    // retrieve ReplyTo address
    // --------------------------
    try {
        replyTo = message.getJMSReplyTo();

    } catch (JMSException ignore) {
    }
    // --------------------------
    // retrieve message text
    // --------------------------
    try {
        messageText = ((TextMessage) message).getText();
    } catch (Throwable ignore) {
    }
    // --------------------------
    // retrieve ifsaServiceDestination
    // --------------------------
    try {
        fullIfsaServiceName = message.getServiceString();
        requestedService = message.getService();

        ifsaServiceName = requestedService.getServiceName();
        ifsaGroup = requestedService.getServiceGroup();
        ifsaOccurrence = requestedService.getServiceOccurance();
        ifsaVersion = requestedService.getServiceVersion();

    } catch (JMSException e) {
        log.error(getLogPrefix() + "got error getting serviceparameter", e);
    }

    String BIFname = null;
    try {
        BIFname = message.getBifName();
        if (StringUtils.isNotEmpty(BIFname)) {
            threadContext.put(THREAD_CONTEXT_BIFNAME_KEY, BIFname);
        }
    } catch (JMSException e) {
        log.error(getLogPrefix() + "got error getting BIFname", e);
    }
    byte btcData[] = null;
    try {
        btcData = message.getBtcData();
    } catch (JMSException e) {
        log.error(getLogPrefix() + "got error getting btcData", e);
    }

    if (log.isDebugEnabled()) {
        log.debug(getLogPrefix() + "got message for [" + fullIfsaServiceName + "] with JMSDeliveryMode=[" + mode
                + "] \n  JMSMessageID=[" + id + "] \n  JMSCorrelationID=[" + cid + "] \n  BIFname=[" + BIFname
                + "] \n  ifsaServiceName=[" + ifsaServiceName + "] \n  ifsaGroup=[" + ifsaGroup
                + "] \n  ifsaOccurrence=[" + ifsaOccurrence + "] \n  ifsaVersion=[" + ifsaVersion
                + "] \n  Timestamp Sent=[" + DateUtils.format(tsSent) + "] \n  ReplyTo=["
                + ((replyTo == null) ? "none" : replyTo.toString()) + "] \n  MessageHeaders=["
                + displayHeaders(message) + "\n"
                //               + "] \n  btcData=["+ btcData
                + "] \n  Message=[" + message.toString() + "\n]");

    }
    //      if (cid == null) {
    //         if (StringUtils.isNotEmpty(BIFname)) {
    //            cid = BIFname;
    //            if (log.isDebugEnabled()) log.debug("Setting correlation ID to BIFname ["+cid+"]");
    //         } else {
    //            cid = id;
    //            if (log.isDebugEnabled()) log.debug("Setting correlation ID to MessageId ["+cid+"]");
    //         }
    //      }

    PipeLineSessionBase.setListenerParameters(threadContext, id, BIFname, null, tsSent);
    threadContext.put("timestamp", tsSent);
    threadContext.put("replyTo", ((replyTo == null) ? "none" : replyTo.toString()));
    threadContext.put("messageText", messageText);
    threadContext.put("fullIfsaServiceName", fullIfsaServiceName);
    threadContext.put("ifsaServiceName", ifsaServiceName);
    threadContext.put("ifsaGroup", ifsaGroup);
    threadContext.put("ifsaOccurrence", ifsaOccurrence);
    threadContext.put("ifsaVersion", ifsaVersion);
    threadContext.put("ifsaBifName", BIFname);
    threadContext.put("ifsaBtcData", btcData);

    Map udz = (Map) message.getIncomingUDZObject();
    if (udz != null) {
        String contextDump = "ifsaUDZ:";
        for (Iterator it = udz.keySet().iterator(); it.hasNext();) {
            String key = (String) it.next();
            String value = (String) udz.get(key);
            contextDump = contextDump + "\n " + key + "=[" + value + "]";
            threadContext.put(key, value);
        }
        if (log.isDebugEnabled()) {
            log.debug(getLogPrefix() + contextDump);
        }
    }

    return BIFname;
}

From source file:nl.nn.adapterframework.jms.JmsListenerBase.java

protected String retrieveIdFromMessage(Message message, Map threadContext) throws ListenerException {
    String cid = "unset";
    String mode = "unknown";
    String id = "unset";
    Date tsSent = null;//from   w  w  w.j a  v a 2 s. c  o m
    Destination replyTo = null;
    try {
        mode = deliveryModeToString(message.getJMSDeliveryMode());
    } catch (JMSException ignore) {
        log.debug("ignoring JMSException in getJMSDeliveryMode()", ignore);
    }
    // --------------------------
    // retrieve MessageID
    // --------------------------
    try {
        id = message.getJMSMessageID();
    } catch (JMSException ignore) {
        log.debug("ignoring JMSException in getJMSMessageID()", ignore);
    }
    // --------------------------
    // retrieve CorrelationID
    // --------------------------
    try {
        if (isForceMessageIdAsCorrelationId()) {
            if (log.isDebugEnabled())
                log.debug("forcing the messageID to be the correlationID");
            cid = id;
        } else {
            cid = message.getJMSCorrelationID();
            if (cid == null) {
                cid = id;
                log.debug("Setting correlation ID to MessageId");
            }
        }
    } catch (JMSException ignore) {
        log.debug("ignoring JMSException in getJMSCorrelationID()", ignore);
    }
    // --------------------------
    // retrieve TimeStamp
    // --------------------------
    try {
        long lTimeStamp = message.getJMSTimestamp();
        tsSent = new Date(lTimeStamp);

    } catch (JMSException ignore) {
        log.debug("ignoring JMSException in getJMSTimestamp()", ignore);
    }
    // --------------------------
    // retrieve ReplyTo address
    // --------------------------
    try {
        replyTo = message.getJMSReplyTo();

    } catch (JMSException ignore) {
        log.debug("ignoring JMSException in getJMSReplyTo()", ignore);
    }

    if (log.isDebugEnabled()) {
        log.debug(getLogPrefix() + "listener on [" + getDestinationName()
                + "] got message with JMSDeliveryMode=[" + mode + "] \n  JMSMessageID=[" + id
                + "] \n  JMSCorrelationID=[" + cid + "] \n  Timestamp Sent=[" + DateUtils.format(tsSent)
                + "] \n  ReplyTo=[" + ((replyTo == null) ? "none" : replyTo.toString()) + "] \n Message=["
                + message.toString() + "]");
    }
    PipeLineSessionBase.setListenerParameters(threadContext, id, cid, null, tsSent);
    threadContext.put("timestamp", tsSent);
    threadContext.put("replyTo", replyTo);
    try {
        if (getAckMode() == Session.CLIENT_ACKNOWLEDGE) {
            message.acknowledge();
            log.debug("Listener on [" + getDestinationName() + "] acknowledged message");
        }
    } catch (JMSException e) {
        log.error("Warning in ack", e);
    }
    return cid;
}