Java Code Examples for javax.jms.Message.getJMSMessageID()

The following are Jave code examples for showing how to use getJMSMessageID() of the javax.jms.Message class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: jaffa-framework   File: LockingService.java   Source Code and License Vote up 5 votes
/** Browses all pending messages in the input queue looking for the locks, as specified in the input filter.
 * Throws an ApplicationException, if any matching message is found, and if the input argument 'deleteLockingMessage' is false.
 * Deletes all matching messages, if the input argument 'deleteLockingMessage' is true.
 * @param queueName the queue name.
 * @param filter the filter for retrieving Lock messages.
 * @param deleteLockingMessage determines if the matching messages are to be deleted.
 * @param session the JMS session.
 * @throws JMSException if any JMS error occurs.
 * @throws FrameworkException Indicates some system error.
 * @throws ApplicationExceptions Indicates application error(s).
 */
private static void checkOrDeleteLockingPendingMessages(String queueName, String filter, boolean deleteLockingMessage, Session session)
throws JMSException, ApplicationExceptions, FrameworkException {
    // Creates a QueueBrowser from the Session, using the filter
    if (log.isDebugEnabled())
        log.debug("Checking for locks in pending messages in " + queueName + " with the filter " + filter);
    QueueBrowser qb = session.createBrowser(JmsClientHelper.obtainQueue(queueName), filter);
    
    // Throws an ApplicationException if any applicable lock is found
    Enumeration e = qb.getEnumeration();
    while (e.hasMoreElements()) {
        Message message = (Message) e.nextElement();
        if (log.isDebugEnabled())
            log.debug("Found a blocking pending message in " + queueName + " with the contents " + message);
        if (deleteLockingMessage)
            JmsBrowser.consumeMessage(session, message, queueName);
        else
            throw new ApplicationExceptions(new JaffaMessagingApplicationException(JaffaMessagingApplicationException.LOCK_ERROR, new Object[] {queueName, message.getJMSMessageID()}));
    }
    
    // Close the QueueBrowser
    qb.close();
}
 
Example 2
Project: jaffa-framework   File: MessageViewerTx.java   Source Code and License Vote up 5 votes
/** Returns the messageId to be used for retrieving the BusinessEventLogs for a Message.
 * @param input The criteria based on which an object will be retrieved.
 * @throws ApplicationExceptions This will be thrown if the criteria contains invalid data.
 * @throws FrameworkException Indicates some system error.
 * @return The messageId.
 */
public String getMessageIdForBusinessEventLog(MessageViewerInDto input) throws FrameworkException, ApplicationExceptions{
    try{
        Message message = findMessage(input);
        return message.getStringProperty(JmsBrowser.HEADER_ORIGINAL_MESSAGE_ID) != null ? message.getStringProperty(JmsBrowser.HEADER_ORIGINAL_MESSAGE_ID) : message.getJMSMessageID();
    } catch(JMSException e) {
        throw new JaffaMessagingFrameworkException(JaffaMessagingFrameworkException.MESSAGE_INFO_MISSING, null, e);
    }
}
 
Example 3
Project: scanning   File: QueueReader.java   Source Code and License Vote up 4 votes
/**
 * Read the status beans from any queue.
 * Returns a list of optionally date-ordered beans in the queue.
 *
 * @param uri
 * @param queueName
 * @param clazz
 * @param monitor
 * @return
 * @throws Exception
 */
public List<T> getBeans(final URI uri, final String queueName, final Class<T> beanClass) throws Exception {

	QueueConnection qCon = null;
	try {
		QueueConnectionFactory connectionFactory = (QueueConnectionFactory)service.createConnectionFactory(uri);
		qCon  = connectionFactory.createQueueConnection(); // This times out when the server is not there.
		QueueSession    qSes  = qCon.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
		Queue queue   = qSes.createQueue(queueName);
		qCon.start();

		QueueBrowser qb = qSes.createBrowser(queue);
		@SuppressWarnings("rawtypes")
		Enumeration  e  = qb.getEnumeration();


		final Collection<T> list;
		if (comparator!=null) {
			list = new TreeSet<T>(comparator);
		} else {
			list = new ArrayList<T>(17);
		}

		while(e.hasMoreElements()) {
			Message m = (Message)e.nextElement();
			if (m==null) continue;
			if (m instanceof TextMessage) {
				TextMessage t = (TextMessage)m;
				String json   = t.getText();
				@SuppressWarnings("unchecked")
				final Class<T> statusBeanClass = (Class<T>) StatusBean.class;
				try {
					final T bean = (T)service.unmarshal(json, beanClass != null ? beanClass : statusBeanClass);
					list.add(bean);

				} catch (Exception unmarshallable) {
					System.out.println("Removing old message "+json);
					String jMSMessageID = m.getJMSMessageID();
					if (jMSMessageID!=null) {
						MessageConsumer consumer = qSes.createConsumer(queue, "JMSMessageID = '"+jMSMessageID+"'");
						Message ignored = consumer.receive(1000);
						consumer.close();
						System.out.println("Removed");
					}

				}
			}
		}
		return list instanceof List ? (List<T>)list : new ArrayList<T>(list);

	} finally {
		if (qCon!=null) qCon.close();
	}

}