List of usage examples for javax.jms Message getJMSMessageID
String getJMSMessageID() throws JMSException;
From source file:nl.nn.adapterframework.extensions.fxf.FxfSender.java
public String sendMessage(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException { String action = "put"; String transfername = getTransfername(); String filename = message;/*from ww w .ja v a2s. com*/ String command = getScript() + " " + action + " " + transfername + " " + filename; if (atLeastVersion2) { int timeout = getTimeout(); command = command + " " + timeout; } String remoteFilename = null; if (remoteFilenameParam != null && prc != null) { try { remoteFilename = (String) prc.getValues(paramList).getParameterValue(0).getValue(); command += " " + remoteFilename; } catch (ParameterException e) { throw new SenderException("Could not resolve remote filename", e); } } log.debug(getLogPrefix() + "sending local file [" + message + "] by executing command [" + command + "]"); String transporthandle = ProcessUtil.executeCommand(command, getTimeout() * 2); log.debug(getLogPrefix() + "output of command [" + transporthandle + "]"); if (transporthandle != null) { transporthandle = transporthandle.trim(); } // delete file or move it to processed directory if (isDelete() || StringUtils.isNotEmpty(getProcessedDirectory())) { File f = new File(message); try { log.debug(getLogPrefix() + "moving or deleteing file [" + message + "]"); FileUtils.moveFileAfterProcessing(f, getProcessedDirectory(), isDelete(), isOverwrite(), getNumberOfBackups()); } catch (Exception e) { throw new SenderException("Could not move file [" + message + "]", e); } } if (atLeastVersion2) { String commitMsg = FxfUtil.makeProcessedPutFileMessage(transporthandle); Session s = null; MessageProducer mp = null; try { s = createSession(); mp = getMessageProducer(s, getDestination()); // create message Message msg = createTextMessage(s, correlationID, commitMsg); mp.setDeliveryMode(DeliveryMode.PERSISTENT); // send message send(mp, msg); if (log.isDebugEnabled()) { log.debug(getLogPrefix() + "sent message [" + message + "] to [" + getDestinationName() + "] " + "msgID [" + msg.getJMSMessageID() + "]"); ; } else { if (log.isInfoEnabled()) { log.info(getLogPrefix() + "sent message to [" + getDestinationName() + "] " + "msgID [" + msg.getJMSMessageID() + "]"); ; } } } catch (Throwable e) { throw new SenderException(e); } finally { if (mp != null) { try { mp.close(); } catch (JMSException e) { log.warn(getLogPrefix() + "got exception closing message producer", e); } } closeSession(s); } } return transporthandle; }
From source file:nl.nn.adapterframework.extensions.tibco.GetTibcoQueues.java
private String getQueueMessage(Session jSession, TibjmsAdmin admin, String queueName, int queueItem, LdapSender ldapSender) throws TibjmsAdminException, JMSException { QueueInfo qInfo = admin.getQueue(queueName); if (qInfo == null) { throw new JMSException(" queue [" + queueName + "] does not exist"); }/*from w ww . jav a 2 s . co m*/ XmlBuilder qMessageXml = new XmlBuilder("qMessage"); ServerInfo serverInfo = admin.getInfo(); String url = serverInfo.getURL(); qMessageXml.addAttribute("url", url); String resolvedUrl = getResolvedUrl(url); if (resolvedUrl != null) { qMessageXml.addAttribute("resolvedUrl", resolvedUrl); } qMessageXml.addAttribute("timestamp", DateUtils.getIsoTimeStamp()); qMessageXml.addAttribute("startTime", DateUtils.format(serverInfo.getStartTime(), DateUtils.fullIsoFormat)); XmlBuilder qNameXml = new XmlBuilder("qName"); qNameXml.setCdataValue(queueName); Queue queue = jSession.createQueue(queueName); QueueBrowser queueBrowser = null; try { queueBrowser = jSession.createBrowser(queue); Enumeration enm = queueBrowser.getEnumeration(); int count = 0; boolean found = false; String chompCharSizeString = AppConstants.getInstance().getString("browseQueue.chompCharSize", null); int chompCharSize = (int) Misc.toFileSize(chompCharSizeString, -1); while (enm.hasMoreElements() && !found) { count++; if (count == queueItem) { qNameXml.addAttribute("item", count); Object o = enm.nextElement(); if (o instanceof Message) { Message msg = (Message) o; XmlBuilder qMessageId = new XmlBuilder("qMessageId"); qMessageId.setCdataValue(msg.getJMSMessageID()); qMessageXml.addSubElement(qMessageId); XmlBuilder qTimestamp = new XmlBuilder("qTimestamp"); qTimestamp.setCdataValue(DateUtils.format(msg.getJMSTimestamp(), DateUtils.fullIsoFormat)); qMessageXml.addSubElement(qTimestamp); StringBuffer sb = new StringBuffer(""); Enumeration propertyNames = msg.getPropertyNames(); while (propertyNames.hasMoreElements()) { String propertyName = (String) propertyNames.nextElement(); Object object = msg.getObjectProperty(propertyName); if (sb.length() > 0) { sb.append("; "); } sb.append(propertyName); sb.append("="); sb.append(object); } XmlBuilder qPropsXml = new XmlBuilder("qProps"); qPropsXml.setCdataValue(sb.toString()); qMessageXml.addSubElement(qPropsXml); XmlBuilder qTextXml = new XmlBuilder("qText"); String msgText; try { TextMessage textMessage = (TextMessage) msg; msgText = textMessage.getText(); } catch (ClassCastException e) { msgText = msg.toString(); qTextXml.addAttribute("text", false); } int msgSize = msgText.length(); if (isHideMessage()) { qTextXml.setCdataValue("***HIDDEN***"); } else { if (chompCharSize >= 0 && msgSize > chompCharSize) { qTextXml.setCdataValue(msgText.substring(0, chompCharSize) + "..."); qTextXml.addAttribute("chomped", true); } else { qTextXml.setCdataValue(msgText); } } qMessageXml.addSubElement(qTextXml); XmlBuilder qTextSizeXml = new XmlBuilder("qTextSize"); qTextSizeXml.setValue(Misc.toFileSize(msgSize)); qMessageXml.addSubElement(qTextSizeXml); } found = true; } else { enm.nextElement(); } } } finally { if (queueBrowser != null) { try { queueBrowser.close(); } catch (JMSException e) { log.warn(getLogPrefix(null) + "exception on closing queue browser", e); } } } qMessageXml.addSubElement(qNameXml); Map aclMap = getAclMap(admin, ldapSender); XmlBuilder aclXml = new XmlBuilder("acl"); XmlBuilder qInfoXml = qInfoToXml(qInfo); aclXml.setValue((String) aclMap.get(qInfo.getName())); qInfoXml.addSubElement(aclXml); qMessageXml.addSubElement(qInfoXml); Map consumersMap = getConnectedConsumersMap(admin); XmlBuilder consumerXml = new XmlBuilder("connectedConsumers"); if (consumersMap.containsKey(qInfo.getName())) { LinkedList<String> consumers = (LinkedList<String>) consumersMap.get(qInfo.getName()); String consumersString = listToString(consumers); if (consumersString != null) { consumerXml.setCdataValue(consumersString); } } qInfoXml.addSubElement(consumerXml); return qMessageXml.toXML(); }
From source file:nl.nn.adapterframework.jms.JMSFacade.java
public String send(MessageProducer messageProducer, Message message, boolean ignoreInvalidDestinationException) throws NamingException, JMSException { if (log.isDebugEnabled()) { log.debug(getLogPrefix() + "sender on [" + getDestinationName() + "] will send message with JMSDeliveryMode=[" + message.getJMSDeliveryMode() + "] \n JMSMessageID=[" + message.getJMSMessageID() + "] \n JMSCorrelationID=[" + message.getJMSCorrelationID() + "] \n JMSTimestamp=[" + DateUtils.format(message.getJMSTimestamp()) + "] \n JMSExpiration=[" + message.getJMSExpiration() + "] \n JMSPriority=[" + message.getJMSPriority() + "] \n Message=[" + message.toString() + "]"); }/* w w w . j a v a 2 s . co m*/ try { if (useJms102()) { if (messageProducer instanceof TopicPublisher) { ((TopicPublisher) messageProducer).publish(message); } else { ((QueueSender) messageProducer).send(message); } return message.getJMSMessageID(); } else { messageProducer.send(message); return message.getJMSMessageID(); } } catch (InvalidDestinationException e) { if (ignoreInvalidDestinationException) { log.warn("queue [" + messageProducer.getDestination() + "] doesn't exist"); return null; } else { throw e; } } }
From source file:nl.nn.adapterframework.jms.JMSFacade.java
public String send(Session session, Destination dest, Message message, boolean ignoreInvalidDestinationException) throws NamingException, JMSException { try {/* w ww . ja v a 2 s . co m*/ if (useJms102()) { if (dest instanceof Topic) { return sendByTopic((TopicSession) session, (Topic) dest, message); } else { return sendByQueue((QueueSession) session, (Queue) dest, message); } } else { MessageProducer mp = session.createProducer(dest); mp.send(message); mp.close(); return message.getJMSMessageID(); } } catch (InvalidDestinationException e) { if (ignoreInvalidDestinationException) { log.warn("queue [" + dest + "] doesn't exist"); return null; } else { throw e; } } }
From source file:nl.nn.adapterframework.jms.JMSFacade.java
protected String sendByQueue(QueueSession session, Queue destination, Message message) throws NamingException, JMSException { QueueSender tqs = session.createSender(destination); tqs.send(message);/*from w ww . jav a 2s .c o m*/ tqs.close(); return message.getJMSMessageID(); }
From source file:nl.nn.adapterframework.jms.JMSFacade.java
protected String sendByTopic(TopicSession session, Topic destination, Message message) throws NamingException, JMSException { TopicPublisher tps = session.createPublisher(destination); tps.publish(message);/*ww w .ja v a2 s .co m*/ tps.close(); return message.getJMSMessageID(); }
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 ww . jav a 2s . com*/ 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; }
From source file:nl.nn.adapterframework.jms.JmsSender.java
public String sendMessage(String correlationID, String message, ParameterResolutionContext prc, String soapHeader) throws SenderException, TimeOutException { Session s = null;/*from ww w. j a v a2 s .c o m*/ MessageProducer mp = null; ParameterValueList pvl = null; if (prc != null && paramList != null) { try { pvl = prc.getValues(paramList); } catch (ParameterException e) { throw new SenderException(getLogPrefix() + "cannot extract parameters", e); } } if (isSoap()) { if (soapHeader == null) { if (pvl != null && StringUtils.isNotEmpty(getSoapHeaderParam())) { ParameterValue soapHeaderParamValue = pvl.getParameterValue(getSoapHeaderParam()); if (soapHeaderParamValue == null) { log.warn("no SoapHeader found using parameter [" + getSoapHeaderParam() + "]"); } else { soapHeader = soapHeaderParamValue.asStringValue(""); } } } message = soapWrapper.putInEnvelope(message, getEncodingStyleURI(), getServiceNamespaceURI(), soapHeader); if (log.isDebugEnabled()) log.debug(getLogPrefix() + "correlationId [" + correlationID + "] soap message [" + message + "]"); } try { s = createSession(); mp = getMessageProducer(s, getDestination(prc)); Destination replyQueue = null; // create message Message msg = createTextMessage(s, correlationID, message); if (getMessageType() != null) { msg.setJMSType(getMessageType()); } if (getDeliveryModeInt() > 0) { msg.setJMSDeliveryMode(getDeliveryModeInt()); mp.setDeliveryMode(getDeliveryModeInt()); } if (getPriority() >= 0) { msg.setJMSPriority(getPriority()); mp.setPriority(getPriority()); } // set properties if (pvl != null) { setProperties(msg, pvl); } if (replyToName != null) { replyQueue = getDestination(replyToName); } else { if (isSynchronous()) { replyQueue = getMessagingSource().getDynamicReplyQueue(s); } } if (replyQueue != null) { msg.setJMSReplyTo(replyQueue); if (log.isDebugEnabled()) log.debug("replyTo set to queue [" + replyQueue.toString() + "]"); } // send message send(mp, msg); if (log.isDebugEnabled()) { log.debug("[" + getName() + "] " + "sent message [" + message + "] " + "to [" + mp.getDestination() + "] " + "msgID [" + msg.getJMSMessageID() + "] " + "correlationID [" + msg.getJMSCorrelationID() + "] " + "using deliveryMode [" + getDeliveryMode() + "] " + ((replyToName != null) ? "replyTo [" + replyToName + "]" : "")); } else { if (log.isInfoEnabled()) { log.info("[" + getName() + "] " + "sent message to [" + mp.getDestination() + "] " + "msgID [" + msg.getJMSMessageID() + "] " + "correlationID [" + msg.getJMSCorrelationID() + "] " + "using deliveryMode [" + getDeliveryMode() + "] " + ((replyToName != null) ? "replyTo [" + replyToName + "]" : "")); } } if (isSynchronous()) { String replyCorrelationId = null; if (replyToName != null) { if ("CORRELATIONID".equalsIgnoreCase(getLinkMethod())) { replyCorrelationId = correlationID; } else if ("CORRELATIONID_FROM_MESSAGE".equalsIgnoreCase(getLinkMethod())) { replyCorrelationId = msg.getJMSCorrelationID(); } else { replyCorrelationId = msg.getJMSMessageID(); } } if (log.isDebugEnabled()) log.debug("[" + getName() + "] start waiting for reply on [" + replyQueue + "] requestMsgId [" + msg.getJMSMessageID() + "] replyCorrelationId [" + replyCorrelationId + "] for [" + getReplyTimeout() + "] ms"); MessageConsumer mc = getMessageConsumerForCorrelationId(s, replyQueue, replyCorrelationId); try { Message rawReplyMsg = mc.receive(getReplyTimeout()); if (rawReplyMsg == null) { throw new TimeOutException("did not receive reply on [" + replyQueue + "] requestMsgId [" + msg.getJMSMessageID() + "] replyCorrelationId [" + replyCorrelationId + "] within [" + getReplyTimeout() + "] ms"); } return getStringFromRawMessage(rawReplyMsg, prc != null ? prc.getSession() : null, isSoap(), getReplySoapHeaderSessionKey(), soapWrapper); } finally { if (mc != null) { try { mc.close(); } catch (JMSException e) { log.warn("JmsSender [" + getName() + "] got exception closing message consumer for reply", e); } } } } return msg.getJMSMessageID(); } catch (JMSException e) { throw new SenderException(e); } catch (IOException e) { throw new SenderException(e); } catch (NamingException e) { throw new SenderException(e); } catch (DomBuilderException e) { throw new SenderException(e); } catch (TransformerException e) { throw new SenderException(e); } catch (JmsException e) { throw new SenderException(e); } finally { if (mp != null) { try { mp.close(); } catch (JMSException e) { log.warn("JmsSender [" + getName() + "] got exception closing message producer", e); } } closeSession(s); } }
From source file:org.apache.activemq.apollo.JmsQueueBrowserTest.java
public void testQueueBrowserWith2Consumers() throws Exception { final int numMessages = 1000; // connection.setAlwaysSyncSend(false); Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE); ActiveMQQueue destination = new ActiveMQQueue("TEST"); ActiveMQQueue destinationPrefetch10 = new ActiveMQQueue("TEST?jms.prefetchSize=10"); ActiveMQQueue destinationPrefetch1 = new ActiveMQQueue("TEST?jms.prefetchsize=1"); connection.start();/*from w w w . jav a2 s.c o m*/ Connection connection2 = factory.createConnection(userName, password); connection2.start(); connections.add(connection2); Session session2 = connection2.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer producer = session.createProducer(destination); MessageConsumer consumer = session.createConsumer(destinationPrefetch10); for (int i = 0; i < numMessages; i++) { TextMessage message = session.createTextMessage("Message: " + i); producer.send(message); } QueueBrowser browser = session2.createBrowser(destinationPrefetch1); Enumeration<Message> browserView = browser.getEnumeration(); List<Message> messages = new ArrayList<Message>(); for (int i = 0; i < numMessages; i++) { Message m1 = consumer.receive(5000); assertNotNull("m1 is null for index: " + i, m1); messages.add(m1); } int i = 0; for (; i < numMessages && browserView.hasMoreElements(); i++) { Message m1 = messages.get(i); Message m2 = browserView.nextElement(); assertNotNull("m2 is null for index: " + i, m2); assertEquals(m1.getJMSMessageID(), m2.getJMSMessageID()); } // currently browse max page size is ignored for a queue browser consumer // only guarantee is a page size - but a snapshot of pagedinpending is // used so it is most likely more assertTrue("got at least our expected minimum in the browser: ", i > 200); assertFalse("nothing left in the browser", browserView.hasMoreElements()); assertNull("consumer finished", consumer.receiveNoWait()); }
From source file:org.apache.axis2.transport.jms.JMSMessageReceiver.java
/** * Process a new message received/*ww w .jav a 2s .com*/ * * @param message the JMS message received * @param ut UserTransaction which was used to receive the message * @return true if caller should commit */ public boolean onMessage(Message message, UserTransaction ut) { try { if (log.isDebugEnabled()) { StringBuffer sb = new StringBuffer(); sb.append("Received new JMS message for service :").append(endpoint.getServiceName()); sb.append("\nDestination : ").append(message.getJMSDestination()); sb.append("\nMessage ID : ").append(message.getJMSMessageID()); sb.append("\nCorrelation ID : ").append(message.getJMSCorrelationID()); sb.append("\nReplyTo : ").append(message.getJMSReplyTo()); sb.append("\nRedelivery ? : ").append(message.getJMSRedelivered()); sb.append("\nPriority : ").append(message.getJMSPriority()); sb.append("\nExpiration : ").append(message.getJMSExpiration()); sb.append("\nTimestamp : ").append(message.getJMSTimestamp()); sb.append("\nMessage Type : ").append(message.getJMSType()); sb.append("\nPersistent ? : ").append(DeliveryMode.PERSISTENT == message.getJMSDeliveryMode()); log.debug(sb.toString()); if (log.isTraceEnabled() && message instanceof TextMessage) { log.trace("\nMessage : " + ((TextMessage) message).getText()); } } } catch (JMSException e) { if (log.isDebugEnabled()) { log.debug("Error reading JMS message headers for debug logging", e); } } // update transport level metrics try { metrics.incrementBytesReceived(JMSUtils.getMessageSize(message)); } catch (JMSException e) { log.warn("Error reading JMS message size to update transport metrics", e); } // has this message already expired? expiration time == 0 means never expires // TODO: explain why this is necessary; normally it is the responsibility of the provider to handle message expiration try { long expiryTime = message.getJMSExpiration(); if (expiryTime > 0 && System.currentTimeMillis() > expiryTime) { if (log.isDebugEnabled()) { log.debug("Discard expired message with ID : " + message.getJMSMessageID()); } return true; } } catch (JMSException ignore) { } boolean successful = false; try { successful = processThoughEngine(message, ut); } catch (JMSException e) { log.error("JMS Exception encountered while processing", e); } catch (AxisFault e) { log.error("Axis fault processing message", e); } catch (Exception e) { log.error("Unknown error processing message", e); } finally { if (successful) { metrics.incrementMessagesReceived(); } else { metrics.incrementFaultsReceiving(); } } return successful; }