List of usage examples for com.rabbitmq.client ExceptionHandler ExceptionHandler
ExceptionHandler
From source file:org.eclipse.hono.dispatcher.amqp.AmqpConnection.java
License:Open Source License
private static Connection createConnection(final String amqpUri) throws NoSuchAlgorithmException, KeyManagementException, URISyntaxException, IOException, TimeoutException { final ConnectionFactory factory = new ConnectionFactory(); AmqpConnection.LOGGER.info("Connecting to " + amqpUri); factory.setUri(amqpUri);/* www .j a va 2s. c om*/ factory.setRequestedHeartbeat(60); factory.setAutomaticRecoveryEnabled(true); factory.setTopologyRecoveryEnabled(true); factory.setExceptionHandler(new ExceptionHandler() { @Override public void handleUnexpectedConnectionDriverException(final Connection conn, final Throwable exception) { AmqpConnection.LOGGER.warn("UnexpectedConnectionDriverException", exception); } @Override public void handleReturnListenerException(final Channel channel, final Throwable exception) { AmqpConnection.LOGGER.warn("ReturnListenerException", exception); } @Override public void handleFlowListenerException(final Channel channel, final Throwable exception) { AmqpConnection.LOGGER.warn("FlowListenerException", exception); } @Override public void handleConfirmListenerException(final Channel channel, final Throwable exception) { AmqpConnection.LOGGER.warn("ConfirmListenerException", exception); } @Override public void handleBlockedListenerException(final Connection connection, final Throwable exception) { AmqpConnection.LOGGER.warn("BlockedListenerException", exception); } @Override public void handleConsumerException(final Channel channel, final Throwable exception, final Consumer consumer, final String consumerTag, final String methodName) { AmqpConnection.LOGGER.warn("ConsumerException", exception); } @Override public void handleConnectionRecoveryException(final Connection conn, final Throwable exception) { AmqpConnection.LOGGER.warn("ConnectionRecoveryException", exception); } @Override public void handleChannelRecoveryException(final Channel ch, final Throwable exception) { AmqpConnection.LOGGER.warn("ChannelRecoveryException", exception); } @Override public void handleTopologyRecoveryException(final Connection conn, final Channel ch, final TopologyRecoveryException exception) { AmqpConnection.LOGGER.warn("TopologyRecoveryException", exception); } }); return factory.newConnection(); }
From source file:org.flockdata.client.amqp.FdRabbitClient.java
License:Apache License
private void initConnectionFactory() throws IOException, TimeoutException { if (connectionFactory == null) { logger.debug("Initializing Rabbit connection"); entityProps = null;/*from w ww .j ava 2s . c om*/ tagProps = null; // Had issues with injecting amqpRabbitConfig.connectionFactory into this class // Connection was randomly closed in integration tests connectionFactory = new ConnectionFactory(); connectionFactory.setAutomaticRecoveryEnabled(true); connectionFactory.setHost(rabbitConfig.getHost()); connectionFactory.setPort(rabbitConfig.getPort()); connectionFactory.setPassword(rabbitConfig.getPass()); connectionFactory.setUsername(rabbitConfig.getUser()); connectionFactory.setExceptionHandler(new ExceptionHandler() { @Override public void handleUnexpectedConnectionDriverException(Connection conn, Throwable exception) { logger.info(exception.getMessage()); } @Override public void handleReturnListenerException(Channel channel, Throwable exception) { logger.info(exception.getMessage()); } @Override public void handleFlowListenerException(Channel channel, Throwable exception) { logger.info(exception.getMessage()); } @Override public void handleConfirmListenerException(Channel channel, Throwable exception) { logger.info(exception.getMessage()); } @Override public void handleBlockedListenerException(Connection connection, Throwable exception) { logger.info(exception.getMessage()); } @Override public void handleConsumerException(Channel channel, Throwable exception, Consumer consumer, String consumerTag, String methodName) { logger.info(exception.getMessage()); } @Override public void handleConnectionRecoveryException(Connection conn, Throwable exception) { } @Override public void handleChannelRecoveryException(Channel ch, Throwable exception) { logger.info(exception.getMessage()); } @Override public void handleTopologyRecoveryException(Connection conn, Channel ch, TopologyRecoveryException exception) { logger.info(exception.getMessage()); } }); } }