List of usage examples for com.rabbitmq.client ConnectionFactory setNetworkRecoveryInterval
public void setNetworkRecoveryInterval(long networkRecoveryInterval)
From source file:org.wso2.carbon.event.adaptor.rabbitmq.internal.EventAdapterHelper.java
License:Apache License
/** * <pre>/* w w w. j ava 2s . c o m*/ * Create a rabbitmq ConnectionFactory instance * </pre> * @param hostName * @param port * @param userName * @param password * @param virtualHost * @return */ public synchronized static ConnectionFactory getConnectionFactory(String hostName, int port, String userName, String password, String virtualHost) { ConnectionFactory factory = new ConnectionFactory(); factory.setHost(hostName); factory.setPort(port); factory.setUsername(userName); factory.setPassword(password); factory.setVirtualHost(virtualHost); /** * Add connection recovery logic * @author Sang-Cheon Park * @date 2015.07.16 */ /** * connection that will recover automatically */ factory.setAutomaticRecoveryEnabled(true); /** * attempt recovery every 5 seconds */ factory.setNetworkRecoveryInterval(5 * 1000); /** * wait maximum 10 seconds to connect(if connection failed, will be retry to connect after 5 seconds) */ factory.setConnectionTimeout(10 * 1000); return factory; }
From source file:reactor.rabbitmq.ConnectionRecoveryTests.java
License:Open Source License
@BeforeEach public void init() throws Exception { ConnectionFactory connectionFactory = new ConnectionFactory(); connectionFactory.useNio();/*from w ww.ja va2 s. c o m*/ connectionFactory.setNetworkRecoveryInterval(RECOVERY_INTERVAL); connection = connectionFactory.newConnection(); Channel channel = connection.createChannel(); String queueName = UUID.randomUUID().toString(); queue = channel.queueDeclare(queueName, false, false, false, null).getQueue(); channel.close(); receiver = null; sender = null; connectionMono = Mono.just(connectionFactory.newConnection()).cache(); }
From source file:rmq.sender.impl.MQSender.java
License:Apache License
@Override public void start() { SSLContext c = null;/* w w w . ja v a2s . co m*/ try { char[] pass = "changeit".toCharArray(); KeyStore tks = KeyStore.getInstance("JKS"); tks.load(new FileInputStream( "/root/test-project/topology-current/" + "/src/main/resources/client/client_cacerts.jks"), pass); TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509"); tmf.init(tks); c = SSLContext.getInstance("TLSv1.2"); c.init(null, tmf.getTrustManagers(), null); } catch (Exception e) { log.error(E_CREATE_CHAN, e); } ConnectionFactory factory = new ConnectionFactory(); factory.setAutomaticRecoveryEnabled(true); factory.setNetworkRecoveryInterval(RECOVERY_INTERVAL); factory.useSslProtocol(c); try { 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, true, null); channel.queueBind(queueName, exchangeName, routingKey); } catch (Exception e) { log.error(E_CREATE_CHAN, e); } log.info("Connection started"); }
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/*from w ww. ja 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 a v a 2 s . c o 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); * */ }