List of usage examples for javax.jms Message getJMSCorrelationID
String getJMSCorrelationID() throws JMSException;
From source file:com.jmstoolkit.pipeline.plugin.Echo.java
@Override public final void onMessage(final Message inMessage) { try {// w w w.java 2 s. c o m if (inMessage instanceof TextMessage) { getJmsTemplate().convertAndSend((Object) ((TextMessage) inMessage).getText(), new BasicMessageProcessor(inMessage.getJMSCorrelationID())); } else { getJmsTemplate().convertAndSend((Object) "Non-text message received by Echo", new BasicMessageProcessor(inMessage.getJMSCorrelationID())); } this.operationCount++; } catch (JMSException ex) { LOGGER.log(Level.SEVERE, "Echo had JMS failure onMessage!", ex); } }
From source file:org.logicblaze.lingo.jms.impl.MultiplexingRequestor.java
public void request(Destination destination, Message message, ReplyHandler handler, long timeout) throws JMSException { String correlationID = message.getJMSCorrelationID(); if (correlationID == null) { correlationID = createCorrelationID(); message.setJMSCorrelationID(correlationID); }/*from www. j a v a 2s. c om*/ synchronized (requestMap) { Object currentHandler = requestMap.get(correlationID); if (currentHandler instanceof AsyncReplyHandler) { AsyncReplyHandler remoteObjectHandler = (AsyncReplyHandler) currentHandler; remoteObjectHandler.setParent(handler); } else { requestMap.put(correlationID, handler, timeout); } } populateHeaders(message); send(destination, message); }
From source file:org.apache.camel.component.jms.reply.ReplyManagerSupport.java
public void onMessage(Message message) { String correlationID = null;// w w w. j av a 2 s . c o m try { correlationID = message.getJMSCorrelationID(); } catch (JMSException e) { // ignore } if (correlationID == null) { log.warn("Ignoring message with no correlationID: " + message); return; } if (log.isDebugEnabled()) { log.debug("Received reply message with correlationID: " + correlationID + " -> " + message); } // handle the reply message handleReplyMessage(correlationID, message); }
From source file:com.fusesource.forge.jmstest.tests.AsyncProducer.java
public void onMessage(Message msg) { try {/*from ww w. j ava 2s .com*/ String recCorrId = msg.getJMSCorrelationID(); synchronized (corrId) { if (recCorrId.equals(corrId)) { receivedResponse = true; String servedBy = msg.getStringProperty("ServedBy"); LOG.debug("Served By : " + servedBy); String brokerStamp = msg.getStringProperty("BrokerStamp"); LOG.debug("BrokerStamp : " + brokerStamp); corrId.notifyAll(); } } } catch (JMSException jme) { LOG.error(jme); } }
From source file:org.apache.camel.component.jms.EndpointMessageListener.java
/** * Strategy to determine which correlation id to use among <tt>JMSMessageID</tt> and <tt>JMSCorrelationID</tt>. * * @param message the JMS message/* w ww. java 2 s . c o m*/ * @return the correlation id to use * @throws JMSException can be thrown */ protected String determineCorrelationId(final Message message) throws JMSException { final String messageId = message.getJMSMessageID(); final String correlationId = message.getJMSCorrelationID(); if (endpoint.getConfiguration().isUseMessageIDAsCorrelationID()) { return messageId; } else if (ObjectHelper.isEmpty(correlationId)) { // correlation id is empty so fallback to message id return messageId; } else { return correlationId; } }
From source file:com.jmstoolkit.beans.MessageTableModel.java
/** * * @param message//from w w w . j av a 2s . c o m */ @Override public void onMessage(Message message) { LOGGER.log(Level.FINE, "Message Received"); messagesReceived++; try { MessageTableRecord qRecord = new MessageTableRecord(); qRecord.setJMSCorrelationID(message.getJMSCorrelationID()); qRecord.setJMSDeliveryMode(message.getJMSDeliveryMode()); qRecord.setJMSExpiration(message.getJMSExpiration()); qRecord.setJMSMessageID(message.getJMSMessageID()); qRecord.setJMSTimestamp(message.getJMSTimestamp()); qRecord.setJMSType(message.getJMSType()); qRecord.setJMSDestination(message.getJMSDestination()); qRecord.setJMSCorrelationIDAsBytes(message.getJMSCorrelationIDAsBytes()); qRecord.setJMSPriority(message.getJMSPriority()); qRecord.setJMSType(message.getJMSType()); qRecord.setJMSReplyTo(message.getJMSReplyTo()); qRecord.setJMSRedelivered(message.getJMSRedelivered()); Enumeration pEnumerator = message.getPropertyNames(); Properties props = new Properties(); while (pEnumerator.hasMoreElements()) { String pElement = (String) pEnumerator.nextElement(); props.put(pElement, message.getStringProperty(pElement)); } qRecord.setProperties(props); if (message instanceof TextMessage) { qRecord.setText(((TextMessage) message).getText()); } if (message instanceof ObjectMessage) { qRecord.setObject(((ObjectMessage) message).getObject()); } List newData = data; newData.add(qRecord); this.setData(newData); } catch (JMSException e) { LOGGER.log(Level.WARNING, "JMS problem", e); } }
From source file:org.apache.axis2.transport.jms.LogAspect.java
@Before("(call(void javax.jms.MessageProducer.send(javax.jms.Message)) ||" + " call(void javax.jms.TopicPublisher.publish(javax.jms.Message))) && args(message)") public void beforeSend(Message message) { try {/*from w ww . j a v a 2s. c o m*/ OutputStream out = LogManager.INSTANCE.createLog("jms"); try { PrintWriter pw = new PrintWriter(new OutputStreamWriter(out), false); pw.println("Type: " + message.getClass().getName()); pw.println("JMS message ID: " + message.getJMSMessageID()); pw.println("JMS correlation ID: " + message.getJMSCorrelationID()); pw.println("JMS reply to: " + message.getJMSReplyTo()); for (Enumeration<?> e = message.getPropertyNames(); e.hasMoreElements();) { String name = (String) e.nextElement(); pw.print(name); pw.print(": "); pw.println(message.getStringProperty(name)); } pw.println(); pw.flush(); if (message instanceof BytesMessage) { BytesMessage bytesMessage = (BytesMessage) message; bytesMessage.reset(); IOUtils.copy(new BytesMessageInputStream(bytesMessage), out); } else if (message instanceof TextMessage) { pw.print(((TextMessage) message).getText()); pw.flush(); } } finally { out.close(); } } catch (Throwable ex) { log.error("Failed to dump JMS message", ex); } }
From source file:org.springframework.jms.support.SimpleJmsHeaderMapper.java
@Override public MessageHeaders toHeaders(javax.jms.Message jmsMessage) { Map<String, Object> headers = new HashMap<String, Object>(); try {// w w w .j a v a2 s . c o m try { String correlationId = jmsMessage.getJMSCorrelationID(); if (correlationId != null) { headers.put(JmsHeaders.CORRELATION_ID, correlationId); } } catch (Exception ex) { logger.info("failed to read JMSCorrelationID property, skipping", ex); } try { Destination destination = jmsMessage.getJMSDestination(); if (destination != null) { headers.put(JmsHeaders.DESTINATION, destination); } } catch (Exception ex) { logger.info("failed to read JMSDestination property, skipping", ex); } try { int deliveryMode = jmsMessage.getJMSDeliveryMode(); headers.put(JmsHeaders.DELIVERY_MODE, deliveryMode); } catch (Exception ex) { logger.info("failed to read JMSDeliveryMode property, skipping", ex); } try { long expiration = jmsMessage.getJMSExpiration(); headers.put(JmsHeaders.EXPIRATION, expiration); } catch (Exception ex) { logger.info("failed to read JMSExpiration property, skipping", ex); } try { String messageId = jmsMessage.getJMSMessageID(); if (messageId != null) { headers.put(JmsHeaders.MESSAGE_ID, messageId); } } catch (Exception ex) { logger.info("failed to read JMSMessageID property, skipping", ex); } try { headers.put(JmsHeaders.PRIORITY, jmsMessage.getJMSPriority()); } catch (Exception ex) { logger.info("failed to read JMSPriority property, skipping", ex); } try { Destination replyTo = jmsMessage.getJMSReplyTo(); if (replyTo != null) { headers.put(JmsHeaders.REPLY_TO, replyTo); } } catch (Exception ex) { logger.info("failed to read JMSReplyTo property, skipping", ex); } try { headers.put(JmsHeaders.REDELIVERED, jmsMessage.getJMSRedelivered()); } catch (Exception ex) { logger.info("failed to read JMSRedelivered property, skipping", ex); } try { String type = jmsMessage.getJMSType(); if (type != null) { headers.put(JmsHeaders.TYPE, type); } } catch (Exception ex) { logger.info("failed to read JMSType property, skipping", ex); } try { headers.put(JmsHeaders.TIMESTAMP, jmsMessage.getJMSTimestamp()); } catch (Exception ex) { logger.info("failed to read JMSTimestamp property, skipping", ex); } Enumeration<?> jmsPropertyNames = jmsMessage.getPropertyNames(); if (jmsPropertyNames != null) { while (jmsPropertyNames.hasMoreElements()) { String propertyName = jmsPropertyNames.nextElement().toString(); try { String headerName = this.toHeaderName(propertyName); headers.put(headerName, jmsMessage.getObjectProperty(propertyName)); } catch (Exception ex) { if (logger.isWarnEnabled()) { logger.warn("Error occurred while mapping JMS property '" + propertyName + "' to Message header", ex); } } } } } catch (JMSException ex) { if (logger.isWarnEnabled()) { logger.warn("Error occurred while mapping from JMS properties to MessageHeaders", ex); } } return new MessageHeaders(headers); }
From source file:org.springframework.jms.support.converter.SimpleJmsHeaderMapper.java
@Override public Map<String, Object> toHeaders(javax.jms.Message jmsMessage) { Map<String, Object> headers = new HashMap<String, Object>(); try {/* w ww . ja v a 2 s. co m*/ try { String correlationId = jmsMessage.getJMSCorrelationID(); if (correlationId != null) { headers.put(JmsHeaders.CORRELATION_ID, correlationId); } } catch (Exception e) { logger.info("failed to read JMSCorrelationID property, skipping", e); } try { Destination destination = jmsMessage.getJMSDestination(); if (destination != null) { headers.put(JmsHeaders.DESTINATION, destination); } } catch (Exception e) { logger.info("failed to read JMSDestination property, skipping", e); } try { int deliveryMode = jmsMessage.getJMSDeliveryMode(); headers.put(JmsHeaders.DELIVERY_MODE, deliveryMode); } catch (Exception e) { logger.info("failed to read JMSDeliveryMode property, skipping", e); } try { long expiration = jmsMessage.getJMSExpiration(); headers.put(JmsHeaders.EXPIRATION, expiration); } catch (Exception e) { logger.info("failed to read JMSExpiration property, skipping", e); } try { String messageId = jmsMessage.getJMSMessageID(); if (messageId != null) { headers.put(JmsHeaders.MESSAGE_ID, messageId); } } catch (Exception e) { logger.info("failed to read JMSMessageID property, skipping", e); } try { headers.put(JmsHeaders.PRIORITY, jmsMessage.getJMSPriority()); } catch (Exception e) { logger.info("failed to read JMSPriority property, skipping", e); } try { Destination replyTo = jmsMessage.getJMSReplyTo(); if (replyTo != null) { headers.put(JmsHeaders.REPLY_TO, replyTo); } } catch (Exception e) { logger.info("failed to read JMSReplyTo property, skipping", e); } try { headers.put(JmsHeaders.REDELIVERED, jmsMessage.getJMSRedelivered()); } catch (Exception e) { logger.info("failed to read JMSRedelivered property, skipping", e); } try { String type = jmsMessage.getJMSType(); if (type != null) { headers.put(JmsHeaders.TYPE, type); } } catch (Exception e) { logger.info("failed to read JMSType property, skipping", e); } try { headers.put(JmsHeaders.TIMESTAMP, jmsMessage.getJMSTimestamp()); } catch (Exception e) { logger.info("failed to read JMSTimestamp property, skipping", e); } Enumeration<?> jmsPropertyNames = jmsMessage.getPropertyNames(); if (jmsPropertyNames != null) { while (jmsPropertyNames.hasMoreElements()) { String propertyName = jmsPropertyNames.nextElement().toString(); try { String headerName = this.toHeaderName(propertyName); headers.put(headerName, jmsMessage.getObjectProperty(propertyName)); } catch (Exception e) { if (logger.isWarnEnabled()) { logger.warn("error occurred while mapping JMS property '" + propertyName + "' to Message header", e); } } } } } catch (JMSException e) { if (logger.isWarnEnabled()) { logger.warn("error occurred while mapping from JMS properties to MessageHeaders", e); } } return headers; }
From source file:org.genemania.connector.JmsEngineConnector.java
public UploadNetworkWebResponseDto uploadNetwork(final UploadNetworkWebRequestDto dto) throws ApplicationException { final String uncid = String.valueOf(System.currentTimeMillis()); UploadNetworkWebResponseDto ret = new UploadNetworkWebResponseDto(); jmsTemplate.send(requestQueue, new MessageCreator() { public TextMessage createMessage(Session session) throws JMSException { LOG.debug("sending UploadnetworkMessage request to " + requestQueue.getQueueName()); UploadNetworkRequestMessage request = BrokerUtils.dto2msg(dto); TextMessage ret = session.createTextMessage(request.toXml()); ret.setJMSDeliveryMode(DeliveryMode.PERSISTENT); ret.setJMSType(MessageType.TEXT2NETWORK.getCode()); replyQueue = session.createTemporaryQueue(); ret.setJMSReplyTo(replyQueue); ret.setJMSCorrelationID(uncid); LOG.debug("uploadNetwork waiting for reply on " + replyQueue.getQueueName()); sentMessages++;/*from w w w .j a va2 s .c o m*/ return ret; } }); Message response; try { response = jmsTemplate.receive(replyQueue); receivedMessages++; if (response.getJMSCorrelationID().equals(uncid)) { LOG.debug("uploadNetwork reply received"); if (response != null) { String responseBody = ((TextMessage) response).getText(); if (StringUtils.isNotEmpty(responseBody)) { UploadNetworkResponseMessage responseMessage = UploadNetworkResponseMessage .fromXml(responseBody); if (responseMessage.getErrorCode() == 0) { ret = BrokerUtils.msg2dto(responseMessage); } else { throw new ApplicationException(responseMessage.getErrorMessage(), responseMessage.getErrorCode()); } } else { LOG.error("uploadNetwork empty response body"); } } else { LOG.error("uploadNetwork JMS response is null"); } } processedMessages++; } catch (JMSException e) { errors++; throw new ApplicationException(Constants.ERROR_CODES.APPLICATION_ERROR); } finally { LOG.debug("messages sent/received/processed/appErrors/errors: " + sentMessages + "/" + receivedMessages + "/" + processedMessages + "/" + appErrors + "/" + errors); // updateStats(); } LOG.debug("uploadNetwork request processing completed"); return ret; }