use of com.rabbitmq.client.ConnectionFactory in project camel by apache.
the class RabbitMQEndpointTest method testCreateConnectionFactoryCustom.
@Test
public void testCreateConnectionFactoryCustom() throws Exception {
ConnectionFactory connectionFactory = createConnectionFactory("rabbitmq:localhost:1234/exchange" + "?username=userxxx" + "&password=passxxx" + "&connectionTimeout=123" + "&requestedChannelMax=456" + "&requestedFrameMax=789" + "&requestedHeartbeat=987" + "&sslProtocol=true" + "&automaticRecoveryEnabled=true" + "&networkRecoveryInterval=654" + "&topologyRecoveryEnabled=false");
assertEquals("localhost", connectionFactory.getHost());
assertEquals(1234, connectionFactory.getPort());
assertEquals("userxxx", connectionFactory.getUsername());
assertEquals("passxxx", connectionFactory.getPassword());
assertEquals(123, connectionFactory.getConnectionTimeout());
assertEquals(456, connectionFactory.getRequestedChannelMax());
assertEquals(789, connectionFactory.getRequestedFrameMax());
assertEquals(987, connectionFactory.getRequestedHeartbeat());
assertTrue(connectionFactory.isSSL());
assertTrue(connectionFactory.isAutomaticRecoveryEnabled());
assertEquals(654, connectionFactory.getNetworkRecoveryInterval());
assertFalse(connectionFactory.isTopologyRecoveryEnabled());
}
use of com.rabbitmq.client.ConnectionFactory in project flink by apache.
the class RMQSource method open.
@Override
public void open(Configuration config) throws Exception {
super.open(config);
ConnectionFactory factory = setupConnectionFactory();
try {
connection = factory.newConnection();
channel = connection.createChannel();
if (channel == null) {
throw new RuntimeException("None of RabbitMQ channels are available");
}
setupQueue();
consumer = new QueueingConsumer(channel);
RuntimeContext runtimeContext = getRuntimeContext();
if (runtimeContext instanceof StreamingRuntimeContext && ((StreamingRuntimeContext) runtimeContext).isCheckpointingEnabled()) {
autoAck = false;
// enables transaction mode
channel.txSelect();
} else {
autoAck = true;
}
LOG.debug("Starting RabbitMQ source with autoAck status: " + autoAck);
channel.basicConsume(queueName, autoAck, consumer);
} catch (IOException e) {
throw new RuntimeException("Cannot create RMQ connection with " + queueName + " at " + rmqConnectionConfig.getHost(), e);
}
running = true;
}
use of com.rabbitmq.client.ConnectionFactory in project flink by apache.
the class RMQConnectionConfigTest method shouldSetProvidedValueIfConnectionTimeoutNotGiven.
@Test
public void shouldSetProvidedValueIfConnectionTimeoutNotGiven() throws NoSuchAlgorithmException, KeyManagementException, URISyntaxException {
RMQConnectionConfig connectionConfig = new RMQConnectionConfig.Builder().setHost("localhost").setPort(5000).setUserName("guest").setPassword("guest").setVirtualHost("/").setConnectionTimeout(5000).build();
ConnectionFactory factory = connectionConfig.getConnectionFactory();
assertEquals(5000, factory.getConnectionTimeout());
}
use of com.rabbitmq.client.ConnectionFactory in project graylog2-server by Graylog2.
the class AmqpConsumer method connect.
public void connect() throws IOException {
final ConnectionFactory factory = new ConnectionFactory();
factory.setHost(hostname);
factory.setPort(port);
factory.setVirtualHost(virtualHost);
factory.setRequestedHeartbeat(heartbeatTimeout);
if (tls) {
try {
LOG.info("Enabling TLS for AMQP input [{}/{}].", sourceInput.getName(), sourceInput.getId());
factory.useSslProtocol();
} catch (NoSuchAlgorithmException | KeyManagementException e) {
throw new IOException("Couldn't enable TLS for AMQP input.", e);
}
}
// Authenticate?
if (!isNullOrEmpty(username) && !isNullOrEmpty(password)) {
factory.setUsername(username);
factory.setPassword(password);
}
try {
connection = factory.newConnection();
} catch (TimeoutException e) {
throw new IOException("Timeout while opening new AMQP connection", e);
}
channel = connection.createChannel();
if (null == channel) {
LOG.error("No channel descriptor available!");
}
if (null != channel && prefetchCount > 0) {
channel.basicQos(prefetchCount);
LOG.info("AMQP prefetch count overriden to <{}>.", prefetchCount);
}
connection.addShutdownListener(new ShutdownListener() {
@Override
public void shutdownCompleted(ShutdownSignalException cause) {
if (cause.isInitiatedByApplication()) {
LOG.info("Not reconnecting connection, we disconnected explicitly.");
return;
}
while (true) {
try {
LOG.error("AMQP connection lost! Trying reconnect in 1 second.");
Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
connect();
LOG.info("Connected! Re-starting consumer.");
run();
LOG.info("Consumer running.");
break;
} catch (IOException e) {
LOG.error("Could not re-connect to AMQP broker.", e);
}
}
}
});
}
use of com.rabbitmq.client.ConnectionFactory in project flink by apache.
the class RMQSink method open.
@Override
public void open(Configuration config) throws Exception {
ConnectionFactory factory = rmqConnectionConfig.getConnectionFactory();
try {
connection = factory.newConnection();
channel = connection.createChannel();
if (channel == null) {
throw new RuntimeException("None of RabbitMQ channels are available");
}
setupQueue();
} catch (IOException e) {
throw new RuntimeException("Error while creating the channel", e);
}
}
Aggregations