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

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

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

Connection.close介绍

暂无

代码示例

代码示例来源:origin: apache/flink

@Override
public void close() throws Exception {
  super.close();
  try {
    if (connection != null) {
      connection.close();
    }
  } catch (IOException e) {
    throw new RuntimeException("Error while closing RMQ connection with " + queueName
      + " at " + rmqConnectionConfig.getHost(), e);
  }
}

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

@Override
 public void close() throws IOException
 {
  log.info("Closing connection to RabbitMQ");
  channel.close();
  connection.close();
 }
};

代码示例来源:origin: apache/flink

@Override
public void close() {
  Exception t = null;
  try {
    if (channel != null) {
      channel.close();
    }
  } catch (IOException | TimeoutException e) {
    t = e;
  }
  try {
    if (connection != null) {
      connection.close();
    }
  } catch (IOException e) {
    if (t != null) {
      LOG.warn("Both channel and connection closing failed. Logging channel exception and failing with connection exception", t);
    }
    t = e;
  }
  if (t != null) {
    throw new RuntimeException("Error while closing RMQ connection with " + queueName
        + " at " + rmqConnectionConfig.getHost(), t);
  }
}

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

public void stop() throws IOException {
  if (channel != null && channel.isOpen()) {
    try {
      channel.close();
    } catch (TimeoutException e) {
      LOG.error("Timeout when closing AMQP channel", e);
      channel.abort();
    }
  }
  if (connection != null && connection.isOpen()) {
    connection.close();
  }
}

代码示例来源:origin: apache/nifi

@Override
public void close() throws IOException {
  IOException ioe = null;
  try {
    worker.close();
  } catch (final IOException e) {
    ioe = e;
  } catch (final TimeoutException e) {
    ioe = new IOException(e);
  }
  try {
    connection.close();
  } catch (final IOException e) {
    if (ioe == null) {
      ioe = e;
    } else {
      ioe.addSuppressed(e);
    }
  }
  if (ioe != null) {
    throw ioe;
  }
}

代码示例来源:origin: yacy/yacy_grid_mcp

@Override
public void close() {
  this.queues.clear();
  try {
    this.channel.close();
  } catch (IOException | TimeoutException e) {}
  try {
    this.connection.close();
  } catch (IOException e) {}
  this.queues = null;
}

代码示例来源:origin: vector4wang/spring-boot-quick

public static void main(String[] args) {
    try {
      ConnectionFactory factory = new ConnectionFactory();
      factory.setUsername("guest");
      factory.setPassword("guest");
      factory.setHost("60.205.191.82");
      factory.setPort(5672);
      Connection conn = factory.newConnection();
      Channel channel = conn.createChannel();

//            channel.qu
      channel.queueDeclare("hello", false, false, false, null);
      String message = "Hello World!";
      channel.basicPublish("", "hello", null, message.getBytes());
      System.out.println(" [x] Sent '" + message + "'");

      channel.close();
      conn.close();
    } catch (IOException e) {
      e.printStackTrace();
    } catch (TimeoutException e) {
      e.printStackTrace();
    }
  }
}

代码示例来源:origin: io.dropwizard.metrics/metrics-graphite

@Override
public void close() throws IOException {
  if (connection != null) {
    connection.close();
  }
}

代码示例来源:origin: org.smartdeveloperhub.curator/sdh-curator-connector

private void closeConnectionQuietly() {
  if(this.connection!=null) {
    try {
      this.connection.close();
    } catch (final Exception e) {
      LOGGER.trace("Could not close connection gracefully",e);
    }
    this.connection=null;
  }
}

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

private void testNackOrRequeue(boolean requeue) throws IOException, TimeoutException {
  Channel channel = mock(Channel.class);
  willReturn(true).given(channel).isOpen();
  Envelope envelope = new Envelope(123L, false, "ex", "rk");
  BasicProperties props = new BasicProperties.Builder().build();
  GetResponse getResponse = new GetResponse(envelope, props, "bar".getBytes(), 0);
  willReturn(getResponse).given(channel).basicGet("foo", false);
  Connection connection = mock(Connection.class);
  willReturn(true).given(connection).isOpen();
  willReturn(channel).given(connection).createChannel();
  ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
  willReturn(connection).given(connectionFactory).newConnection((ExecutorService) isNull(), anyString());
  CachingConnectionFactory ccf = new CachingConnectionFactory(connectionFactory);
  AmqpMessageSource source = new AmqpMessageSource(ccf, "foo");
  Message<?> received = source.receive();
  verify(connection).createChannel();
  StaticMessageHeaderAccessor.getAcknowledgmentCallback(received)
      .acknowledge(requeue ? Status.REQUEUE : Status.REJECT);
  verify(channel).basicReject(123L, requeue);
  verify(connection).createChannel();
  ccf.destroy();
  verify(channel).close();
  verify(connection).close(30000);
}

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

ccf.destroy();
verify(channel, times(2)).close();
verify(connection).close(30000);

代码示例来源:origin: addthis/hydra

@Override public void close() throws IOException {
  if (channel != null) {
    try {
      channel.close();
    } catch (TimeoutException e) {
      log.warn("[rabbit.producer] error timeout", e);
    }
  }
  if (connection != null) {
    connection.close();
  }
}

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

@Override
public void close() {
  try {
    this.explicitlyClosed = true;
    // let the physical close time out if necessary
    this.delegate.close(this.closeTimeout);
  }
  catch (IOException e) {
    throw RabbitExceptionTranslator.convertRabbitAccessException(e);
  }
}

代码示例来源:origin: org.graylog2/gelfj

public void close() {
    shutdown = true;
    try {
      channel.close();
    } catch (Exception e) {
    }
    try {
      connection.close();
    } catch (Exception e) {
    }
  }
}

代码示例来源:origin: org.geoserver.community/gs-notification-common

public void close() throws Exception {
  if (this.channel != null) {
    this.channel.close();
  }
  if (this.conn != null) {
    this.conn.close();
  }
}

代码示例来源:origin: de.unibonn.iai.eis/luzzu-io

public static void close() {
  if(connection.isOpen()) {
    try {
      connection.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}

代码示例来源:origin: io.druid.extensions/druid-rabbitmq

@Override
 public void close() throws IOException
 {
  log.info("Closing connection to RabbitMQ");
  channel.close();
  connection.close();
 }
};

代码示例来源:origin: uk.gov.dstl.baleen/baleen-rabbitmq

@Override
 protected void doDestroy() {
  getMonitor().debug("Disconnecting from RabbitMQ");
  try {
   connection.close();
  } catch (final Exception e) {
   getMonitor().error("Could not close connection to RabbitMQ", e);
  }
 }
}

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

@Test
public void test(ConnectionFactory connectionFactory) throws Exception {
  Connection conn = connectionFactory.newConnection();
  Channel channel = conn.createChannel();
  DeclareOk declareOk = channel.queueDeclarePassive("rabbitAvailableTests.queue");
  assertEquals(0, declareOk.getConsumerCount());
  channel.close();
  conn.close();
}

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

@Test
public void test(ConnectionFactory cf) throws Exception {
  assertSame(cf, this.connectionFactory);
  Connection conn = this.connectionFactory.newConnection();
  Channel channel = conn.createChannel();
  DeclareOk declareOk = channel.queueDeclarePassive("rabbitAvailableTests.queue");
  assertEquals(0, declareOk.getConsumerCount());
  channel.close();
  conn.close();
}

相关文章