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 camel by apache.
the class RabbitMQComponent method createEndpoint.
@Override
protected RabbitMQEndpoint createEndpoint(String uri, String remaining, Map<String, Object> params) throws Exception {
URI host = new URI("http://" + remaining);
String hostname = host.getHost();
int portNumber = host.getPort();
// We need to support the exchange to be "" the path is empty
String exchangeName = "";
if (host.getPath().trim().length() > 1) {
exchangeName = host.getPath().substring(1);
}
// ConnectionFactory reference
ConnectionFactory connectionFactory = resolveAndRemoveReferenceParameter(params, "connectionFactory", ConnectionFactory.class);
@SuppressWarnings("unchecked") Map<String, Object> clientProperties = resolveAndRemoveReferenceParameter(params, "clientProperties", Map.class);
TrustManager trustManager = resolveAndRemoveReferenceParameter(params, "trustManager", TrustManager.class);
RabbitMQEndpoint endpoint;
if (connectionFactory == null) {
endpoint = new RabbitMQEndpoint(uri, this);
} else {
endpoint = new RabbitMQEndpoint(uri, this, connectionFactory);
}
endpoint.setHostname(hostname);
endpoint.setPortNumber(portNumber);
endpoint.setExchangeName(exchangeName);
endpoint.setClientProperties(clientProperties);
endpoint.setTrustManager(trustManager);
setProperties(endpoint, params);
if (LOG.isDebugEnabled()) {
LOG.debug("Creating RabbitMQEndpoint with host {}:{} and exchangeName: {}", new Object[] { endpoint.getHostname(), endpoint.getPortNumber(), endpoint.getExchangeName() });
}
HashMap<String, Object> args = new HashMap<>();
args.putAll(IntrospectionSupport.extractProperties(params, ARG_PREFIX));
endpoint.setArgs(args);
HashMap<String, Object> argsCopy = new HashMap<>(args);
// Combine the three types of rabbit arguments with their individual endpoint properties
endpoint.getExchangeArgs().putAll(IntrospectionSupport.extractProperties(argsCopy, EXCHANGE_ARG_PREFIX));
endpoint.getQueueArgs().putAll(IntrospectionSupport.extractProperties(argsCopy, QUEUE_ARG_PREFIX));
endpoint.getBindingArgs().putAll(IntrospectionSupport.extractProperties(argsCopy, BINDING_ARG_PREFIX));
return endpoint;
}
use of com.rabbitmq.client.ConnectionFactory in project camel by apache.
the class RabbitMQConnectionFactorySupport method createFactoryFor.
public ConnectionFactory createFactoryFor(final RabbitMQEndpoint endpoint) {
ConnectionFactory factory = new ConnectionFactory();
factory.setUsername(endpoint.getUsername());
factory.setPassword(endpoint.getPassword());
factory.setVirtualHost(endpoint.getVhost());
factory.setHost(endpoint.getHostname());
factory.setPort(endpoint.getPortNumber());
if (endpoint.getClientProperties() != null) {
factory.setClientProperties(endpoint.getClientProperties());
}
factory.setConnectionTimeout(endpoint.getConnectionTimeout());
factory.setRequestedChannelMax(endpoint.getRequestedChannelMax());
factory.setRequestedFrameMax(endpoint.getRequestedFrameMax());
factory.setRequestedHeartbeat(endpoint.getRequestedHeartbeat());
if (endpoint.getSslProtocol() != null) {
try {
if (endpoint.getSslProtocol().equals("true")) {
factory.useSslProtocol();
} else if (endpoint.getTrustManager() == null) {
factory.useSslProtocol(endpoint.getSslProtocol());
} else {
factory.useSslProtocol(endpoint.getSslProtocol(), endpoint.getTrustManager());
}
} catch (NoSuchAlgorithmException | KeyManagementException e) {
throw new IllegalArgumentException("Invalid sslProtocol " + endpoint.getSslProtocol(), e);
}
}
if (endpoint.getAutomaticRecoveryEnabled() != null) {
factory.setAutomaticRecoveryEnabled(endpoint.getAutomaticRecoveryEnabled());
}
if (endpoint.getNetworkRecoveryInterval() != null) {
factory.setNetworkRecoveryInterval(endpoint.getNetworkRecoveryInterval());
}
if (endpoint.getTopologyRecoveryEnabled() != null) {
factory.setTopologyRecoveryEnabled(endpoint.getTopologyRecoveryEnabled());
}
return factory;
}
use of com.rabbitmq.client.ConnectionFactory in project camel by apache.
the class AbstractRabbitMQIntTest method connection.
/**
* Helper method for creating a rabbitmq connection to the test instance of the
* rabbitmq server.
* @return
* @throws IOException
* @throws TimeoutException
*/
protected Connection connection() throws IOException, TimeoutException {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
factory.setPort(5672);
factory.setUsername("cameltest");
factory.setPassword("cameltest");
factory.setVirtualHost("/");
return factory.newConnection();
}
use of com.rabbitmq.client.ConnectionFactory in project uavstack by uavorg.
the class DoTestRabbitmqProxy method main.
public static void main(String[] args) {
ConsoleLogger cl = new ConsoleLogger("test");
cl.setDebugable(true);
UAVServer.instance().setLog(cl);
UAVServer.instance().putServerInfo(CaptureConstants.INFO_APPSERVER_VENDOR, ServerVendor.TOMCAT);
RabbitmqHookProxy p = new RabbitmqHookProxy("test", Collections.emptyMap());
p.doInstallDProxy(null, "testApp");
ConnectionFactory factory = new ConnectionFactory();
factory.setUsername("guest");
factory.setPassword("guest");
factory.setHost("127.0.0.1");
factory.setPort(5672);
try {
conn = factory.newConnection();
channel = conn.createChannel();
channel.queueDeclare(QUEUE_NAME, false, false, false, null);
channel.queueDeclare("aaa", false, false, false, null);
new Thread(new Runnable() {
@Override
public void run() {
String message = "Hello World!";
while (true) {
try {
channel.basicPublish("", QUEUE_NAME, null, message.getBytes("UTF-8"));
// System.out.println(" [x] Sent '" + message + "'");
channel.basicPublish("", "aaa", null, "aaame".getBytes("UTF-8"));
// System.out.println(" [x] Sent 'aaame'");
Thread.sleep(1000);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}).start();
Connection connection = factory.newConnection();
Channel recvchannel = connection.createChannel();
recvchannel.queueDeclare(QUEUE_NAME, false, false, false, null);
recvchannel.queueDeclare("aaa", false, false, false, null);
Consumer consumer = new DefaultConsumer(recvchannel) {
@Override
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
String message = new String(body, "UTF-8");
// System.out.println(" [x] Received '" + message + "'1");
}
};
recvchannel.basicConsume(QUEUE_NAME, true, consumer);
String consumerTag = recvchannel.basicConsume("aaa", true, consumer);
try {
Thread.sleep(50000);
recvchannel.basicCancel(consumerTag);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (TimeoutException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Aggregations