com.rabbitmq.client.Connection.addShutdownListener()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(9.7k)|赞(0)|评价(0)|浏览(184)

本文整理了Java中com.rabbitmq.client.Connection.addShutdownListener()方法的一些代码示例,展示了Connection.addShutdownListener()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Connection.addShutdownListener()方法的具体详情如下:
包路径:com.rabbitmq.client.Connection
类名称:Connection
方法名:addShutdownListener

Connection.addShutdownListener介绍

暂无

代码示例

代码示例来源:origin: Graylog2/graylog2-server

connection.addShutdownListener(cause -> {
  if (cause.isInitiatedByApplication()) {
    LOG.info("Shutting down AMPQ consumer.");

代码示例来源:origin: apache/incubator-druid

connection.addShutdownListener(
  new ShutdownListener()

代码示例来源:origin: com.github.combinedmq/combinedmq

@Override
public void addShutdownListener(ShutdownListener listener) {
  connection.addShutdownListener(listener);
}

代码示例来源:origin: ppat/storm-rabbitmq

private Connection createConnection() throws IOException, TimeoutException {
  Connection connection = highAvailabilityHosts == null || highAvailabilityHosts.length == 0 
     ? connectionFactory.newConnection() 
     : connectionFactory.newConnection(highAvailabilityHosts);
  connection.addShutdownListener(new ShutdownListener() {
   @Override
   public void shutdownCompleted(ShutdownSignalException cause) {
    logger.error("shutdown signal received", cause);
    reporter.reportError(cause);
    reset();
   }
  });
  logger.info("connected to rabbitmq: " + connection + " for " + queueName);
  return connection;
 }
}

代码示例来源:origin: joshdevins/rabbitmq-ha-client

/**
 * Creates an {@link HaConnectionProxy} around a raw {@link Connection}.
 */
protected ConnectionSet createConnectionProxy(final Address[] addrs,
    final Connection targetConnection) {
  ClassLoader classLoader = Connection.class.getClassLoader();
  Class<?>[] interfaces = { Connection.class };
  HaConnectionProxy proxy = new HaConnectionProxy(addrs, targetConnection, retryStrategy);
  if (LOG.isDebugEnabled()) {
    LOG
        .debug("Creating connection proxy: "
            + (targetConnection == null ? "none" : targetConnection.toString()));
  }
  Connection target = (Connection) Proxy.newProxyInstance(classLoader, interfaces, proxy);
  HaShutdownListener listener = new HaShutdownListener(proxy);
  // failed initial connections will have this set later upon successful connection
  if (targetConnection != null) {
    target.addShutdownListener(listener);
  }
  return new ConnectionSet(target, proxy, listener);
}

代码示例来源:origin: NationalSecurityAgency/lemongrenade

private Connection createConnection() throws IOException, TimeoutException {
    Connection connection = highAvailabilityHosts == null || highAvailabilityHosts.length == 0
        ? connectionFactory.newConnection()
        : connectionFactory.newConnection(highAvailabilityHosts);

    connection.addShutdownListener(cause -> {
      logger.error("Shutdown signal received", cause);
      reporter.reportError(cause);
      reset();
    });

    logger.info("Connected to rabbitmq: " + connection + " for " + queueName);
    return connection;
  }
}

代码示例来源:origin: org.apache.airavata/airavata-messaging-core

private Connection createConnection() throws IOException {
  try {
    ConnectionFactory connectionFactory = new ConnectionFactory();
    connectionFactory.setUri(url);
    connectionFactory.setAutomaticRecoveryEnabled(true);
    Connection connection = connectionFactory.newConnection();
    connection.addShutdownListener(new ShutdownListener() {
      public void shutdownCompleted(ShutdownSignalException cause) {
      }
    });
    log.info("connected to rabbitmq: " + connection + " for " + exchangeName);
    return connection;
  } catch (Exception e) {
    log.info("connection failed to rabbitmq: " + connection + " for " + exchangeName);
    return null;
  }
}

代码示例来源:origin: vert-x3/vertx-rabbitmq-client

private void connect() throws IOException, TimeoutException {
 log.debug("Connecting to rabbitmq...");
 connection = newConnection(config);
 connection.addShutdownListener(this);
 channel = connection.createChannel();
 log.debug("Connected to rabbitmq !");
}

代码示例来源:origin: awin/rabbiteasy

/**
 * Establishes a new connection.
 *
 * @throws IOException if establishing a new connection fails
 */
void establishConnection () throws IOException {
  synchronized (operationOnConnectionMonitor) {
    if (state == State.CLOSED) {
      throw new IOException("Attempt to establish a connection with a closed connection factory");
    } else if (state == State.CONNECTED) {
      LOGGER.warn("Establishing new connection although a connection is already established");
    }
    try {
      LOGGER.info("Trying to establish connection to {}:{}", getHost(), getPort());
      connection = super.newConnection(executorService);
      connection.addShutdownListener(connectionShutdownListener);
      LOGGER.info("Established connection to {}:{}", getHost(), getPort());
      changeState(State.CONNECTED);
    } catch (IOException e) {
      LOGGER.error("Failed to establish connection to {}:{}", getHost(), getPort());
      throw e;
    }
  }
}

代码示例来源:origin: org.apache.airavata/airavata-messaging-core

private void createConnection() throws AiravataException {
    try {
      ConnectionFactory connectionFactory = new ConnectionFactory();
      connectionFactory.setUri(url);
      connectionFactory.setAutomaticRecoveryEnabled(true);
      connection = connectionFactory.newConnection();
      connection.addShutdownListener(new ShutdownListener() {
        public void shutdownCompleted(ShutdownSignalException cause) {
        }
      });
      log.info("connected to rabbitmq: " + connection + " for " + taskLaunchExchangeName);

      channel = connection.createChannel();
      channel.basicQos(prefetchCount);

//            channel.exchangeDeclare(taskLaunchExchangeName, "fanout");

    } catch (Exception e) {
      String msg = "could not open channel for exchange " + taskLaunchExchangeName;
      log.error(msg);
      throw new AiravataException(msg, e);
    }
  }

代码示例来源:origin: org.apache.airavata/airavata-messaging-core

private void createConnection() throws AiravataException {
  try {
    ConnectionFactory connectionFactory = new ConnectionFactory();
    connectionFactory.setUri(url);
    connectionFactory.setAutomaticRecoveryEnabled(true);
    connection = connectionFactory.newConnection();
    connection.addShutdownListener(new ShutdownListener() {
      public void shutdownCompleted(ShutdownSignalException cause) {
      }
    });
    log.info("connected to rabbitmq: " + connection + " for " + exchangeName);
    channel = connection.createChannel();
    channel.basicQos(prefetchCount);
    channel.exchangeDeclare(exchangeName, EXCHANGE_TYPE, false);
  } catch (Exception e) {
    String msg = "could not open channel for exchange " + exchangeName;
    log.error(msg);
    throw new AiravataException(msg, e);
  }
}

代码示例来源:origin: jhalterman/lyra

public void createConnection(Connection proxy) throws IOException, TimeoutException {
 try {
  this.proxy = proxy;
  createConnection(config.getConnectRetryPolicy(), config.getRetryableExceptions(), false);
  ShutdownListener shutdownListener = new ConnectionShutdownListener();
  shutdownListeners.add(shutdownListener);
  delegate.addShutdownListener(shutdownListener);
  for (ConnectionListener listener : config.getConnectionListeners())
   try {
    listener.onCreate(proxy);
   } catch (Exception ignore) {
   }
 } catch (IOException e) {
  log.error("Failed to create connection {}", connectionName, e);
  connectionClosed();
  for (ConnectionListener listener : config.getConnectionListeners())
   try {
    listener.onCreateFailure(e);
   } catch (Exception ignore) {
   }
  throw e;
 }
}

代码示例来源:origin: net.jodah/lyra

public void createConnection(Connection proxy) throws IOException, TimeoutException {
 try {
  this.proxy = proxy;
  createConnection(config.getConnectRetryPolicy(), config.getRetryableExceptions(), false);
  ShutdownListener shutdownListener = new ConnectionShutdownListener();
  shutdownListeners.add(shutdownListener);
  delegate.addShutdownListener(shutdownListener);
  for (ConnectionListener listener : config.getConnectionListeners())
   try {
    listener.onCreate(proxy);
   } catch (Exception ignore) {
   }
 } catch (IOException e) {
  log.error("Failed to create connection {}", connectionName, e);
  connectionClosed();
  for (ConnectionListener listener : config.getConnectionListeners())
   try {
    listener.onCreateFailure(e);
   } catch (Exception ignore) {
   }
  throw e;
 }
}

代码示例来源:origin: com.sitewhere/sitewhere-rabbit-mq

connection.addShutdownListener(new ShutdownListener() {
public void shutdownCompleted(ShutdownSignalException cause) {
  LOGGER.info("shutdown signal received", cause);

代码示例来源:origin: ppat/storm-rabbitmq

Connection connection = connectionConfig.getHighAvailabilityHosts().isEmpty() ? connectionFactory.newConnection()
  : connectionFactory.newConnection(connectionConfig.getHighAvailabilityHosts().toAddresses());
connection.addShutdownListener(new ShutdownListener() {
 @Override
 public void shutdownCompleted(ShutdownSignalException cause) {

代码示例来源:origin: jhalterman/lyra

delegate.addShutdownListener(listener);

代码示例来源:origin: net.jodah/lyra

delegate.addShutdownListener(listener);

代码示例来源:origin: rabbitmq/rabbitmq-jms-client

/**
 * Creates an RMQConnection object.
 * @param connectionParams parameters for this connection
 */
public RMQConnection(ConnectionParams connectionParams) {
  connectionParams.getRabbitConnection().addShutdownListener(new RMQConnectionShutdownListener());
  this.rabbitConnection = connectionParams.getRabbitConnection();
  this.terminationTimeout = connectionParams.getTerminationTimeout();
  this.queueBrowserReadMax = connectionParams.getQueueBrowserReadMax();
  this.onMessageTimeoutMs = connectionParams.getOnMessageTimeoutMs();
  this.channelsQos = connectionParams.getChannelsQos();
  this.preferProducerMessageProperty = connectionParams.willPreferProducerMessageProperty();
  this.requeueOnMessageListenerException = connectionParams.willRequeueOnMessageListenerException();
  this.cleanUpServerNamedQueuesForNonDurableTopicsOnSessionClose = connectionParams.isCleanUpServerNamedQueuesForNonDurableTopicsOnSessionClose();
  this.amqpPropertiesCustomiser = connectionParams.getAmqpPropertiesCustomiser();
  this.sendingContextConsumer = connectionParams.getSendingContextConsumer();
  this.receivingContextConsumer = connectionParams.getReceivingContextConsumer();
}

代码示例来源:origin: spring-projects/spring-amqp

try {
  template.execute(channel -> {
    channel.getConnection().addShutdownListener(cause -> {
      logger.info("Error", cause);
      latch.countDown();

代码示例来源:origin: sitewhere/sitewhere

connection.addShutdownListener(new ShutdownListener() {
public void shutdownCompleted(ShutdownSignalException cause) {
  getLogger().info("shutdown signal received", cause);

相关文章