Java Code Examples for javax.jms.JMSProducer#setDeliveryDelay()

The following examples show how to use javax.jms.JMSProducer#setDeliveryDelay() . 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: JmsPoolJMSProducerTest.java    From pooled-jms with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeliveryDelay() {
    JMSProducer producer = context.createProducer();

    assertEquals(0, producer.getDeliveryDelay());
    try {
        producer.setDeliveryDelay(2000);
        fail("Pool JMSProducer can't modify shared session delay mode.");
    } catch (JMSRuntimeException jmsre) {
    }
}
 
Example 2
Source File: DeliveryDelayTest.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
/**
 * The client sends a messagge to a fanout exchange instance which is bound to a queue with
 * holdsOnPublish turned off. The Broker must reject the message.
 */
@Test
public void testDeliveryDelayNotSupportedByQueueViaExchange_MessageRejected() throws Exception
{
    try (JMSContext context = getConnectionBuilder().buildConnectionFactory().createContext())
    {
        String testQueueName = BrokerAdmin.TEST_QUEUE_NAME;
        String testExchangeName = "test_exch";

        Destination consumeDest = createQueue(context, testQueueName, false);
        Destination publishDest = createExchange(context, testExchangeName);
        bindQueueToExchange(testExchangeName, testQueueName);


        JMSConsumer consumer = context.createConsumer(consumeDest);
        JMSProducer producer = context.createProducer();

        producer.send(publishDest, "message without delivery delay");

        Message message = consumer.receive(getReceiveTimeout());
        assertNotNull("Message published without delivery delay not received", message);

        producer.setDeliveryDelay(DELIVERY_DELAY);

        try
        {
            producer.send(publishDest, "message with delivery delay");
            fail("Exception not thrown");
        }
        catch (JMSRuntimeException e)
        {
            assertTrue("Unexpected exception message: " + e.getMessage(),
                       e.getMessage().contains("amqp:precondition-failed"));
        }
    }
}
 
Example 3
Source File: JmsProducerTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeliveryDelay() {
    JMSProducer producer = context.createProducer();

    producer.setDeliveryDelay(2000);
    assertEquals(2000, producer.getDeliveryDelay());
}
 
Example 4
Source File: JmsProducerTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
private void doTestSendAppliesDeliveryDelayMessageBody(Class<?> bodyType) throws JMSException {
    JMSProducer producer = context.createProducer();

    // Create matcher to expect the DeliveryTime to be set to a value
    // representing 'now', within a upper delta for execution time.
    long deliveryTimeLower = System.currentTimeMillis();
    long deliveryTimeUpper = deliveryTimeLower + 3000;
    Matcher<Long> inRange = both(greaterThanOrEqualTo(deliveryTimeLower)).and(lessThanOrEqualTo(deliveryTimeUpper));

    sendWithBodyOfType(producer, bodyType);

    JmsOutboundMessageDispatch envelope = remotePeer.getLastReceivedMessage();
    assertNotNull(envelope);
    JmsMessage message = envelope.getMessage();
    assertThat(message.getJMSDeliveryTime(), inRange);

    // Repeat with a non-zero delay
    int deliveryDelay = 123456;
    producer.setDeliveryDelay(deliveryDelay);

    // Create matcher to expect the DeliveryTime to be set to a value
    // representing 'now' + delivery-delay, within a upper delta for execution time.
    deliveryTimeLower = System.currentTimeMillis();
    deliveryTimeUpper = deliveryTimeLower + deliveryDelay + 3000;
    inRange = both(greaterThanOrEqualTo(deliveryTimeLower)).and(lessThanOrEqualTo(deliveryTimeUpper));

    sendWithBodyOfType(producer, bodyType);

    envelope = remotePeer.getLastReceivedMessage();
    assertNotNull(envelope);
    message = envelope.getMessage();
    assertThat(message.getJMSDeliveryTime(), inRange);
}
 
Example 5
Source File: JmsContextTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testDelay() throws Exception {
   JMSProducer producer = context.createProducer();

   JMSConsumer consumer = context.createConsumer(queue1);

   producer.setDeliveryDelay(500);

   long timeStart = System.currentTimeMillis();

   String strRandom = newXID().toString();

   producer.send(queue1, context.createTextMessage(strRandom));

   TextMessage msg = (TextMessage) consumer.receive(2500);

   assertNotNull(msg);

   long actualDelay = System.currentTimeMillis() - timeStart;
   assertTrue("delay is not working, actualDelay=" + actualDelay, actualDelay >= 500 && actualDelay < 2000);

   assertEquals(strRandom, msg.getText());
}
 
Example 6
Source File: JmsProducer.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
private void setOptions( JMSProducer producer ) {
  String optionValue = meta.getDisableMessageId();
  getLogChannel().logDebug( "Disable Message ID is set to " + optionValue );
  if ( !StringUtil.isEmpty( optionValue ) ) {
    producer.setDisableMessageID( BooleanUtils.toBoolean( optionValue ) );
  }

  optionValue = meta.getDisableMessageTimestamp();
  getLogChannel().logDebug( "Disable Message Timestamp is set to " + optionValue );
  if ( !StringUtil.isEmpty( optionValue ) ) {
    producer.setDisableMessageTimestamp( BooleanUtils.toBoolean( optionValue ) );
  }

  optionValue = meta.getDeliveryMode();
  getLogChannel().logDebug( "Delivery Mode is set to " + optionValue );
  if ( !StringUtil.isEmpty( optionValue ) ) {
    producer.setDeliveryMode( Integer.parseInt( optionValue ) );
  }

  optionValue = meta.getPriority();
  getLogChannel().logDebug( "Priority is set to " + optionValue );
  if ( !StringUtil.isEmpty( optionValue ) ) {
    producer.setPriority( Integer.parseInt( optionValue ) );
  }

  optionValue = meta.getTimeToLive();
  getLogChannel().logDebug( "Time to Live is set to " + optionValue );
  if ( !StringUtil.isEmpty( optionValue ) ) {
    producer.setTimeToLive( Long.parseLong( optionValue ) );
  }

  optionValue = meta.getDeliveryDelay();
  getLogChannel().logDebug( "Delivery Delay is set to " + optionValue );
  if ( !StringUtil.isEmpty( optionValue ) ) {
    producer.setDeliveryDelay( Long.parseLong( optionValue ) );
  }

  optionValue = meta.getJmsCorrelationId();
  getLogChannel().logDebug( "JMS Correlation ID is set to " + optionValue );
  if ( !StringUtil.isEmpty( optionValue ) ) {
    producer.setJMSCorrelationID( optionValue );
  }

  optionValue = meta.getJmsType();
  getLogChannel().logDebug( "JMS Type is set to " + optionValue );
  if ( !StringUtil.isEmpty( optionValue ) ) {
    producer.setJMSType( optionValue );
  }
}