List of usage examples for com.rabbitmq.client ConnectionFactory setAutomaticRecoveryEnabled
public void setAutomaticRecoveryEnabled(boolean automaticRecovery)
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 av 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);/*from w w w . ja v a 2 s . c om*/ 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 ww . j av a2s . 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.geoserver.notification.support.Receiver.java
License:Open Source License
protected ConnectionFactory createConnectionFactory() throws Exception { ConnectionFactory factory = new ConnectionFactory(); factory.setAutomaticRecoveryEnabled(false); factory.setUri(BROKER_URI);/*w ww .j a v a 2 s .co m*/ return factory; }
From source file:org.iplantcollaborative.ClientRegistrar.java
License:Apache License
public void connect() throws IOException, TimeoutException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost(this.serverConf.getHostname()); factory.setPort(this.serverConf.getPort()); factory.setUsername(this.serverConf.getUserId()); factory.setPassword(this.serverConf.getUserPwd()); factory.setVirtualHost(this.serverConf.getVhostPublish()); factory.setAutomaticRecoveryEnabled(true); this.connection = factory.newConnection(); this.channel = this.connection.createChannel(); LOG.info("client registrar connected - " + this.serverConf.getHostname() + ":" + this.serverConf.getPort()); this.channel.basicQos(1); this.channel.queueBind(QUEUE_NAME, EXCHANGE_NAME, "#"); this.consumer = new DefaultConsumer(this.channel) { @Override/*from w w w. j a v a2s .c om*/ public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException { String message = new String(body, "UTF-8"); LOG.info("registration - " + message); BasicProperties replyProps = new BasicProperties.Builder() .correlationId(properties.getCorrelationId()).build(); ARequest request = RequestFactory.getRequestInstance(message); // handle lease request if (request instanceof RequestLease) { ResponseLease res = lease((RequestLease) request); String response_json = serializer.toJson(res); if (properties.getReplyTo() != null) { channel.basicPublish("", properties.getReplyTo(), replyProps, response_json.getBytes()); } else { LOG.error("unable to return response. reply_to field is null"); } } else { LOG.error("Unknown request : " + message); } channel.basicAck(envelope.getDeliveryTag(), false); } }; this.workerThread = new Thread(new Runnable() { @Override public void run() { try { channel.basicConsume(QUEUE_NAME, false, consumer); LOG.info("Waiting for registrations"); } catch (IOException ex) { LOG.error("Exception occurred while consuming message", ex); } } }); this.workerThread.start(); }
From source file:org.iplantcollaborative.DataStoreMessageReceiver.java
License:Apache License
public void connect() throws IOException, TimeoutException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost(this.serverConf.getHostname()); factory.setPort(this.serverConf.getPort()); factory.setUsername(this.serverConf.getUserId()); factory.setPassword(this.serverConf.getUserPwd()); factory.setVirtualHost(this.serverConf.getVhostSubscribe()); factory.setAutomaticRecoveryEnabled(true); this.connection = factory.newConnection(); this.channel = this.connection.createChannel(); LOG.info("subscriber connected - " + this.serverConf.getHostname() + ":" + this.serverConf.getPort()); this.channel.basicQos(1); this.queueName = this.channel.queueDeclare().getQueue(); this.channel.queueBind(this.queueName, EXCHANGE_NAME, "#"); this.consumer = new DefaultConsumer(this.channel) { @Override/*from w w w .ja va2 s .c om*/ public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException { String message = new String(body, "UTF-8"); LOG.debug("subscribe - " + envelope.getRoutingKey() + ":" + message); DataStoreMessageProcessor processor = binder.getProcessor(); if (processor != null) { processor.process(envelope.getRoutingKey(), message); } else { LOG.error("processor not registered"); } channel.basicAck(envelope.getDeliveryTag(), false); } }; this.workerThread = new Thread(new Runnable() { @Override public void run() { try { channel.basicConsume(queueName, consumer); LOG.info("Waiting for messages"); } catch (IOException ex) { LOG.error("Exception occurred while consuming a message", ex); } } }); this.workerThread.start(); }
From source file:org.iplantcollaborative.MessagePublisher.java
License:Apache License
public void connect() throws IOException, TimeoutException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost(this.serverConf.getHostname()); factory.setPort(this.serverConf.getPort()); factory.setUsername(this.serverConf.getUserId()); factory.setPassword(this.serverConf.getUserPwd()); factory.setVirtualHost(this.serverConf.getVhostPublish()); factory.setAutomaticRecoveryEnabled(true); this.connection = factory.newConnection(); this.channel = this.connection.createChannel(); this.channel.basicQos(1); LOG.info("publisher connected - " + this.serverConf.getHostname() + ":" + this.serverConf.getPort()); }
From source file:org.kairosdb.plugin.rabbitmq.core.RabbitmqService.java
License:MIT License
@Override public void start() throws KairosDBException { try {//from www . java 2s .c o m LOGGER.info("[KRMQ] Starting to RabbitMQ consumer thread."); // Socket abstract connection with broker ConnectionFactory rabbitmqConnectionFactory = new ConnectionFactory(); rabbitmqConnectionFactory.setHost(rabbmitmqHost); rabbitmqConnectionFactory.setVirtualHost(rabbitmqVirtualHost); rabbitmqConnectionFactory.setUsername(rabbitmqUser); rabbitmqConnectionFactory.setPassword(rabbitmqPassword); rabbitmqConnectionFactory.setPort(rabbitmqPort); rabbitmqConnectionFactory.setConnectionTimeout(rabbitmqTimeout); rabbitmqConnectionFactory.setRequestedChannelMax(rabbitmqChannelMax); rabbitmqConnectionFactory.setRequestedFrameMax(rabbitmqFrameMax); rabbitmqConnectionFactory.setRequestedHeartbeat(rabbitmqHearbeat); rabbitmqConnectionFactory.setAutomaticRecoveryEnabled(true); // Get KairosDatastore implementation KairosDatastore kairosDatabase = googleInjector.getInstance(KairosDatastore.class); // Create consumer thread RabbitmqConsumer consumer = new RabbitmqConsumer(kairosDatabase, rabbitmqConnectionFactory, bindingsFile, configurationJSONFieldValue, configurationJSONTimeStamp, configurationJSONTags, configurationCSVSeperator, configurationDefaultContentType); // Start consumer thread consumerThread = new Thread(consumer); consumerThread.start(); } catch (Exception e) { LOGGER.error("[KRMQ] An error occurred: ", e); } }
From source file:org.onosproject.rabbitmq.impl.MQSender.java
License:Apache License
@Override public void start() { ConnectionFactory factory = new ConnectionFactory(); factory.setAutomaticRecoveryEnabled(true); factory.setNetworkRecoveryInterval(RECOVERY_INTERVAL); try {//w ww. j a v a 2 s. c om factory.setUri(url); if (executorService != null) { conn = factory.newConnection(executorService); } else { conn = factory.newConnection(); } channel = conn.createChannel(); channel.exchangeDeclare(exchangeName, TOPIC, true); /* * Setting the following parameters to queue * durable - true * exclusive - false * autoDelete - false * arguments - null */ channel.queueDeclare(this.queueName, true, false, false, null); channel.queueBind(queueName, exchangeName, routingKey); } catch (Exception e) { log.error(E_CREATE_CHAN, e); } }
From source file:org.opendaylight.federationmessagequeue.impl.RabbitMessageBus.java
License:Open Source License
@Override public boolean createQueue(String queueName, String mqBrokerIp, int mqPortNumber, String mqUser, String mqUserPwd) {//from www. j a va 2 s . c o m LOG.info("Creating connection for queue {} on broker {}", queueName, mqBrokerIp); ConnectionFactory factory = new ConnectionFactory(); factory.setHost(mqBrokerIp); factory.setPort(mqPortNumber); factory.setUsername(mqUser); factory.setPassword(mqUserPwd); factory.setAutomaticRecoveryEnabled(true); try { Connection connection = factory.newConnection(); LOG.info("Created connection to broker {}:{} for user {} ", mqBrokerIp, mqPortNumber, mqUser); Channel channel = connection.createChannel(); channel.queueDeclare(queueName, false, false, false, null); LOG.info("Declared queue {} on broker {}", queueName, mqBrokerIp); MessageBusConnectionData mbcd = new MessageBusConnectionData(mqBrokerIp, connection, channel); queueNameToConnectionData.put(queueName, mbcd); return true; } catch (IOException | TimeoutException e) { LOG.warn("Failed creating queue {} on broker {}:{} for user {} because: {}", queueName, mqBrokerIp, mqPortNumber, mqUser, e.getMessage()); return false; } }