List of usage examples for com.rabbitmq.client ConnectionFactory ConnectionFactory
ConnectionFactory
From source file:org.apache.airavata.messaging.core.impl.RabbitMQProcessLaunchConsumer.java
License:Apache License
private void createConnection() throws AiravataException { try {/*from w w w . java2s.co m*/ ConnectionFactory connectionFactory = new ConnectionFactory(); connectionFactory.setUri(url); connectionFactory.setAutomaticRecoveryEnabled(true); connection = connectionFactory.newConnection(); connection.addShutdownListener(new ShutdownListener() { public void shutdownCompleted(ShutdownSignalException cause) { } }); log.info("connected to rabbitmq: " + connection + " for " + taskLaunchExchangeName); channel = connection.createChannel(); channel.basicQos(prefetchCount); // channel.exchangeDeclare(taskLaunchExchangeName, "fanout"); } catch (Exception e) { String msg = "could not open channel for exchange " + taskLaunchExchangeName; log.error(msg); throw new AiravataException(msg, e); } }
From source file:org.apache.airavata.messaging.core.impl.RabbitMQProducer.java
License:Apache License
private Connection createConnection() throws IOException { try {//www . j av a2 s.co m ConnectionFactory connectionFactory = new ConnectionFactory(); connectionFactory.setUri(url); connectionFactory.setAutomaticRecoveryEnabled(true); Connection connection = connectionFactory.newConnection(); connection.addShutdownListener(new ShutdownListener() { public void shutdownCompleted(ShutdownSignalException cause) { } }); log.info("connected to rabbitmq: " + connection + " for " + exchangeName); return connection; } catch (Exception e) { log.info("connection failed to rabbitmq: " + connection + " for " + exchangeName); return null; } }
From source file:org.apache.airavata.messaging.core.impl.RabbitMQPublisher.java
License:Apache License
private void connect() throws AiravataException { try {/*from ww w . j a va2 s .c o m*/ ConnectionFactory connectionFactory = new ConnectionFactory(); connectionFactory.setUri(properties.getBrokerUrl()); connectionFactory.setAutomaticRecoveryEnabled(properties.isAutoRecoveryEnable()); connection = connectionFactory.newConnection(); connection.addShutdownListener(new ShutdownListener() { public void shutdownCompleted(ShutdownSignalException cause) { } }); log.info("connected to rabbitmq: " + connection + " for " + properties.getExchangeName()); channel = connection.createChannel(); if (properties.getPrefetchCount() > 0) { channel.basicQos(properties.getPrefetchCount()); } if (properties.getExchangeName() != null) { channel.exchangeDeclare(properties.getExchangeName(), properties.getExchangeType(), true); //durable } } catch (Exception e) { String msg = "RabbitMQ connection issue for exchange : " + properties.getExchangeName(); log.error(msg); throw new AiravataException(msg, e); } }
From source file:org.apache.airavata.messaging.core.impl.RabbitMQStatusConsumer.java
License:Apache License
private void createConnection() throws AiravataException { try {/*from w w w.j a v a 2s . co m*/ ConnectionFactory connectionFactory = new ConnectionFactory(); connectionFactory.setUri(url); connectionFactory.setAutomaticRecoveryEnabled(true); connection = connectionFactory.newConnection(); connection.addShutdownListener(new ShutdownListener() { public void shutdownCompleted(ShutdownSignalException cause) { } }); log.info("connected to rabbitmq: " + connection + " for " + exchangeName); channel = connection.createChannel(); channel.basicQos(prefetchCount); channel.exchangeDeclare(exchangeName, EXCHANGE_TYPE, false); } catch (Exception e) { String msg = "could not open channel for exchange " + exchangeName; log.error(msg); throw new AiravataException(msg, e); } }
From source file:org.apache.airavata.messaging.core.impl.RabbitMQSubscriber.java
License:Apache License
private void createConnection() throws AiravataException { try {// ww w . j av a 2s . c o m ConnectionFactory connectionFactory = new ConnectionFactory(); connectionFactory.setUri(properties.getBrokerUrl()); connectionFactory.setAutomaticRecoveryEnabled(properties.isAutoRecoveryEnable()); connection = connectionFactory.newConnection(); addShutdownListener(); log.info("connected to rabbitmq: " + connection + " for " + properties.getExchangeName()); channel = connection.createChannel(); channel.basicQos(properties.getPrefetchCount()); channel.exchangeDeclare(properties.getExchangeName(), properties.getExchangeType(), true); // durable } catch (Exception e) { String msg = "could not open channel for exchange " + properties.getExchangeName(); log.error(msg); throw new AiravataException(msg, e); } }
From source file:org.apache.airavata.messaging.core.impl.RabbitMQTaskLaunchConsumer.java
License:Apache License
private void createConnection() throws AiravataException { try {/*w ww .j a va 2s .co m*/ ConnectionFactory connectionFactory = new ConnectionFactory(); connectionFactory.setUri(url); connection = connectionFactory.newConnection(); connection.addShutdownListener(new ShutdownListener() { public void shutdownCompleted(ShutdownSignalException cause) { } }); log.info("connected to rabbitmq: " + connection + " for " + taskLaunchExchangeName); channel = connection.createChannel(); // channel.exchangeDeclare(taskLaunchExchangeName, "fanout"); } catch (Exception e) { String msg = "could not open channel for exchange " + taskLaunchExchangeName; log.error(msg); throw new AiravataException(msg, e); } }
From source file:org.apache.airavata.monitoring.consumer.StatusReceiver.java
License:Apache License
public void startThread() throws KeyManagementException, NoSuchAlgorithmException, URISyntaxException, IOException, TimeoutException { ConnectionFactory factory = new ConnectionFactory(); factory.setAutomaticRecoveryEnabled(true); factory.setUri(brokerURI);//from w w w. j a va 2s . c o m connection = factory.newConnection(); recieverThread = new Thread(this); recieverThread.start(); }
From source file:org.apache.airavata.monitoring.producer.RabbitMQEmailPublisher.java
License:Apache License
/** * RabbitMQ Publisher with auto-recovery enabled * * @param exchangeName Name of the exchange * @param brokerURL Broker URL//from w ww.j ava 2s . co m * @param queueNames Name of the queues which needs to be declared and binded to * the exchange * @throws IOException * @throws TimeoutException * @throws KeyManagementException * @throws NoSuchAlgorithmException * @throws URISyntaxException */ public RabbitMQEmailPublisher(String exchangeName, String brokerURL, String[] queueNames) throws IOException, TimeoutException, KeyManagementException, NoSuchAlgorithmException, URISyntaxException { this.exchangeName = exchangeName; // TODO get singleton instance of connection factory this.factory = new ConnectionFactory(); this.factory.setUri(brokerURL); factory.setAutomaticRecoveryEnabled(true); this.connection = factory.newConnection(); this.channel = connection.createChannel(); this.channel.exchangeDeclare(exchangeName, EXCHANGE_TYPE); for (String queueName : queueNames) { // declare all the queues channel.queueDeclare(queueName, true, false, false, null).getQueue(); // bind all the queues to exchange channel.queueBind(queueName, exchangeName, ""); } }
From source file:org.apache.apex.malhar.contrib.rabbitmq.AbstractRabbitMQInputOperator.java
License:Apache License
@Override public void activate(OperatorContext ctx) { try {/*from ww w. j a va 2 s . co m*/ connFactory = new ConnectionFactory(); connFactory.setHost(host); if (port != 0) { connFactory.setPort(port); } connection = connFactory.newConnection(); channel = connection.createChannel(); channel.exchangeDeclare(exchange, exchangeType); boolean resetQueueName = false; if (queueName == null) { // unique queuename is generated // used in case of fanout exchange queueName = channel.queueDeclare().getQueue(); resetQueueName = true; } else { // user supplied name // used in case of direct exchange channel.queueDeclare(queueName, true, false, false, null); } channel.queueBind(queueName, exchange, routingKey); // consumer = new QueueingConsumer(channel); // channel.basicConsume(queueName, true, consumer); tracingConsumer = new TracingConsumer(channel); cTag = channel.basicConsume(queueName, false, tracingConsumer); if (resetQueueName) { queueName = null; } } catch (IOException ex) { throw new RuntimeException("Connection Failure", ex); } }
From source file:org.apache.axis2.transport.amqp.common.AMQPConnectionFactory.java
License:Apache License
/** * Digest a AMQP CF definition from an axis2.xml 'Parameter' and construct * @param parameter the axis2.xml 'Parameter' that defined the AMQP CF *//* w w w .j a v a 2 s . c om*/ public AMQPConnectionFactory(Parameter parameter) { confac = new ConnectionFactory(); this.name = parameter.getName(); ParameterIncludeImpl pi = new ParameterIncludeImpl(); try { pi.deserializeParameters((OMElement) parameter.getValue()); } catch (AxisFault axisFault) { handleException("Error reading parameters for AMQP connection factory" + name, axisFault); } for (Object o : pi.getParameters()) { Parameter p = (Parameter) o; parameters.put(p.getName(), (String) p.getValue()); } log.info("Connection factory parameters: " + parameters); if (AMQPConstants.EXECUTION_CLOUD.equals(parameters.get(AMQPConstants.PARAM_EXECUTION_ENV))) { CloudEnvironment environment = new CloudEnvironment(); String cf_servicename = parameters.get(AMQPConstants.PARAM_AMQP_SERVICENAME); RabbitServiceInfo service = environment.getServiceInfo(cf_servicename, RabbitServiceInfo.class); if (service == null) log.error("Cannot retrieve CF service " + cf_servicename); log.info("Initialising AMQP ConnectionFactory : " + name + " using CloudFoundry data: " + service); confac.setHost(service.getHost()); confac.setPort(service.getPort()); confac.setUsername(service.getUserName()); confac.setPassword(service.getPassword()); confac.setVirtualHost(service.getVirtualHost()); } else { confac.setHost(parameters.get(AMQPConstants.PARAM_AMQP_HOST)); confac.setPassword(parameters.get(AMQPConstants.PARAM_AMQP_PASSWORD)); confac.setPort(Integer.parseInt(parameters.get(AMQPConstants.PARAM_AMQP_PORT))); confac.setUsername(parameters.get(AMQPConstants.PARAM_AMQP_USERNAME)); confac.setVirtualHost(parameters.get(AMQPConstants.PARAM_AMQP_VHOST)); } log.info("AMQP ConnectionFactory : " + name + " initialized"); }