List of usage examples for com.rabbitmq.client ConnectionFactory setHost
public void setHost(String host)
From source file:org.wso2.siddhi.debs2017.input.DebsBenchmarkSystem.java
License:Open Source License
private Connection createConnection(ExecutorService executorService) throws IOException, TimeoutException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost(getHost()); return (executorService == null) ? factory.newConnection() : factory.newConnection(executorService); }
From source file:org.wso2.siddhi.debs2017.input.rabbitmq.RabbitMQConsumer.java
License:Open Source License
/** * Consumes the sample data/* w ww . j av a 2s .c o m*/ * */ public void consume(String queue, String host, String host1, int port1, String host2, int port2, String host3, int port3, int executorSize) { TASK_QUEUE_NAME = queue; ConnectionFactory factory = new ConnectionFactory(); factory.setHost(host); final Connection connection; final Channel channel; final Consumer consumer; try { connection = factory.newConnection(EXECUTORS); channel = connection.createChannel(); consumer = new EventDispatcher(channel, host1, port1, host2, port2, host3, port3, executorSize); boolean autoAck = true; // acknowledgment is covered below channel.basicConsume(TASK_QUEUE_NAME, autoAck, consumer); } catch (IOException e) { e.printStackTrace(); } catch (TimeoutException e) { e.printStackTrace(); } }
From source file:org.wso2.siddhi.debs2017.input.rabbitmq.RabbitMQSampleDataPublisher.java
License:Open Source License
public static void start(String[] argv) { try {//from ww w .jav a2 s .c om if (argv.length > 0) { TASK_QUEUE_NAME = argv[0]; } ConnectionFactory factory = new ConnectionFactory(); factory.setHost("localhost"); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null); String data = ""; BufferedReader reader = new BufferedReader(new FileReader("frmattedData_63.nt"));//molding_machine_100M.nt rdfSample.txt //Machine_59 //frmattedData.txt // read file line by line String line; Scanner scanner; int count = 0; while ((line = reader.readLine()) != null) { scanner = new Scanner(line); while (scanner.hasNext()) { String dataInLine = scanner.next(); if (dataInLine.contains("----")) { if (data.length() > 100) { for (int i = 0; i < 5; i++) { count++; System.out.println(count); String data1 = data.replace("Machine_59", "Machine_" + i).replace("_59_", "_" + i + "_"); channel.basicPublish("", TASK_QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN, data1.getBytes()); } } data = ""; } else { data += " " + dataInLine; if (dataInLine.contains(".") && !dataInLine.contains("<")) { data += "\n"; } } } } channel.close(); connection.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.wso2.siddhi.debs2017.input.rabbitmq.RabbitMQSamplePublisher.java
License:Open Source License
public static void main(String[] argv) throws java.io.IOException, TimeoutException { if (argv.length > 0) { TASK_QUEUE_NAME = argv[0];// ww w . ja v a 2s . c om } ConnectionFactory factory = new ConnectionFactory(); factory.setHost("localhost"); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null); String data = ""; try { BufferedReader reader = new BufferedReader(new FileReader("frmattedData_63.nt"));//molding_machine_100M.nt rdfSample.txt //Machine_59 //frmattedData.txt // read file line by line String line; Scanner scanner; int count = 0; while ((line = reader.readLine()) != null) { scanner = new Scanner(line); while (scanner.hasNext()) { String dataInLine = scanner.next(); if (dataInLine.contains("----")) { if (data.length() > 100) { for (int i = 0; i < 5; i++) { count++; System.out.println(count); // System.out.println(data); //Thread.sleep(5000); String data1 = data.replace("Machine_59", "Machine_" + i).replace("_59_", "_" + i + "_"); channel.basicPublish("", TASK_QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN, data1.getBytes()); } } data = ""; } else { data += " " + dataInLine; if (dataInLine.contains(".") && !dataInLine.contains("<")) { data += "\n"; } } } } } catch (Exception e) { e.printStackTrace(); } channel.close(); connection.close(); }
From source file:other.common.messaging.JsonConnection.java
License:Apache License
public JsonConnection() { // Create a ConnectionFactory ConnectionFactory connectionFactory = new ConnectionFactory(); // Create a Connection try {/*w w w. ja v a 2 s . co m*/ // Create a ConnectionFactory connectionFactory.setHost(Play.configuration.getProperty("AMQPhost")); connectionFactory.setPort(Integer.valueOf(Play.configuration.getProperty("AMQPport"))); connectionFactory.setUsername(Play.configuration.getProperty("AMQPuser")); connectionFactory.setPassword(Play.configuration.getProperty("AMQPpasswd")); /* The AMQ connection. */ Connection connection = connectionFactory.newConnection(); channel = connection.createChannel(); // Create exchange channel.exchangeDeclare("iris", "topic", true); } catch (IOException e) { LOGGER.error("Error while connection to AMQP broker: " + e.getMessage()); System.exit(1); } }
From source file:ox.softeng.burst.service.message.RabbitMessageService.java
public RabbitMessageService(EntityManagerFactory emf, Properties properties) throws IOException, TimeoutException { exchange = properties.getProperty("rabbitmq.exchange"); queue = properties.getProperty("rabbitmq.queue"); entityManagerFactory = emf;/* w w w. j a v a 2s . com*/ consumerCount = Utils.convertToInteger("message.service.thread.size", properties.getProperty("message.service.consumer.size"), 1); String host = properties.getProperty("rabbitmq.host"); String username = properties.getProperty("rabbitmq.user", ConnectionFactory.DEFAULT_USER); String password = properties.getProperty("rabbitmq.password", ConnectionFactory.DEFAULT_PASS); Integer port = Utils.convertToInteger("rabbitmq.port", properties.getProperty("rabbitmq.port"), ConnectionFactory.DEFAULT_AMQP_PORT); ConnectionFactory factory = new ConnectionFactory(); factory.setUsername(username); factory.setPassword(password); factory.setPort(port); factory.setHost(host); factory.setAutomaticRecoveryEnabled(true); factory.setThreadFactory(new NamedThreadFactory("consumer")); connection = factory.newConnection(); logger.info("Creating new RabbitMQ Service using: \n" + " host: {}:{}\n" + " user: {}\n" + " exchange: {}\n" + " queue: {}", host, port, username, exchange, queue); }
From source file:ox.softeng.burst.services.RabbitService.java
License:Open Source License
public RabbitService(String rabbitMQHost, Integer port, String username, String password, String rabbitMQExchange, String rabbitMQQueue, EntityManagerFactory emf) throws IOException, TimeoutException, JAXBException { ConnectionFactory factory = new ConnectionFactory(); factory.setUsername(username);/*from w w w. j a v a2 s. c o m*/ factory.setPassword(password); factory.setPort(port); factory.setHost(rabbitMQHost); factory.setAutomaticRecoveryEnabled(true); entityManagerFactory = emf; this.rabbitMQQueue = rabbitMQQueue; this.rabbitMQExchange = rabbitMQExchange; connection = factory.newConnection(); unmarshaller = JAXBContext.newInstance(MessageDTO.class).createUnmarshaller(); }
From source file:pe.gob.sunat.tecnologia3.arquitectura.framework.desktop.manejadorColas.ConnectionProviderImpl.java
public ConnectionFactory getConnectionFactory() { ConnectionFactory connectionFactory = new ConnectionFactory(); connectionFactory.setHost(mqHost); // connectionFactory.setPort(mqPort); // connectionFactory.setUsername(mqUsername); // connectionFactory.setPassword(mqPassword); // connectionFactory.setVirtualHost(mqVirtualhost); // connectionFactory.setAutomaticRecoveryEnabled(true); return connectionFactory; }
From source file:pl.nask.hsn2.bus.test.rabbitmq.RbtAbstractEndPointTest.java
License:Open Source License
private ConnectionFactory getConnectionFactory() { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("195.187.238.85"); return factory; }
From source file:pl.nask.hsn2.connector.AbstractConnector.java
License:Open Source License
private void connect(String connectorAddress) throws BusException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost(connectorAddress); try {// w w w . j a v a 2s . c om connection = factory.newConnection(); } catch (IOException e) { throw new BusException("Can't create connection.", e); } }