/** * Validates that {@link Connection} is not null and open. * * @param connection instance of {@link Connection} */ private void validateConnection(Connection connection) { if (connection == null) { throw new IllegalArgumentException("'connection' must not be null!"); } if (!connection.isOpen()) { throw new IllegalStateException("'connection' must be open!"); } } }
public boolean isConnected() { return connection != null && connection.isOpen() && channel != null && channel.isOpen(); }
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(); } }
private void init() throws IOException { ConnectionFactory factory = new ConnectionFactory(); factory.setAutomaticRecoveryEnabled(true); factory.setHost(this.server); if (this.port > 0) factory.setPort(this.port); if (this.username != null && this.username.length() > 0) factory.setUsername(this.username); if (this.password != null && this.password.length() > 0) factory.setPassword(this.password); try { this.connection = factory.newConnection(); //Map<String, Object> map = this.connection.getServerProperties(); if (!this.connection.isOpen()) throw new IOException("no connection"); this.channel = connection.createChannel(); if (!this.channel.isOpen()) throw new IOException("no channel"); this.queues = new ConcurrentHashMap<>(); } catch (TimeoutException e) { throw new IOException(e.getMessage()); } }
public boolean isConnected() { synchronized (monitor) { return connection != null && connection.isOpen(); } }
public boolean isOpen(){ if(connection!=null){ return connection.isOpen(); } return false; }
@Override public boolean isConnected() { boolean connected = false; if (connection != null) { if (connection.isOpen()) { connected = true; } } return connected; }
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); }
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);
public boolean isConnected() { return connection != null && connection.isOpen() && channel != null && channel.isOpen(); }
public boolean isConnected() { return connection != null && connection.isOpen() && channel != null && channel.isOpen(); }
public static void close() { if(connection.isOpen()) { try { connection.close(); } catch (IOException e) { e.printStackTrace(); } } }
public static void closeConnection(Connection connection) throws Exception { try { if(connection != null && connection.isOpen()) { log.info("Closing RabbitMQ connection."); connection.close(); } } catch(com.rabbitmq.client.AlreadyClosedException e) { log.info("RabbitMQ connection already closed."); } }
public boolean isConnected() { return connection != null && connection.isOpen() && channel != null && channel.isOpen(); }
private synchronized Connection getOrCreateConnection(ChannelType connectionType) throws IOException { if (conToChannel.containsKey(connectionType)) { if (conToChannel.get(connectionType).connection.isOpen()) { return conToChannel.get(connectionType).connection; }else{ //TODO not covered in tests conToChannel.remove(connectionType); } } return createConnection(connectionType); }
public TriplePublisher() { if(connection == null || channel == null || !connection.isOpen() || !channel.isOpen()) { connect(); } }
public TriplePublisher() { if(connection == null || channel == null || !connection.isOpen() || !channel.isOpen()) { connect(); } }
public void close() { try { if(channel.isOpen()) { channel.close(); } if(connection.isOpen()) { connection.close(); } } catch (IOException e) { logger.warn("Error closing channel or connection to MQ service", e); } }
public void close() { try { if(channel.isOpen()) { channel.close(); } if(connection.isOpen()) { connection.close(); } } catch (IOException | TimeoutException e) { logger.warn("Error closing channel or connection to MQ service", e); } }
private Boolean isConnected() throws IOException, TimeoutException { try (Connection connection = rabbitMQ.connectionFactory().newConnection()) { return connection.isOpen(); } }