List of usage examples for com.rabbitmq.client ConnectionFactory setAutomaticRecoveryEnabled
public void setAutomaticRecoveryEnabled(boolean automaticRecovery)
From source file:uk.ac.sanger.cgp.wwdocker.messages.Messaging.java
License:Open Source License
public Connection getRmqConn() throws IOException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost(config.getString("rabbit_host")); factory.setPort(config.getInt("rabbit_port", 5672)); factory.setUsername(config.getString("rabbit_user")); factory.setPassword(config.getString("rabbit_pw")); factory.setNetworkRecoveryInterval(60000); // retry every 60 seconds factory.setAutomaticRecoveryEnabled(true); return factory.newConnection(); }
From source file:ws.ament.hammock.rabbitmq.ConnectionFactoryProducer.java
License:Apache License
@Produces @ApplicationScoped// w w w .j a v a2 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 a 2 s . com*/ 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); * */ }