List of usage examples for org.springframework.amqp.rabbit.connection Connection close
@Override void close() throws AmqpException;
From source file:org.springframework.amqp.rabbit.connection.CachingConnectionFactoryTests.java
@Test @Ignore // Test to verify log message is suppressed after patch to CCF public void testReturnsNormalCloseDeferredClose() throws Exception { com.rabbitmq.client.ConnectionFactory mockConnectionFactory = mock( com.rabbitmq.client.ConnectionFactory.class); com.rabbitmq.client.Connection mockConnection = mock(com.rabbitmq.client.Connection.class); Channel mockChannel = mock(Channel.class); when(mockConnectionFactory.newConnection(any(ExecutorService.class), anyString())) .thenReturn(mockConnection); when(mockConnection.isOpen()).thenReturn(true); when(mockConnection.createChannel()).thenReturn(mockChannel); when(mockChannel.isOpen()).thenReturn(true); doThrow(new ShutdownSignalException(true, false, new com.rabbitmq.client.AMQP.Connection.Close.Builder().replyCode(200).replyText("OK").build(), null)).when(mockChannel).close(); CachingConnectionFactory ccf = new CachingConnectionFactory(mockConnectionFactory); ccf.setPublisherReturns(true);//from w ww .ja v a2s .c om ccf.setExecutor(Executors.newSingleThreadExecutor()); Connection conn = ccf.createConnection(); Channel channel = conn.createChannel(false); RabbitUtils.setPhysicalCloseRequired(channel, true); channel.close(); Thread.sleep(6000); }
From source file:org.springframework.amqp.rabbit.connection.RabbitUtils.java
/** * Close the given RabbitMQ Connection and ignore any thrown exception. This is useful for typical * <code>finally</code> blocks in manual RabbitMQ code. * @param connection the RabbitMQ Connection to close (may be <code>null</code>) */// w w w.j a va2 s . co m public static void closeConnection(Connection connection) { if (connection != null) { try { connection.close(); } catch (Exception ex) { logger.debug("Ignoring Connection exception - assuming already closed: " + ex); } } }