List of usage examples for com.rabbitmq.client ConnectionFactory setExceptionHandler
public void setExceptionHandler(ExceptionHandler exceptionHandler)
From source file:com.paxxis.cornerstone.messaging.service.amqp.AMQPServiceBusConnector.java
License:Apache License
protected void initConnection() { try {// www . ja v a 2 s . co m ConnectionFactory factory = new ConnectionFactory(); factory.setHost(host); factory.setPort(port); factory.setAutomaticRecoveryEnabled(autoRecover); factory.setConnectionTimeout(timeout); factory.setNetworkRecoveryInterval(recoveryInterval); factory.setRequestedHeartbeat(heartbeat); factory.setTopologyRecoveryEnabled(autoTopologyRecover); factory.setExceptionHandler(exceptionHandler); connection = factory.newConnection(); session = (AMQPSession) createSession(); } catch (IOException e) { logger.error(e); throw new RuntimeException(e); } }
From source file:org.eclipse.ditto.services.connectivity.messaging.rabbitmq.ConnectionBasedRabbitConnectionFactoryFactory.java
License:Open Source License
@Override public ConnectionFactory createConnectionFactory(final Connection connection, final ExceptionHandler exceptionHandler) { checkNotNull(connection, "Connection"); checkNotNull(exceptionHandler, "Exception Handler"); try {//from www .j a v a 2s . com final ConnectionFactory connectionFactory = new CustomConnectionFactory(); if (SECURE_AMQP_SCHEME.equalsIgnoreCase(connection.getProtocol())) { if (connection.isValidateCertificates()) { final SSLContextCreator sslContextCreator = SSLContextCreator.fromConnection(connection, null); connectionFactory.useSslProtocol(sslContextCreator.withoutClientCertificate()); } else { // attention: this accepts all certificates whether they are valid or not connectionFactory.useSslProtocol(); } } connectionFactory.setUri(connection.getUri()); // this makes no difference as the used newmotion client always sets the AutomaticRecoveryEnabled to false: connectionFactory.setAutomaticRecoveryEnabled(connection.isFailoverEnabled()); connectionFactory.setExceptionHandler(exceptionHandler); configureConnectionFactory(connectionFactory, connection.getSpecificConfig()); return connectionFactory; } catch (final NoSuchAlgorithmException | KeyManagementException | URISyntaxException e) { LOGGER.warn(e.getMessage()); throw new IllegalStateException("Failed to create RabbitMQ connection factory.", e); } }
From source file:org.eclipse.hono.client.AmqpConnectionManagerImpl.java
License:Open Source License
private Connection createConnection(final ConnectionConfig connectionConfig) throws NoSuchAlgorithmException, KeyManagementException, URISyntaxException, IOException, TimeoutException { final ConnectionFactory factory = new ConnectionFactory(); final String amqpUri = connectionConfig.getConnectionUri(); AmqpConnectionManagerImpl.LOGGER.info("Connecting to " + amqpUri); factory.setUri(amqpUri);/*w w w.j a v a 2 s.c o m*/ factory.setAutomaticRecoveryEnabled(true); factory.setExceptionHandler(new DefaultExceptionHandler()); return factory.newConnection(); }
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);//w w w . ja v a 2 s. c o m 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.smartdeveloperhub.curator.connector.BrokerController.java
License:Apache License
void connect() throws ControllerException { this.write.lock(); try {// w ww . j a v a 2 s . c om if (this.connected) { return; } final ConnectionFactory factory = new ConnectionFactory(); factory.setHost(this.broker.host()); factory.setPort(this.broker.port()); factory.setVirtualHost(this.broker.virtualHost()); factory.setThreadFactory(brokerThreadFactory()); factory.setExceptionHandler(new BrokerControllerExceptionHandler(this)); this.connection = factory.newConnection(); createChannel(); } catch (IOException | TimeoutException e) { this.connected = false; final String message = String.format("Could not connect to broker at %s:%s using virtual host %s", this.broker.host(), this.broker.port(), this.broker.virtualHost()); throw new ControllerException(message, e); } finally { this.write.unlock(); } }
From source file:org.smartdeveloperhub.harvesters.it.notification.ConnectionManager.java
License:Apache License
void connect() throws ControllerException { this.lock.lock(); try {/*w w w . j a va 2 s . c om*/ if (connected()) { return; } final ConnectionFactory factory = new ConnectionFactory(); factory.setHost(this.brokerHost); factory.setPort(this.brokerPort); factory.setVirtualHost(this.virtualHost); factory.setThreadFactory(brokerThreadFactory()); factory.setExceptionHandler(new ConnectionManagerExceptionHandler(this)); this.connection = factory.newConnection(); createChannel(); } catch (IOException | TimeoutException e) { final String message = String.format("Could not connect to broker at %s:%s using virtual host %s", this.brokerHost, this.brokerPort, this.virtualHost); throw new ControllerException(this.brokerHost, this.brokerPort, this.virtualHost, message, e); } finally { this.lock.unlock(); } }
From source file:ws.ament.hammock.rabbitmq.ConnectionFactoryProducer.java
License:Apache License
@Produces @ApplicationScoped/* w ww. j a va 2 s.c o m*/ public ConnectionFactory createConnectionFactory(RabbitMQConfiguration rabbitMQConfiguration) { ConnectionFactory connectionFactory = new ConnectionFactory(); connectionFactory.setAutomaticRecoveryEnabled(rabbitMQConfiguration.isAutomaticRecovery()); connectionFactory.setClientProperties(rabbitMQConfiguration.getClientProperties()); connectionFactory.setConnectionTimeout(rabbitMQConfiguration.getConnectionTimeout()); connectionFactory.setExceptionHandler(rabbitMQConfiguration.getExceptionHandler()); connectionFactory.setHandshakeTimeout(rabbitMQConfiguration.getHandshakeTimeout()); connectionFactory.setHeartbeatExecutor(rabbitMQConfiguration.getHeartbeatExecutor()); connectionFactory.setMetricsCollector(rabbitMQConfiguration.getMetricsCollector()); connectionFactory.setHost(rabbitMQConfiguration.getHost()); connectionFactory.setNetworkRecoveryInterval(rabbitMQConfiguration.getNetworkRecoveryInterval()); if (rabbitMQConfiguration.isNio()) { connectionFactory.useNio(); connectionFactory.setNioParams(rabbitMQConfiguration.getNioParams()); } connectionFactory.setPassword(rabbitMQConfiguration.getPassword()); connectionFactory.setPort(rabbitMQConfiguration.getPort()); connectionFactory.setRequestedChannelMax(rabbitMQConfiguration.getRequestedChannelMax()); connectionFactory.setRequestedFrameMax(rabbitMQConfiguration.getRequestedFrameMax()); connectionFactory.setRequestedHeartbeat(rabbitMQConfiguration.getRequestedHeartbeat()); connectionFactory.setSaslConfig(rabbitMQConfiguration.getSaslConfig()); connectionFactory.setSharedExecutor(rabbitMQConfiguration.getSharedExecutor()); connectionFactory.setShutdownExecutor(rabbitMQConfiguration.getShutdownExecutor()); connectionFactory.setShutdownTimeout(rabbitMQConfiguration.getShutdownTimeout()); connectionFactory.setSocketConfigurator(rabbitMQConfiguration.getSocketConf()); connectionFactory.setSocketFactory(rabbitMQConfiguration.getFactory()); connectionFactory.setThreadFactory(rabbitMQConfiguration.getThreadFactory()); connectionFactory.setTopologyRecoveryEnabled(rabbitMQConfiguration.isTopologyRecovery()); try { connectionFactory.setUri(rabbitMQConfiguration.getUri()); } catch (Exception e) { throw new RuntimeException("Unable to populate URI ", e); } connectionFactory.setUsername(rabbitMQConfiguration.getUsername()); connectionFactory.setVirtualHost(rabbitMQConfiguration.getVirtualHost()); if (rabbitMQConfiguration.getSslContext() != null) { connectionFactory.useSslProtocol(rabbitMQConfiguration.getSslContext()); } return connectionFactory; }
From source file:ylj.demo.mq.amqp.rabbitmq_client.DemoConsumer.java
License:Apache License
public static void doConsume() throws Exception { ExecutorService consumeES = Executors.newFixedThreadPool(2); ConnectionFactory factory = new ConnectionFactory(); factory.setUri("amqp://guest:guest@newsrec10.photo.163.org:5672"); // factory.setUri("amqp://guest:guest@/?brokerlist='tcp://newsrec10.photo.163.org:5672'"); factory.setAutomaticRecoveryEnabled(true); factory.setNetworkRecoveryInterval(10000); factory.setExceptionHandler(new MyExceptionHandler()); AutorecoveringConnection conn = (AutorecoveringConnection) factory.newConnection(consumeES); conn.addRecoveryListener(new MyRecoveryListener()); // ?queue??/*from w w w.j av a2 s. co m*/ Channel channel = conn.createChannel(); // channel.close(); // channel.queueDeclare("recsys.news.userfeed.usermodel", false, false, false, null); // channel.basicConsume("recsys.news.userfeed.usermodel", true, null, new MyConsumer()); channel.basicConsume("recsys.news.userfeed.usermodel", new MyConsumer()); // conn.close(); /* * work??work???? channel.basicConsume("hello",false,consumer); channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false); * */ }