Java Code Examples for javax.jms.Message#getJMSRedelivered()

The following examples show how to use javax.jms.Message#getJMSRedelivered() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MessageListenerTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Override
public void onMessage(Message message) {
    TextMessage textMessage = (TextMessage)message;
    try {
        switch (TestMessage.valueOf(textMessage.getText())) {
        case OK:
            //System.out.println("Simulating Processing successful");
            break;
        case FAILFIRST:
            if (message.getJMSRedelivered()) {
                //System.out.println("Simulating processing worked on second try");
                break;
            }
            throw new RuntimeException("Simulating something went wrong. Expecting rollback");
        case FAIL:
            throw new RuntimeException("Simulating something went wrong. Expecting rollback");
        default:
            throw new IllegalArgumentException("Invalid message type");
        }
    } catch (JMSException e) {
        // Ignore
    }
}
 
Example 2
Source File: Client.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
private ClientMessage buildClientMessage(final Message message) throws JMSException
{
    String jmsMessageID = message.getJMSMessageID();
    String jmsCorrelationID = message.getJMSCorrelationID();
    byte[] jmsCorrelationIDAsBytes;
    try
    {
        jmsCorrelationIDAsBytes = message.getJMSCorrelationIDAsBytes();
    }
    catch (JMSException e)
    {
        jmsCorrelationIDAsBytes = null;
    }
    long jmsTimestamp = message.getJMSTimestamp();
    int jmsDeliveryMode = message.getJMSDeliveryMode();
    boolean jmsRedelivered = message.getJMSRedelivered();
    String jmsType = message.getJMSType();
    long jmsExpiration = message.getJMSExpiration();
    int jmsPriority = message.getJMSPriority();

    return new JMSMessageAdaptor(jmsMessageID,
                                 jmsTimestamp,
                                 jmsCorrelationID,
                                 jmsCorrelationIDAsBytes,
                                 jmsDeliveryMode,
                                 jmsRedelivered,
                                 jmsType,
                                 jmsExpiration,
                                 jmsPriority);
}
 
Example 3
Source File: AbstractJMSInputOperator.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
/**
 * This method is called when a message is added to {@link #holdingBuffer} and can be overwritten by subclasses
 * if required. This is called by the JMS thread not Operator thread.
 *
 * @param message
 * @return message is accepted.
 * @throws javax.jms.JMSException
 */
protected boolean messageConsumed(Message message) throws JMSException
{
  if (message.getJMSRedelivered() && pendingAck.contains(message.getJMSMessageID())) {
    counters.getCounter(CounterKeys.REDELIVERED).increment();
    LOG.warn("IGNORING: Redelivered Message {}", message.getJMSMessageID());
    return false;
  }
  pendingAck.add(message.getJMSMessageID());
  MutableLong receivedCt = counters.getCounter(CounterKeys.RECEIVED);
  receivedCt.increment();
  LOG.debug("message id: {} buffer size: {} received: {}", message.getJMSMessageID(), holdingBuffer.size(),
      receivedCt.longValue());
  return true;
}
 
Example 4
Source File: AutoAckMessageListenerTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public void onMessage(Message message) {
   try {
      if (message.getBooleanProperty("last") == false) {
         log.debug("Received first message.");
         if (message.getJMSRedelivered() == true) {
            // should not re-receive this one
            log.debug("Error: received first message twice");
            passed = false;
         }
      } else {
         if (message.getJMSRedelivered() == false) {
            // received second message for first time
            log.debug("Received second message. Calling recover()");
            session.recover();
         } else {
            // should be redelivered after recover
            log.debug("Received second message again as expected");
            passed = true;
            monitor.countDown();
         }
      }
   } catch (JMSException e) {
      log.warn("Exception caught in message listener:\n" + e);
      passed = false;
      monitor.countDown();
   }

}
 
Example 5
Source File: MessageVerifier.java    From qpid-broker-j with Apache License 2.0 4 votes vote down vote up
private static void verifyMessageHeaders(final MessageDescription messageDescription,
                                         final Message message) throws VerificationException
{
    try
    {
        for (Map.Entry<MessageDescription.MessageHeader, Serializable> entry : messageDescription.getHeaders()
                                                                                                 .entrySet())
        {
            Object actualValue;

            switch (entry.getKey())
            {
                case DESTINATION:
                    actualValue = message.getJMSDestination();
                    break;
                case DELIVERY_MODE:
                    actualValue = message.getJMSDeliveryMode();
                    break;
                case MESSAGE_ID:
                    actualValue = message.getJMSMessageID();
                    break;
                case TIMESTAMP:
                    actualValue = message.getJMSTimestamp();
                    break;
                case CORRELATION_ID:
                    if (entry.getValue() instanceof byte[])
                    {
                        actualValue = message.getJMSCorrelationIDAsBytes();
                    }
                    else
                    {
                        actualValue = message.getJMSCorrelationID();
                    }
                    break;
                case REPLY_TO:
                    actualValue = message.getJMSReplyTo();
                    break;
                case REDELIVERED:
                    actualValue = message.getJMSRedelivered();
                    break;
                case TYPE:
                    actualValue = message.getJMSType();
                    break;
                case EXPIRATION:
                    actualValue = message.getJMSExpiration();
                    break;
                case PRIORITY:
                    actualValue = message.getJMSPriority();
                    break;
                default:
                    throw new RuntimeException(String.format("unexpected message header '%s'", entry.getKey()));
            }

            verifyEquals(String.format("Unexpected message header '%s'", entry.getKey()),
                         entry.getValue(),
                         actualValue);
        }
    }
    catch (JMSException e)
    {
        throw new RuntimeException("Unexpected exception during message header verification", e);
    }
}
 
Example 6
Source File: MessageDumpWriter.java    From a with Apache License 2.0 4 votes vote down vote up
public MessageDump toDumpMessage(Message msg) throws JMSException{
	
	MessageDump dump = new MessageDump();
	dump.JMSCorrelationID = msg.getJMSCorrelationID();
	dump.JMSMessageID = msg.getJMSMessageID();
	dump.JMSType = msg.getJMSType();
	dump.JMSDeliveryMode =  msg.getJMSDeliveryMode();
	dump.JMSExpiration = msg.getJMSExpiration();
	dump.JMSRedelivered = msg.getJMSRedelivered();
	dump.JMSTimestamp =  msg.getJMSTimestamp();
	dump.JMSPriority = msg.getJMSPriority();
	
	@SuppressWarnings("rawtypes")
	Enumeration propertyNames = msg.getPropertyNames();
	while(propertyNames.hasMoreElements()){
		String property = (String) propertyNames.nextElement();
		Object propertyValue = msg.getObjectProperty(property);
		if( propertyValue instanceof String){
			dump.stringProperties.put(property, (String)propertyValue);
		} else if ( propertyValue instanceof Integer ){
			dump.intProperties.put(property, (Integer)propertyValue);
		} else if ( propertyValue instanceof Long) {
			dump.longProperties.put(property, (Long)propertyValue);
		} else if( propertyValue instanceof Double) {
			dump.doubleProperties.put(property, (Double) propertyValue);
		} else if (propertyValue instanceof Short) {
			dump.shortProperties.put(property, (Short)propertyValue);
		} else if (propertyValue instanceof Float) {
			dump.floatProperties.put(property, (Float) propertyValue);
		} else if (propertyValue instanceof Byte) {
			dump.byteProperties.put(property, (Byte)propertyValue);
		} else if (propertyValue instanceof Boolean) {
			dump.boolProperties.put(property, (Boolean)propertyValue);
		} else if (propertyValue instanceof Serializable){
			// Object property.. if it's on Classpath and Serializable
			byte[] propBytes = SerializationUtils.serialize((Serializable) propertyValue);
			dump.objectProperties.put(property, Base64.encodeBase64String(propBytes));
		} else {
			// Corner case.
			throw new IllegalArgumentException("Property of key '"+ property +"' is not serializable. Type is: " + propertyValue.getClass().getCanonicalName());
		}
	}
	
	dump.body = "";
	dump.type = "";
	
	if (msg instanceof TextMessage) {
		dump.body = ((TextMessage)msg).getText();
		dump.type = "TextMessage";
	} else if (msg instanceof BytesMessage) {
		BytesMessage bm = (BytesMessage)msg;
		byte[] bytes = new byte[(int) bm.getBodyLength()];
		bm.readBytes(bytes);
		dump.body = Base64.encodeBase64String(bytes);
		dump.type = "BytesMessage";
	} else if (msg instanceof ObjectMessage) {
		ObjectMessage om = (ObjectMessage)msg;
		byte[] objectBytes = SerializationUtils.serialize(om.getObject());
		dump.body = Base64.encodeBase64String(objectBytes);
		dump.type = "ObjectMessage";
	}
	return dump;
}
 
Example 7
Source File: JmsDupsOkTest.java    From qpid-jms with Apache License 2.0 4 votes vote down vote up
@Override
public void onMessage(Message message) {
    try {
        int msgNumProperty = message.getIntProperty(MESSAGE_NUMBER);

        if(complete ){
            LOG.info("Test already finished, ignoring delivered message: " + msgNumProperty);
            return;
        }

        if (msgNumProperty == 1) {
            if (!seenFirstMessage) {
                LOG.info("Received first message.");
                seenFirstMessage = true;
            } else {
                LOG.error("Received first message again.");
                complete(true);
            }
        } else if (msgNumProperty == 2) {
            if(!seenSecondMessage){
                seenSecondMessage = true;
                LOG.info("Received second message. Now calling recover()");
                session.recover();
            } else {
                LOG.info("Received second message again as expected.");
                seenSecondMessageTwice = true;
                if(message.getJMSRedelivered()) {
                    LOG.info("Message was marked redelivered as expected.");
                } else {
                    LOG.error("Message was not marked redelivered.");
                    complete(true);
                }
            }
        } else {
            if (msgNumProperty != 3) {
                LOG.error("Received unexpected message: " + msgNumProperty);
                complete(true);
                return;
            }

            if (!(seenFirstMessage && seenSecondMessageTwice)) {
                LOG.error("Third message was not received in expected sequence.");
                complete(true);
                return;
            }

            LOG.info("Received third message.");

            if(message.getJMSRedelivered()) {
                LOG.error("Message was marked redelivered against expectation.");
                complete(true);
            } else {
                LOG.info("Message was not marked redelivered, as expected.");
                complete(false);
            }
        }
    } catch (JMSException e) {
        LOG.error("Exception caught in listener", e);
        complete(true);
    }
}
 
Example 8
Source File: JmsAutoAckTest.java    From qpid-jms with Apache License 2.0 4 votes vote down vote up
@Override
public void onMessage(Message message) {
    try {
        int msgNumProperty = message.getIntProperty(MESSAGE_NUMBER);

        if(complete ){
            LOG.info("Test already finished, ignoring delivered message: " + msgNumProperty);
            return;
        }

        if (msgNumProperty == 1) {
            if (!seenFirstMessage) {
                LOG.info("Received first message.");
                seenFirstMessage = true;
            } else {
                LOG.error("Received first message again.");
                complete(true);
            }
        } else if (msgNumProperty == 2) {
            if(!seenSecondMessage){
                seenSecondMessage = true;
                LOG.info("Received second message. Now calling recover()");
                session.recover();
            } else {
                LOG.info("Received second message again as expected.");
                seenSecondMessageTwice = true;
                if(message.getJMSRedelivered()) {
                    LOG.info("Message was marked redelivered as expected.");
                } else {
                    LOG.error("Message was not marked redelivered.");
                    complete(true);
                }
            }
        } else {
            if (msgNumProperty != 3) {
                LOG.error("Received unexpected message: " + msgNumProperty);
                complete(true);
                return;
            }

            if (!(seenFirstMessage && seenSecondMessageTwice)) {
                LOG.error("Third message was not received in expected sequence.");
                complete(true);
                return;
            }

            LOG.info("Received third message.");

            if(message.getJMSRedelivered()) {
                LOG.error("Message was marked redelivered against expectation.");
                complete(true);
            } else {
                LOG.info("Message was not marked redelivered, as expected.");
                complete(false);
            }
        }
    } catch (JMSException e) {
        LOG.error("Exception caught in listener", e);
        complete(true);
    }
}
 
Example 9
Source File: JmsClientAckTest.java    From qpid-jms with Apache License 2.0 4 votes vote down vote up
@Override
public void onMessage(Message message) {
    try {
        int msgNumProperty = message.getIntProperty(MESSAGE_NUMBER);

        if(complete ){
            LOG.info("Test already finished, ignoring delivered message: " + msgNumProperty);
            return;
        }

        if (msgNumProperty == 1) {
            if (!seenFirstMessage) {
                LOG.info("Received first message.");
                seenFirstMessage = true;
            } else {
                LOG.info("Received first message again.");
                if(message.getJMSRedelivered()) {
                    LOG.info("Message was marked redelivered as expected.");
                } else {
                    LOG.error("Message was not marked redelivered.");
                    complete(true);
                }
                seenFirstMessageTwice = true;
            }
        } else if (msgNumProperty == 2) {
            if(!seenSecondMessage){
                seenSecondMessage = true;
                LOG.info("Received second message. Now calling recover()");
                session.recover();
            } else {
                if (!seenFirstMessageTwice) {
                    LOG.error("Received second message again before seeing first message again.");
                    complete(true);
                    return;
                }

                LOG.info("Received second message again as expected.");
                seenSecondMessageTwice = true;

                if(message.getJMSRedelivered()) {
                    LOG.info("Message was marked redelivered as expected.");
                } else {
                    LOG.error("Message was not marked redelivered.");
                    complete(true);
                }
            }
        } else {
            if (msgNumProperty != 3) {
                LOG.error("Received unexpected message: " + msgNumProperty);
                complete(true);
                return;
            }

            if (!(seenFirstMessageTwice && seenSecondMessageTwice)) {
                LOG.error("Third message was not received in expected sequence.");
                complete(true);
                return;
            }

            if(message.getJMSRedelivered()) {
                LOG.error("Message was marked redelivered against expectation.");
                complete(true);
            } else {
                LOG.info("Message was not marked redelivered, as expected.");
                complete(false);
            }
        }
    } catch (JMSException e) {
        LOG.error("Exception caught in listener", e);
        complete(true);
    }
}