List of usage examples for javax.jms Message getJMSPriority
int getJMSPriority() throws JMSException;
From source file:org.apache.axis2.transport.jms.JMSUtils.java
/** * Extract transport level headers for JMS from the given message into a Map * * @param message the JMS message/* ww w .ja v a 2 s . co m*/ * @return a Map of the transport headers */ public static Map<String, Object> getTransportHeaders(Message message) { // create a Map to hold transport headers Map<String, Object> map = new HashMap<String, Object>(); // correlation ID try { if (message.getJMSCorrelationID() != null) { map.put(JMSConstants.JMS_COORELATION_ID, message.getJMSCorrelationID()); } } catch (JMSException ignore) { } // set the delivery mode as persistent or not try { map.put(JMSConstants.JMS_DELIVERY_MODE, Integer.toString(message.getJMSDeliveryMode())); } catch (JMSException ignore) { } // destination name try { if (message.getJMSDestination() != null) { Destination dest = message.getJMSDestination(); map.put(JMSConstants.JMS_DESTINATION, dest instanceof Queue ? ((Queue) dest).getQueueName() : ((Topic) dest).getTopicName()); } } catch (JMSException ignore) { } // expiration try { map.put(JMSConstants.JMS_EXPIRATION, Long.toString(message.getJMSExpiration())); } catch (JMSException ignore) { } // if a JMS message ID is found try { if (message.getJMSMessageID() != null) { map.put(JMSConstants.JMS_MESSAGE_ID, message.getJMSMessageID()); } } catch (JMSException ignore) { } // priority try { map.put(JMSConstants.JMS_PRIORITY, Long.toString(message.getJMSPriority())); } catch (JMSException ignore) { } // redelivered try { map.put(JMSConstants.JMS_REDELIVERED, Boolean.toString(message.getJMSRedelivered())); } catch (JMSException ignore) { } // replyto destination name try { if (message.getJMSReplyTo() != null) { Destination dest = message.getJMSReplyTo(); map.put(JMSConstants.JMS_REPLY_TO, dest instanceof Queue ? ((Queue) dest).getQueueName() : ((Topic) dest).getTopicName()); } } catch (JMSException ignore) { } // priority try { map.put(JMSConstants.JMS_TIMESTAMP, Long.toString(message.getJMSTimestamp())); } catch (JMSException ignore) { } // message type try { if (message.getJMSType() != null) { map.put(JMSConstants.JMS_TYPE, message.getJMSType()); } } catch (JMSException ignore) { } // any other transport properties / headers Enumeration<?> e = null; try { e = message.getPropertyNames(); } catch (JMSException ignore) { } if (e != null) { while (e.hasMoreElements()) { String headerName = (String) e.nextElement(); try { map.put(headerName, message.getStringProperty(headerName)); continue; } catch (JMSException ignore) { } try { map.put(headerName, message.getBooleanProperty(headerName)); continue; } catch (JMSException ignore) { } try { map.put(headerName, message.getIntProperty(headerName)); continue; } catch (JMSException ignore) { } try { map.put(headerName, message.getLongProperty(headerName)); continue; } catch (JMSException ignore) { } try { map.put(headerName, message.getDoubleProperty(headerName)); continue; } catch (JMSException ignore) { } try { map.put(headerName, message.getFloatProperty(headerName)); } catch (JMSException ignore) { } } } return map; }
From source file:org.apache.camel.component.jms.JmsBinding.java
public Map<String, Object> extractHeadersFromJms(Message jmsMessage, Exchange exchange) { Map<String, Object> map = new HashMap<String, Object>(); if (jmsMessage != null) { // lets populate the standard JMS message headers try {/*from ww w .jav a 2s .c om*/ map.put("JMSCorrelationID", jmsMessage.getJMSCorrelationID()); map.put("JMSDeliveryMode", jmsMessage.getJMSDeliveryMode()); map.put("JMSDestination", jmsMessage.getJMSDestination()); map.put("JMSExpiration", jmsMessage.getJMSExpiration()); map.put("JMSMessageID", jmsMessage.getJMSMessageID()); map.put("JMSPriority", jmsMessage.getJMSPriority()); map.put("JMSRedelivered", jmsMessage.getJMSRedelivered()); map.put("JMSTimestamp", jmsMessage.getJMSTimestamp()); // to work around OracleAQ not supporting the JMSReplyTo header (CAMEL-2909) try { map.put("JMSReplyTo", jmsMessage.getJMSReplyTo()); } catch (JMSException e) { LOG.trace("Cannot read JMSReplyTo header. Will ignore this exception.", e); } // to work around OracleAQ not supporting the JMSType header (CAMEL-2909) try { map.put("JMSType", jmsMessage.getJMSType()); } catch (JMSException e) { LOG.trace("Cannot read JMSType header. Will ignore this exception.", e); } // this works around a bug in the ActiveMQ property handling map.put("JMSXGroupID", jmsMessage.getStringProperty("JMSXGroupID")); } catch (JMSException e) { throw new RuntimeCamelException(e); } Enumeration names; try { names = jmsMessage.getPropertyNames(); } catch (JMSException e) { throw new RuntimeCamelException(e); } while (names.hasMoreElements()) { String name = names.nextElement().toString(); try { Object value = jmsMessage.getObjectProperty(name); if (headerFilterStrategy != null && headerFilterStrategy.applyFilterToExternalHeaders(name, value, exchange)) { continue; } // must decode back from safe JMS header name to original header name // when storing on this Camel JmsMessage object. String key = jmsKeyFormatStrategy.decodeKey(name); map.put(key, value); } catch (JMSException e) { throw new RuntimeCamelException(name, e); } } } return map; }
From source file:org.apache.james.queue.jms.JMSMailQueue.java
@Override public long flush() throws MailQueueException { boolean first = true; long count = 0; try (Session session = connection.createSession(true, Session.SESSION_TRANSACTED)) { Queue queue = session.createQueue(queueName); try (MessageConsumer consumer = session.createConsumer(queue)) { try (MessageProducer producer = session.createProducer(queue)) { Message message = null; while (first || message != null) { if (first) { // give the consumer 2000 ms to receive messages message = consumer.receive(2000); } else { message = consumer.receiveNoWait(); }/*from www .j ava 2s .co m*/ first = false; if (message != null) { Message m = copy(session, message); m.setBooleanProperty(FORCE_DELIVERY, true); producer.send(m, message.getJMSDeliveryMode(), message.getJMSPriority(), message.getJMSExpiration()); count++; } } session.commit(); return count; } } } catch (Exception e) { LOGGER.error("Unable to flush mail", e); throw new MailQueueException("Unable to get size of queue " + queueName, e); } }
From source file:org.apache.qpid.disttest.jms.ClientJmsDelegate.java
public Message sendNextMessage(final CreateProducerCommand command) { Message sentMessage = null; MessageProvider messageProvider = _testMessageProviders.get(command.getMessageProviderName()); if (messageProvider == null) { messageProvider = _defaultMessageProvider; }//from w ww . java2 s .c om final Session session = _testSessions.get(command.getSessionName()); final MessageProducer producer = _testProducers.get(command.getParticipantName()); try { sentMessage = messageProvider.nextMessage(session, command); int deliveryMode = producer.getDeliveryMode(); int priority = producer.getPriority(); long ttl = producer.getTimeToLive(); if (messageProvider.isPropertySet(MessageProvider.PRIORITY)) { priority = sentMessage.getJMSPriority(); } if (messageProvider.isPropertySet(MessageProvider.DELIVERY_MODE)) { deliveryMode = sentMessage.getJMSDeliveryMode(); } if (messageProvider.isPropertySet(MessageProvider.TTL)) { ttl = sentMessage.getLongProperty(MessageProvider.TTL); } producer.send(sentMessage, deliveryMode, priority, ttl); } catch (final JMSException jmse) { throw new DistributedTestException("Unable to create and send message with producer: " + command.getParticipantName() + " on session: " + command.getSessionName(), jmse); } return sentMessage; }
From source file:org.apache.qpid.systest.management.jmx.QueueManagementTest.java
/** * Tests {@link ManagedQueue#viewMessages(long, long)} interface. *///from w w w.java 2 s . c o m public void testViewSingleMessage() throws Exception { final List<Message> sentMessages = sendMessage(_session, _sourceQueue, 1); syncSession(_session); final Message sentMessage = sentMessages.get(0); assertEquals("Unexpected queue depth", 1, _managedSourceQueue.getMessageCount().intValue()); // Check the contents of the message final TabularData tab = _managedSourceQueue.viewMessages(1l, 1l); assertEquals("Unexpected number of rows in table", 1, tab.size()); final Iterator<CompositeData> rowItr = (Iterator<CompositeData>) tab.values().iterator(); final CompositeData row1 = rowItr.next(); assertNotNull("Message should have AMQ message id", row1.get(ManagedQueue.MSG_AMQ_ID)); assertEquals("Unexpected queue position", 1l, row1.get(ManagedQueue.MSG_QUEUE_POS)); assertEquals("Unexpected redelivered flag", Boolean.FALSE, row1.get(ManagedQueue.MSG_REDELIVERED)); // Check the contents of header (encoded in a string array) final String[] headerArray = (String[]) row1.get(ManagedQueue.MSG_HEADER); assertNotNull("Expected message header array", headerArray); final Map<String, String> headers = headerArrayToMap(headerArray); final String expectedJMSMessageID = isBroker010() ? sentMessage.getJMSMessageID().replace("ID:", "") : sentMessage.getJMSMessageID(); final String expectedFormattedJMSTimestamp = FastDateFormat .getInstance(ManagedQueue.JMSTIMESTAMP_DATETIME_FORMAT).format(sentMessage.getJMSTimestamp()); assertEquals("Unexpected JMSMessageID within header", expectedJMSMessageID, headers.get("JMSMessageID")); assertEquals("Unexpected JMSPriority within header", String.valueOf(sentMessage.getJMSPriority()), headers.get("JMSPriority")); assertEquals("Unexpected JMSTimestamp within header", expectedFormattedJMSTimestamp, headers.get("JMSTimestamp")); }
From source file:org.apache.synapse.message.store.impl.jms.JmsConsumer.java
public MessageContext receive() { boolean error; JMSException exception;//w w w . j a va2s .c o m if (!checkConnection()) { if (!reconnect()) { if (logger.isDebugEnabled()) { logger.debug(getId() + " cannot receive message from store. Cannot reconnect."); } return null; } else { logger.info(getId() + " reconnected to store."); isReceiveError = false; } } if (!checkConnection()) { if (logger.isDebugEnabled()) { logger.debug(getId() + " cannot receive message from store."); } return null; } try { Message message = consumer.receive(1); if (message == null) { return null; } if (!(message instanceof ObjectMessage)) { logger.warn(getId() + ". Did not receive a javax.jms.ObjectMessage"); message.acknowledge(); // TODO: return null; } ObjectMessage msg = (ObjectMessage) message; String messageId = msg.getStringProperty(Constants.OriginalMessageID); if (!(msg.getObject() instanceof StorableMessage)) { logger.warn(getId() + ". Did not receive a valid message."); message.acknowledge(); return null; } StorableMessage storableMessage = (StorableMessage) msg.getObject(); org.apache.axis2.context.MessageContext axis2Mc = store.newAxis2Mc(); MessageContext synapseMc = store.newSynapseMc(axis2Mc); synapseMc = MessageConverter.toMessageContext(storableMessage, axis2Mc, synapseMc); updateCache(message, synapseMc, messageId, false); if (logger.isDebugEnabled()) { logger.debug( getId() + " Received MessageId:" + messageId + " priority:" + message.getJMSPriority()); } return synapseMc; } catch (JMSException e) { error = true; exception = e; } if (error) { if (!isReceiveError) { logger.error( getId() + " cannot receive message from store. Error:" + exception.getLocalizedMessage());//, exception); } updateCache(null, null, "", true); cleanup(); return null; } return null; }
From source file:org.apache.synapse.transport.jms.JMSUtils.java
/** * Extract transport level headers for JMS from the given message into a Map * * @param message the JMS message/*w ww . jav a2 s . c o m*/ * @return a Map of the transport headers */ public static Map getTransportHeaders(Message message) { // create a Map to hold transport headers Map map = new HashMap(); // correlation ID try { if (message.getJMSCorrelationID() != null) { map.put(JMSConstants.JMS_COORELATION_ID, message.getJMSCorrelationID()); } } catch (JMSException ignore) { } // set the delivery mode as persistent or not try { map.put(JMSConstants.JMS_DELIVERY_MODE, Integer.toString(message.getJMSDeliveryMode())); } catch (JMSException ignore) { } // destination name try { if (message.getJMSDestination() != null) { Destination dest = message.getJMSDestination(); map.put(JMSConstants.JMS_DESTINATION, dest instanceof Queue ? ((Queue) dest).getQueueName() : ((Topic) dest).getTopicName()); } } catch (JMSException ignore) { } // expiration try { map.put(JMSConstants.JMS_EXPIRATION, Long.toString(message.getJMSExpiration())); } catch (JMSException ignore) { } // if a JMS message ID is found try { if (message.getJMSMessageID() != null) { map.put(JMSConstants.JMS_MESSAGE_ID, message.getJMSMessageID()); } } catch (JMSException ignore) { } // priority try { map.put(JMSConstants.JMS_PRIORITY, Long.toString(message.getJMSPriority())); } catch (JMSException ignore) { } // redelivered try { map.put(JMSConstants.JMS_REDELIVERED, Boolean.toString(message.getJMSRedelivered())); } catch (JMSException ignore) { } // replyto destination name try { if (message.getJMSReplyTo() != null) { Destination dest = message.getJMSReplyTo(); map.put(JMSConstants.JMS_REPLY_TO, dest instanceof Queue ? ((Queue) dest).getQueueName() : ((Topic) dest).getTopicName()); } } catch (JMSException ignore) { } // priority try { map.put(JMSConstants.JMS_TIMESTAMP, Long.toString(message.getJMSTimestamp())); } catch (JMSException ignore) { } // message type try { if (message.getJMSType() != null) { map.put(JMSConstants.JMS_TYPE, message.getJMSType()); } } catch (JMSException ignore) { } // any other transport properties / headers Enumeration e = null; try { e = message.getPropertyNames(); } catch (JMSException ignore) { } if (e != null) { while (e.hasMoreElements()) { String headerName = (String) e.nextElement(); try { map.put(headerName, message.getStringProperty(headerName)); continue; } catch (JMSException ignore) { } try { map.put(headerName, Boolean.valueOf(message.getBooleanProperty(headerName))); continue; } catch (JMSException ignore) { } try { map.put(headerName, new Integer(message.getIntProperty(headerName))); continue; } catch (JMSException ignore) { } try { map.put(headerName, new Long(message.getLongProperty(headerName))); continue; } catch (JMSException ignore) { } try { map.put(headerName, new Double(message.getDoubleProperty(headerName))); continue; } catch (JMSException ignore) { } try { map.put(headerName, new Float(message.getFloatProperty(headerName))); continue; } catch (JMSException ignore) { } } } return map; }
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()); }//from www. j av a2s . 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.mule.transport.jms.JmsMessageUtils.java
public static Message copyJMSProperties(Message from, Message to, JmsConnector connector) throws JMSException { if (connector.supportsProperty(JmsConstants.JMS_CORRELATION_ID)) { to.setJMSCorrelationID(from.getJMSCorrelationID()); }// www. jav a 2s . co m if (connector.supportsProperty(JmsConstants.JMS_DELIVERY_MODE)) { to.setJMSDeliveryMode(from.getJMSDeliveryMode()); } if (connector.supportsProperty(JmsConstants.JMS_DESTINATION)) { to.setJMSDestination(from.getJMSDestination()); } if (connector.supportsProperty(JmsConstants.JMS_EXPIRATION)) { to.setJMSExpiration(from.getJMSExpiration()); } if (connector.supportsProperty(JmsConstants.JMS_MESSAGE_ID)) { to.setJMSMessageID(from.getJMSMessageID()); } if (connector.supportsProperty(JmsConstants.JMS_PRIORITY)) { to.setJMSPriority(from.getJMSPriority()); } if (connector.supportsProperty(JmsConstants.JMS_REDELIVERED)) { to.setJMSRedelivered(from.getJMSRedelivered()); } if (connector.supportsProperty(JmsConstants.JMS_REPLY_TO)) { to.setJMSReplyTo(from.getJMSReplyTo()); } if (connector.supportsProperty(JmsConstants.JMS_TIMESTAMP)) { to.setJMSTimestamp(from.getJMSTimestamp()); } if (connector.supportsProperty(JmsConstants.JMS_TYPE)) { to.setJMSType(from.getJMSType()); } return to; }
From source file:org.openanzo.combus.endpoint.BaseServiceListener.java
public void onMessage(Message message) { if (started) { try {//from w w w.j ava 2s. c o m if (threadPool != null) { if (message.propertyExists(SerializationConstants.bypassPool) && message.getBooleanProperty(SerializationConstants.bypassPool)) { processMessage(message); } else { if (message.getJMSPriority() < 4) { while (threadPool.getNumActive() >= threadPool.getMaxActive() || (highActive > (threadPool.getNumActive() / 2) && lowActive > 1)) { synchronized (threadPool) { threadPool.wait(); } } ProcessThread pt = (ProcessThread) threadPool.borrowObject(); pt.setRequest(message, false); } else { ProcessThread pt = (ProcessThread) threadPool.borrowObject(); pt.setRequest(message, true); } } } else { processMessage(message); } } catch (Throwable jmex) { log.error(LogUtils.COMBUS_MARKER, "Error in BaseService Listener's process thread loop", jmex); } } }