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

The following examples show how to use javax.jms.Message#getJMSDeliveryMode() . 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: ClientJmsDelegate.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
public Message sendNextMessage(final CreateProducerCommand command)
{
    final String messageProviderName = command.getMessageProviderName();
    final MessageProvider messageProvider = getMessageProvider(messageProviderName);

    final Session session = _testSessions.get(command.getSessionName());
    final MessageProducer producer = _testProducers.get(command.getParticipantName());
    try
    {
        Message message = messageProvider.nextMessage(session, command);
        int deliveryMode = producer.getDeliveryMode();
        int priority = producer.getPriority();
        long ttl = producer.getTimeToLive();
        if (messageProvider.isPropertySet(MessageProvider.PRIORITY))
        {
            priority = message.getJMSPriority();
        }
        if (messageProvider.isPropertySet(MessageProvider.DELIVERY_MODE))
        {
            deliveryMode = message.getJMSDeliveryMode();
        }
        if (messageProvider.isPropertySet(MessageProvider.TTL))
        {
            ttl = message.getLongProperty(MessageProvider.TTL);
        }
        producer.send(message, deliveryMode, priority, ttl);
        return message;
    }
    catch (final JMSException jmse)
    {
        throw new DistributedTestException("Unable to create and send message with producer: " +
                        command.getParticipantName() + " on session: " + command.getSessionName(), jmse);
    }
}
 
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: A.java    From a with Apache License 2.0 5 votes vote down vote up
protected void outputHeaders(Message msg) {
	output("Message Headers");
	try {
		String deliveryMode = msg.getJMSDeliveryMode() == DeliveryMode.PERSISTENT ? "persistent"
				: "non-persistent";
		output("  JMSCorrelationID: " + msg.getJMSCorrelationID());
		output("  JMSExpiration: "
				+ timestampToString(msg.getJMSExpiration()));
		output("  JMSDeliveryMode: " + deliveryMode);
		output("  JMSMessageID: " + msg.getJMSMessageID());
		output("  JMSPriority: " + msg.getJMSPriority());
		output("  JMSTimestamp: "
				+ timestampToString(msg.getJMSTimestamp()));
		output("  JMSType: " + msg.getJMSType());
		output("  JMSDestination: "
				+ (msg.getJMSDestination() != null ? msg
						.getJMSDestination().toString() : "Not set"));
		output("  JMSRedelivered: "
				+ Boolean.toString(msg.getJMSRedelivered()));
		output("  JMSReplyTo: "
				+ (msg.getJMSReplyTo() != null ? msg.getJMSReplyTo()
						.toString() : "Not set"));
	} catch (JMSException e) {
		// nothing to do here. just ignore.
		logger.debug("Cannot print JMS headers." + e.getMessage());
	}
}
 
Example 4
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 5
Source File: MessageRenderer.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
    Render a {@link javax.jms.Message}.
 */
 public
 String  doRender(Object o) {
   if(o instanceof Message) {
     StringBuffer sbuf = new StringBuffer();
     Message m = (Message) o;
     try {
sbuf.append("DeliveryMode=");
switch(m.getJMSDeliveryMode()) {
case DeliveryMode.NON_PERSISTENT :
  sbuf.append("NON_PERSISTENT");
  break;
case DeliveryMode.PERSISTENT :
  sbuf.append("PERSISTENT");
  break;
default: sbuf.append("UNKNOWN");
}
sbuf.append(", CorrelationID=");
sbuf.append(m.getJMSCorrelationID());

sbuf.append(", Destination=");
sbuf.append(m.getJMSDestination());

sbuf.append(", Expiration=");
sbuf.append(m.getJMSExpiration());

sbuf.append(", MessageID=");
sbuf.append(m.getJMSMessageID());

sbuf.append(", Priority=");
sbuf.append(m.getJMSPriority());

sbuf.append(", Redelivered=");
sbuf.append(m.getJMSRedelivered());

sbuf.append(", ReplyTo=");
sbuf.append(m.getJMSReplyTo());

sbuf.append(", Timestamp=");
sbuf.append(m.getJMSTimestamp());

sbuf.append(", Type=");
sbuf.append(m.getJMSType());

//Enumeration enum = m.getPropertyNames();
//while(enum.hasMoreElements()) {
//  String key = (String) enum.nextElement();
//  sbuf.append("; "+key+"=");
//  sbuf.append(m.getStringProperty(key));
//}

     } catch(JMSException e) {
LogLog.error("Could not parse Message.", e);
     }
     return sbuf.toString();
   } else {
     return o.toString();
   }
 }
 
Example 6
Source File: MessageRenderer.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Render a {@link Message}.
 */
public String doRender(final Object o) {

   if (o instanceof Message) {
      final StringBuilder sbuf = new StringBuilder(100);
      final Message m = (Message) o;
      try {
         sbuf.append("DeliveryMode=");
         switch (m.getJMSDeliveryMode()) {
            case DeliveryMode.NON_PERSISTENT:
               sbuf.append("NON_PERSISTENT");
               break;
            case DeliveryMode.PERSISTENT:
               sbuf.append("PERSISTENT");
               break;
            default:
               sbuf.append("UNKNOWN");
         }
         sbuf.append(", CorrelationID=");
         sbuf.append(m.getJMSCorrelationID());

         sbuf.append(", Destination=");
         sbuf.append(m.getJMSDestination());

         sbuf.append(", Expiration=");
         sbuf.append(m.getJMSExpiration());

         sbuf.append(", MessageID=");
         sbuf.append(m.getJMSMessageID());

         sbuf.append(", Priority=");
         sbuf.append(m.getJMSPriority());

         sbuf.append(", Redelivered=");
         sbuf.append(m.getJMSRedelivered());

         sbuf.append(", ReplyTo=");
         sbuf.append(m.getJMSReplyTo());

         sbuf.append(", Timestamp=");
         sbuf.append(m.getJMSTimestamp());

         sbuf.append(", Type=");
         sbuf.append(m.getJMSType());

         //Enumeration enum = m.getPropertyNames();
         //while(enum.hasMoreElements()) {
         //  String key = (String) enum.nextElement();
         //  sbuf.append("; "+key+"=");
         //  sbuf.append(m.getStringProperty(key));
         //}

      } catch (final JMSException e) {
         LogLog.error("Could not parse Message.", e);
      }
      return sbuf.toString();
   } else {
      return o.toString();
   }
}
 
Example 7
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 8
Source File: MessageRenderer.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
/**
 Render a {@link javax.jms.Message}.
 */
public
String  doRender(Object obj) {
    if (obj instanceof Message) {
        StringBuilder sb = new StringBuilder();
        Message message = (Message) obj;
        try {
            sb.append("DeliveryMode=");
            switch(message.getJMSDeliveryMode()) {
                case DeliveryMode.NON_PERSISTENT :
                    sb.append("NON_PERSISTENT");
                    break;
                case DeliveryMode.PERSISTENT :
                    sb.append("PERSISTENT");
                    break;
                default: sb.append("UNKNOWN");
            }
            sb.append(", CorrelationID=");
            sb.append(message.getJMSCorrelationID());

            sb.append(", Destination=");
            sb.append(message.getJMSDestination());

            sb.append(", Expiration=");
            sb.append(message.getJMSExpiration());

            sb.append(", MessageID=");
            sb.append(message.getJMSMessageID());

            sb.append(", Priority=");
            sb.append(message.getJMSPriority());

            sb.append(", Redelivered=");
            sb.append(message.getJMSRedelivered());

            sb.append(", ReplyTo=");
            sb.append(message.getJMSReplyTo());

            sb.append(", Timestamp=");
            sb.append(message.getJMSTimestamp());

            sb.append(", Type=");
            sb.append(message.getJMSType());

        } catch(JMSException e) {
            LOGGER.error("Could not parse Message.", e);
        }
        return sb.toString();
    } else {
        return obj.toString();
    }
}