@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); } }
@Override public void close() throws IOException { log.info("Closing connection to RabbitMQ"); channel.close(); connection.close(); } };
@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); } }
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(); } }
@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; } }
@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; }
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(); } } }
@Override public void close() throws IOException { if (connection != null) { connection.close(); } }
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; } }
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); }
ccf.destroy(); verify(channel, times(2)).close(); verify(connection).close(30000);
@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(); } }
@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); } }
public void close() { shutdown = true; try { channel.close(); } catch (Exception e) { } try { connection.close(); } catch (Exception e) { } } }
public void close() throws Exception { if (this.channel != null) { this.channel.close(); } if (this.conn != null) { this.conn.close(); } }
public static void close() { if(connection.isOpen()) { try { connection.close(); } catch (IOException e) { e.printStackTrace(); } } }
@Override public void close() throws IOException { log.info("Closing connection to RabbitMQ"); channel.close(); connection.close(); } };
@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); } } }
@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(); }
@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(); }