@Bean
  public RedeliveryPolicy defaultRedeliveryPolicy() {
    final RedeliveryPolicy redeliveryPolicy = new RedeliveryPolicy();
    redeliveryPolicy.setInitialRedeliveryDelay(
        Long.parseLong(
            this.environment.getRequiredProperty(
                PROPERTY_NAME_JMS_DEFAULT_INITIAL_REDELIVERY_DELAY)));
    redeliveryPolicy.setMaximumRedeliveries(
        Integer.parseInt(
            this.environment.getRequiredProperty(PROPERTY_NAME_JMS_DEFAULT_MAXIMUM_REDELIVERIES)));
    redeliveryPolicy.setMaximumRedeliveryDelay(
        Long.parseLong(
            this.environment.getRequiredProperty(
                PROPERTY_NAME_JMS_DEFAULT_MAXIMUM_REDELIVERY_DELAY)));
    redeliveryPolicy.setRedeliveryDelay(
        Long.parseLong(
            this.environment.getRequiredProperty(PROPERTY_NAME_JMS_DEFAULT_REDELIVERY_DELAY)));
    redeliveryPolicy.setBackOffMultiplier(
        Double.parseDouble(
            this.environment.getRequiredProperty(PROPERTY_NAME_JMS_DEFAULT_BACK_OFF_MULTIPLIER)));
    redeliveryPolicy.setUseExponentialBackOff(
        Boolean.parseBoolean(
            this.environment.getRequiredProperty(
                PROPERTY_NAME_JMS_DEFAULT_USE_EXPONENTIAL_BACK_OFF)));

    return redeliveryPolicy;
  }
 @Bean
 public RedeliveryPolicy osgpResponsesRedeliveryPolicy() {
   final RedeliveryPolicy redeliveryPolicy = new RedeliveryPolicy();
   redeliveryPolicy.setInitialRedeliveryDelay(
       Long.parseLong(
           this.environment.getRequiredProperty(
               PROPERTY_NAME_JMS_OSGP_RESPONSES_INITIAL_REDELIVERY_DELAY)));
   redeliveryPolicy.setMaximumRedeliveries(
       Integer.parseInt(
           this.environment.getRequiredProperty(
               PROPERTY_NAME_JMS_OSGP_RESPONSES_MAXIMUM_REDELIVERIES)));
   redeliveryPolicy.setMaximumRedeliveryDelay(
       Long.parseLong(
           this.environment.getRequiredProperty(
               PROPERTY_NAME_JMS_OSGP_RESPONSES_MAXIMUM_REDELIVERY_DELAY)));
   redeliveryPolicy.setRedeliveryDelay(
       Long.parseLong(
           this.environment.getRequiredProperty(
               PROPERTY_NAME_JMS_OSGP_RESPONSES_REDELIVERY_DELAY)));
   redeliveryPolicy.setDestination(this.dlmsRequestsQueue());
   redeliveryPolicy.setBackOffMultiplier(
       Double.parseDouble(
           this.environment.getRequiredProperty(
               PROPERTY_NAME_JMS_OSGP_RESPONSES_BACK_OFF_MULTIPLIER)));
   redeliveryPolicy.setUseExponentialBackOff(
       Boolean.parseBoolean(
           this.environment.getRequiredProperty(
               PROPERTY_NAME_JMS_OSGP_RESPONSES_USE_EXPONENTIAL_BACK_OFF)));
   return redeliveryPolicy;
 }
Ejemplo n.º 3
0
 @Bean(name = "domainAdminIncomingOsgpCoreRequestsRedeliveryPolicy")
 public RedeliveryPolicy incomingOsgpCoreRequestsRedeliveryPolicy() {
   final RedeliveryPolicy redeliveryPolicy = new RedeliveryPolicy();
   redeliveryPolicy.setInitialRedeliveryDelay(
       Long.parseLong(
           this.environment.getRequiredProperty(
               PROPERTY_NAME_JMS_INCOMING_OSGP_CORE_REQUESTS_INITIAL_REDELIVERY_DELAY)));
   redeliveryPolicy.setMaximumRedeliveries(
       Integer.parseInt(
           this.environment.getRequiredProperty(
               PROPERTY_NAME_JMS_INCOMING_OSGP_CORE_REQUESTS_MAXIMUM_REDELIVERIES)));
   redeliveryPolicy.setMaximumRedeliveryDelay(
       Long.parseLong(
           this.environment.getRequiredProperty(
               PROPERTY_NAME_JMS_INCOMING_OSGP_CORE_REQUESTS_MAXIMUM_REDELIVERY_DELAY)));
   redeliveryPolicy.setRedeliveryDelay(
       Long.parseLong(
           this.environment.getRequiredProperty(
               PROPERTY_NAME_JMS_INCOMING_OSGP_CORE_REQUESTS_REDELIVERY_DELAY)));
   redeliveryPolicy.setDestination(this.incomingOsgpCoreRequestsQueue());
   redeliveryPolicy.setBackOffMultiplier(
       Double.parseDouble(
           this.environment.getRequiredProperty(
               PROPERTY_NAME_JMS_INCOMING_OSGP_CORE_REQUESTS_BACK_OFF_MULTIPLIER)));
   redeliveryPolicy.setUseExponentialBackOff(
       Boolean.parseBoolean(
           this.environment.getRequiredProperty(
               PROPERTY_NAME_JMS_INCOMING_OSGP_CORE_REQUESTS_USE_EXPONENTIAL_BACK_OFF)));
   return redeliveryPolicy;
 }
Ejemplo n.º 4
0
    private synchronized QueueConnection newQueueConnection() throws Exception {

      if (connectionFactory == null) {
        connectionFactory = new ActiveMQConnectionFactory(amqUser, amqPassword, activemqURL);
      }

      // Set the redelivery count to -1 (infinite), or else messages will start dropping
      // after the queue has had a certain number of failures (default is 6)
      RedeliveryPolicy policy = connectionFactory.getRedeliveryPolicy();
      policy.setMaximumRedeliveries(-1);

      QueueConnection amqConnection = connectionFactory.createQueueConnection();
      amqConnection.start();
      return amqConnection;
    }
Ejemplo n.º 5
0
  @Bean
  public RedeliveryPolicy defaultRedeliveryPolicy() {
    final RedeliveryPolicy redeliveryPolicy = new RedeliveryPolicy();
    redeliveryPolicy.setInitialRedeliveryDelay(
        Long.parseLong(
            this.environment.getRequiredProperty(
                PROPERTY_NAME_JMS_DEFAULT_INITIAL_REDELIVERY_DELAY)));
    redeliveryPolicy.setMaximumRedeliveries(
        Integer.parseInt(
            this.environment.getRequiredProperty(PROPERTY_NAME_JMS_DEFAULT_MAXIMUM_REDELIVERIES)));
    redeliveryPolicy.setMaximumRedeliveryDelay(
        Long.parseLong(
            this.environment.getRequiredProperty(
                PROPERTY_NAME_JMS_DEFAULT_MAXIMUM_REDELIVERY_DELAY)));
    redeliveryPolicy.setRedeliveryDelay(
        Long.parseLong(
            this.environment.getRequiredProperty(PROPERTY_NAME_JMS_DEFAULT_REDELIVERY_DELAY)));

    return redeliveryPolicy;
  }
Ejemplo n.º 6
0
  private void startBroker(boolean deleteMessages) throws Exception {
    broker = new BrokerService();
    broker.setPersistent(false);
    broker.setSchedulerSupport(true);

    RedeliveryPlugin redeliveryPlugin = new RedeliveryPlugin();

    RedeliveryPolicy brokerRedeliveryPolicy = new RedeliveryPolicy();
    brokerRedeliveryPolicy.setRedeliveryDelay(redeliveryDelayMillis);
    brokerRedeliveryPolicy.setInitialRedeliveryDelay(initialRedeliveryDelayMillis);
    brokerRedeliveryPolicy.setMaximumRedeliveries(maxBrokerRedeliveries);

    RedeliveryPolicyMap redeliveryPolicyMap = new RedeliveryPolicyMap();
    redeliveryPolicyMap.setDefaultEntry(brokerRedeliveryPolicy);
    redeliveryPlugin.setRedeliveryPolicyMap(redeliveryPolicyMap);

    broker.setPlugins(new BrokerPlugin[] {redeliveryPlugin});

    if (deleteMessages) {
      broker.setDeleteAllMessagesOnStartup(true);
    }
    broker.start();
  }
Ejemplo n.º 7
0
  public void doTestScheduledRedelivery(int maxBrokerRedeliveriesToValidate, boolean validateDLQ)
      throws Exception {

    startBroker(true);
    sendMessage(0);

    ActiveMQConnection consumerConnection = (ActiveMQConnection) createConnection();
    RedeliveryPolicy redeliveryPolicy = new RedeliveryPolicy();
    redeliveryPolicy.setInitialRedeliveryDelay(0);
    redeliveryPolicy.setMaximumRedeliveries(0);
    consumerConnection.setRedeliveryPolicy(redeliveryPolicy);
    consumerConnection.start();
    Session consumerSession = consumerConnection.createSession(true, Session.SESSION_TRANSACTED);
    MessageConsumer consumer = consumerSession.createConsumer(destination);
    Message message = consumer.receive(1000);
    assertNotNull("got message", message);
    LOG.info("got: " + message);
    consumerSession.rollback();

    for (int i = 0; i < maxBrokerRedeliveriesToValidate; i++) {
      Message shouldBeNull = consumer.receive(500);
      assertNull(
          "did not get message after redelivery count exceeded: " + shouldBeNull, shouldBeNull);

      TimeUnit.SECONDS.sleep(4);

      Message brokerRedeliveryMessage = consumer.receive(1500);
      LOG.info("got: " + brokerRedeliveryMessage);
      assertNotNull("got message via broker redelivery after delay", brokerRedeliveryMessage);
      assertEquals(
          "message matches",
          message.getStringProperty("data"),
          brokerRedeliveryMessage.getStringProperty("data"));
      assertEquals(
          "has expiryDelay specified - iteration:" + i,
          i == 0 ? initialRedeliveryDelayMillis : redeliveryDelayMillis,
          brokerRedeliveryMessage.getLongProperty(RedeliveryPlugin.REDELIVERY_DELAY));

      consumerSession.rollback();
    }

    if (validateDLQ) {
      MessageConsumer dlqConsumer =
          consumerSession.createConsumer(
              new ActiveMQQueue(SharedDeadLetterStrategy.DEFAULT_DEAD_LETTER_QUEUE_NAME));
      Message dlqMessage = dlqConsumer.receive(2000);
      assertNotNull("Got message from dql", dlqMessage);
      assertEquals(
          "message matches",
          message.getStringProperty("data"),
          dlqMessage.getStringProperty("data"));
      consumerSession.commit();
    } else {
      // consume/commit ok
      message = consumer.receive(3000);
      assertNotNull("got message", message);
      assertEquals(
          "redeliveries accounted for",
          maxBrokerRedeliveriesToValidate + 2,
          message.getLongProperty("JMSXDeliveryCount"));
      consumerSession.commit();
    }

    consumerConnection.close();
  }