Java Code Examples for javax.jms.TextMessage#setJMSDeliveryMode()

The following examples show how to use javax.jms.TextMessage#setJMSDeliveryMode() . 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: BaseTest.java    From a with Apache License 2.0 5 votes vote down vote up
private TextMessage createTextMessage(String testCorrId, String stringPropertyValue, String utfText, Queue replyQueue) throws JMSException {
    final TextMessage tm1 = session.createTextMessage(utfText);
    tm1.setStringProperty("myStringProperty", stringPropertyValue);
    tm1.setIntProperty("myIntProperty", 42);
    tm1.setDoubleProperty("myDoubleProperty", Math.PI);
    tm1.setJMSType("myJmsType");
    tm1.setJMSCorrelationID(testCorrId);
    tm1.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
    tm1.setJMSPriority(2);
    tm1.setJMSReplyTo(replyQueue);
    return tm1;
}
 
Example 2
Source File: JMSEventMarshaller.java    From cougar with Apache License 2.0 5 votes vote down vote up
@Override
public TextMessage marshallEvent(EventServiceBindingDescriptor bindingDescriptor, Event event, Object session) throws CougarException {
    try {
        TextMessage message = ((Session)session).createTextMessage(marshallEventBody(event));

        //Sets the routing string
        message.setStringProperty(JMSPropertyConstants.MESSAGE_ROUTING_FIELD_NAME, getHostString(event));

        //Sets the message id guid.  If there isn't one, make one up
        String messageId = event.getMessageId();
        if (messageId == null) {
            messageId = new RequestUUIDImpl().toString();
        }
        message.setStringProperty(JMSPropertyConstants.MESSAGE_ID_FIELD_NAME, messageId);

        //Sets the version header
        message.setStringProperty(JMSPropertyConstants.EVENT_VERSION_FIELD_NAME, bindingDescriptor.getServiceVersion().toString());

        //Sets the event name header
        message.setStringProperty(JMSPropertyConstants.EVENT_NAME_FIELD_NAME, event.getClass().getSimpleName());

        message.setBooleanProperty("JMS_SonicMQ_preserveUndelivered", true);
        message.setBooleanProperty("JMS_SonicMQ_notifyUndelivered",   true);
        message.setJMSDeliveryMode(deliveryMode);
        message.setJMSExpiration(expirationTime);
        message.setJMSPriority(priority);

        return message;
    } catch (JMSException jmsex) {
        throw new CougarFrameworkException("Error marshalling Event", jmsex);
    } catch (UnknownHostException e) {
        throw new CougarFrameworkException("Error looking up local host name", e);
    }
}
 
Example 3
Source File: LargeMessageQueueAutoCreationTest.java    From activemq-artemis with Apache License 2.0 2 votes vote down vote up
private void sendStringOfSize(int msgSize) throws JMSException {

      ConnectionFactory factoryToUse = usingCore ? coreCf : factory;

      Connection conn = factoryToUse.createConnection();

      try {
         Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

         MessageProducer prod = session.createProducer(queue1);

         TextMessage m = session.createTextMessage();

         m.setJMSDeliveryMode(DeliveryMode.PERSISTENT);

         StringBuffer buffer = new StringBuffer();
         while (buffer.length() < msgSize) {
            buffer.append(UUIDGenerator.getInstance().generateStringUUID());
         }

         final String originalString = buffer.toString();

         m.setText(originalString);

         prod.send(m);

         conn.close();

         conn = factoryToUse.createConnection();

         session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

         MessageConsumer cons = session.createConsumer(queue1);

         conn.start();

         TextMessage rm = (TextMessage) cons.receive(5000);
         Assert.assertNotNull(rm);

         String str = rm.getText();
         Assert.assertEquals(originalString, str);
      } finally {
         if (conn != null) {
            conn.close();
         }
      }
   }
 
Example 4
Source File: QueueAutoCreationTest.java    From activemq-artemis with Apache License 2.0 2 votes vote down vote up
private void sendStringOfSize(int msgSize, boolean useCoreReceive) throws JMSException {

      Connection conn = this.createConnection();

      try {
         Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

         MessageProducer prod = session.createProducer(queue1);

         TextMessage m = session.createTextMessage();

         m.setJMSDeliveryMode(DeliveryMode.PERSISTENT);

         StringBuffer buffer = new StringBuffer();
         while (buffer.length() < msgSize) {
            buffer.append(UUIDGenerator.getInstance().generateStringUUID());
         }

         final String originalString = buffer.toString();

         m.setText(originalString);

         prod.send(m);

         conn.close();

         if (useCoreReceive) {
            conn = createCoreConnection();
         } else {
            conn = createConnection();
         }

         session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

         MessageConsumer cons = session.createConsumer(queue1);

         conn.start();

         TextMessage rm = (TextMessage) cons.receive(5000);
         Assert.assertNotNull(rm);

         String str = rm.getText();
         Assert.assertEquals(originalString, str);
      } finally {
         if (conn != null) {
            conn.close();
         }
      }
   }