Exemplo n.º 1
0
  /**
   * Asserts that a failure from a channel listener during recovery results in the channel being
   * recovered.
   */
  public void shouldHandleRecoveryFailureFromChannelListener() throws Throwable {
    config =
        new Config()
            .withRetryPolicy(RetryPolicies.retryAlways().withRetryInterval(Duration.millis(10)))
            .withRecoveryPolicy(RetryPolicies.retryAlways())
            .withChannelListeners(
                new DefaultChannelListener() {
                  @Override
                  public void onRecovery(Channel channel) {
                    try {
                      channel.queueDelete("test-queue");
                    } catch (IOException e) {
                    }
                  }
                });

    performRecovery(nonRetryableChannelShutdownSignal(), 1);
    verifyCxnCreations(2);
    verifyChannelCreations(1, 2);
    verifyChannelCreations(2, 7);
    verifyConsumerCreations(1, 1, 2);
    verifyConsumerCreations(1, 2, 2);
    verifyConsumerCreations(2, 5, 4);
    verifyConsumerCreations(2, 6, 7);
  }
  @PostConstruct
  public void start() throws IOException, TimeoutException {
    // millis
    connectionFactory.setConnectionTimeout(1000);
    // seconds
    connectionFactory.setRequestedHeartbeat(4);
    // lyra reconnect logic
    Config config =
        new Config()
            .withRecoveryPolicy(
                new RecoveryPolicy().withMaxAttempts(-1).withInterval(Duration.seconds(1)))
            .withChannelListeners(this);

    ConnectionOptions connectionOptions =
        new ConnectionOptions(connectionFactory).withAddresses(rabbitmqHosts);
    connectionOptions.withUsername(username);
    connectionOptions.withPassword(password);
    // create single connection
    // clientConnection = connectionFactory.newConnection(Address.parseAddresses(rabbitmqHosts));
    clientConnection = Connections.create(connectionOptions, config);
    // create a seperate producer and a seperate consumer channel
    consumerChannel = clientConnection.createChannel();
    producerChannel = clientConnection.createChannel();
    // ensure the exchange is there
    consumerChannel.exchangeDeclare(exchangeName, "direct", true);
    if (ackType == BUFFERED) {
      messageAcker = new BufferingMessageAcker(consumerChannel);
    } else if (ackType == WRITE_BEHIND) {
      messageAcker = new WriteBehindMessageAcker(consumerChannel);
    } else if (ackType == ASYNC) {
      messageAcker = new AsyncMessageAcker(consumerChannel);
    } else {
      messageAcker = new DirectMessageAcker(consumerChannel);
    }
    messageAcker.start();
  }
Exemplo n.º 3
0
 /**
  * Set the requested heartbeat, zero for none.
  *
  * @throws NullPointerException if {@code requestedHeartbeat} is null
  */
 public ConnectionOptions withRequestedHeartbeat(Duration requestedHeartbeat) {
   factory.setRequestedHeartbeat((int) requestedHeartbeat.toMillis());
   return this;
 }
Exemplo n.º 4
0
 /**
  * Set the connection timeout, zero for infinite, for an individual connection attempt.
  *
  * @throws NullPointerException if {@code connectionTimeout} is null
  */
 public ConnectionOptions withConnectionTimeout(Duration connectionTimeout) {
   factory.setConnectionTimeout((int) connectionTimeout.toMillis());
   return this;
 }