List of usage examples for com.rabbitmq.client ConnectionFactory ConnectionFactory
ConnectionFactory
From source file:com.netcore.hsmart.AppConstants.java
/** * RabbitMQ/* w w w . j a va 2 s .co m*/ */ public static void initializeRabbitMqConnection() { final Logger logger = LoggerFactory.getLogger(AppConstants.class); AppConstants.rabbitMqFactory = new ConnectionFactory(); rabbitMqFactory.setHost(AppConstants.RABBITMQ_HOST); rabbitMqFactory.setPort(Integer.parseInt(AppConstants.RABBITMQ_PORT)); rabbitMqFactory.setUsername(AppConstants.RABBITMQ_USERNAME); rabbitMqFactory.setPassword(AppConstants.RABBITMQ_PASSWORD); rabbitMqFactory.setNetworkRecoveryInterval(5000); rabbitMqFactory.setAutomaticRecoveryEnabled(true); try { rabbitMqConnection = rabbitMqFactory.newConnection(); } catch (IOException | TimeoutException e) { // TODO Auto-generated catch block logger.error("RABBITMQ_CONN_ERROR:" + e.getMessage()); e.printStackTrace(); } }
From source file:com.nifi.processors.amqp.AbstractAMQPProcessor.java
License:Apache License
/** * Creates {@link Connection} to AMQP system. *///from ww w .ja va 2s. co m private Connection createConnection(ProcessContext context) { ConnectionFactory cf = new ConnectionFactory(); cf.setHost(context.getProperty(HOST).getValue()); cf.setPort(Integer.parseInt(context.getProperty(PORT).getValue())); cf.setUsername(context.getProperty(USER).getValue()); cf.setPassword(context.getProperty(PASSWORD).getValue()); String vHost = context.getProperty(V_HOST).getValue(); if (vHost != null) { cf.setVirtualHost(vHost); } // handles TLS/SSL aspects final SSLContextService sslService = context.getProperty(SSL_CONTEXT_SERVICE) .asControllerService(SSLContextService.class); final String rawClientAuth = context.getProperty(CLIENT_AUTH).getValue(); final SSLContext sslContext; if (sslService != null) { final SSLContextService.ClientAuth clientAuth; if (StringUtils.isBlank(rawClientAuth)) { clientAuth = SSLContextService.ClientAuth.REQUIRED; } else { // try { clientAuth = SSLContextService.ClientAuth.valueOf(rawClientAuth); // } catch (final IllegalArgumentException iae) { // throw new ProviderCreationException(String.format("Unrecognized client auth '%s'. Possible values are [%s]", // rawClientAuth, StringUtils.join(SslContextFactory.ClientAuth.values(), ", "))); // } } sslContext = sslService.createSSLContext(clientAuth); } else { sslContext = null; } // check if the ssl context is set and add it to the factory if so if (sslContext != null) { cf.useSslProtocol(sslContext); } try { Connection connection = cf.newConnection(); return connection; } catch (Exception e) { throw new IllegalStateException("Failed to establish connection with AMQP Broker: " + cf.toString(), e); } }
From source file:com.nrkei.microservices.rapids_rivers.rabbit_mq.RabbitMqRapids.java
public RabbitMqRapids(String serviceName, String host, String port) { queueName = serviceName + "_" + UUID.randomUUID().toString(); factory = new ConnectionFactory(); factory.setHost(host);/*ww w .j av a2 s . c om*/ factory.setPort(Integer.parseInt(port)); }
From source file:com.nxttxn.vramel.components.rabbitMQ.RabbitMQEndpoint.java
License:Apache License
private ConnectionFactory getOrCreateConnectionFactory() { if (connectionFactory == null) { ConnectionFactory factory = new ConnectionFactory(); factory.setUsername(getUsername()); factory.setPassword(getPassword()); factory.setVirtualHost(getVhost()); factory.setHost(getHostname());/*w w w .ja v a 2 s . co m*/ factory.setPort(getPortNumber()); if (getClientProperties() != null) { factory.setClientProperties(getClientProperties()); } factory.setConnectionTimeout(getConnectionTimeout()); factory.setRequestedChannelMax(getRequestedChannelMax()); factory.setRequestedFrameMax(getRequestedFrameMax()); factory.setRequestedHeartbeat(getRequestedHeartbeat()); if (getSslProtocol() != null) { try { if (getSslProtocol().equals("true")) { factory.useSslProtocol(); } else if (getTrustManager() == null) { factory.useSslProtocol(getSslProtocol()); } else { factory.useSslProtocol(getSslProtocol(), getTrustManager()); } } catch (NoSuchAlgorithmException | KeyManagementException e) { throw new IllegalArgumentException("Invalid sslProtocol " + sslProtocol, e); } } if (getAutomaticRecoveryEnabled() != null) { factory.setAutomaticRecoveryEnabled(getAutomaticRecoveryEnabled()); } if (getNetworkRecoveryInterval() != null) { factory.setNetworkRecoveryInterval(getNetworkRecoveryInterval()); } if (getTopologyRecoveryEnabled() != null) { factory.setTopologyRecoveryEnabled(getTopologyRecoveryEnabled()); } connectionFactory = factory; } return connectionFactory; }
From source file:com.ojdbc.rmqhelper.rmq.Helper.java
public static synchronized ConnectionFactory getConnectionFactory() { //Create a connection factory if (factory != null) { return factory; }/*from ww w . jav a 2 s . co m*/ factory = new ConnectionFactory(); factory.setHost(ip); factory.setPort(port); factory.setUsername(userName); factory.setPassword(password); return factory; }
From source file:com.paxxis.cornerstone.messaging.service.amqp.AMQPServiceBusConnector.java
License:Apache License
protected void initConnection() { try {/*from w w w.j a v a2 s .co m*/ ConnectionFactory factory = new ConnectionFactory(); factory.setHost(host); factory.setPort(port); factory.setAutomaticRecoveryEnabled(autoRecover); factory.setConnectionTimeout(timeout); factory.setNetworkRecoveryInterval(recoveryInterval); factory.setRequestedHeartbeat(heartbeat); factory.setTopologyRecoveryEnabled(autoTopologyRecover); factory.setExceptionHandler(exceptionHandler); connection = factory.newConnection(); session = (AMQPSession) createSession(); } catch (IOException e) { logger.error(e); throw new RuntimeException(e); } }
From source file:com.pcs.test.amqp.Consumer.java
License:Open Source License
public static void main(String[] args) throws IOException, TimeoutException, ShutdownSignalException, ConsumerCancelledException, InterruptedException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("pcss-hdop04"); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.queueDeclare(QUEUE_NAME, false, false, false, null); System.out.println("listen for messages"); QueueingConsumer consumer = new QueueingConsumer(channel); channel.basicConsume(QUEUE_NAME, true, consumer); while (true) { QueueingConsumer.Delivery delivery = consumer.nextDelivery(); String msg = new String(delivery.getBody(), "UTF-8"); System.out.println("Msg received " + msg); }//from w w w . j a v a 2s . c o m }
From source file:com.pcs.test.amqp.Publisher.java
License:Open Source License
public static void main(String[] args) throws IOException, TimeoutException { System.out.println("starting"); ConnectionFactory factory = new ConnectionFactory(); factory.setHost("pcss-hdop04"); factory.setAutomaticRecoveryEnabled(true); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.queueDeclare(QUEUE_NAME, false, false, false, null); String message = "first message , hello world"; channel.basicPublish("", QUEUE_NAME, null, message.getBytes()); System.out.println("message sent"); channel.close();// ww w . j a v a 2 s .com connection.close(); }
From source file:com.preferya.facadesmsgatewaycontrolservlet.utils.RabbitMQUtils.java
public RabbitMQUtils() throws IOException { this.factory = new ConnectionFactory(); this.factory.setHost("localhost"); this.connection = this.factory.newConnection(); this.channel = this.connection.createChannel(); this.channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null); }
From source file:com.preferya.facadesmsgatewaycontrolservlet.utils.RabbitMQUtilsIsoCountry.java
public RabbitMQUtilsIsoCountry(String task_queue_name) throws IOException { this.factory = new ConnectionFactory(); this.factory.setHost("localhost"); this.connection = this.factory.newConnection(); this.channel = this.connection.createChannel(); this.task_queue_name = task_queue_name; this.channel.queueDeclare(task_queue_name, true, false, false, null); }