List of usage examples for com.rabbitmq.client ConnectionFactory newConnection
public Connection newConnection() throws IOException, TimeoutException
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());/*from w ww.j a v a2 s. c o m*/ return (executorService == null) ? factory.newConnection() : factory.newConnection(executorService); }
From source file:org.wso2.siddhi.debs2017.input.rabbitmq.RabbitMQSampleDataPublisher.java
License:Open Source License
public static void start(String[] argv) { try {//from w w w. j a v a2s .c o m 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];/*from w w w . ja v a 2s . co m*/ } 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 {/*from w w w .ja v a 2 s . c o 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. jav a 2 s.c o m*/ 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 ww w. j av a 2 s .com*/ 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:pl.nask.hsn2.connector.AbstractConnector.java
License:Open Source License
private void connect(String connectorAddress) throws BusException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost(connectorAddress);/*from www. j a v a 2 s . com*/ try { connection = factory.newConnection(); } catch (IOException e) { throw new BusException("Can't create connection.", e); } }
From source file:pl.nask.hsn2.DataStoreActiveCleaner.java
License:Open Source License
/** * Initialize RabbitMQ connection.//from ww w.j av a2 s . c om * * @return RabbitMQ consumer. * @throws IOException * When there's some connection issues. */ private QueueingConsumer initRabbitMqConnection() throws IOException { ConnectionFactory connFactory = new ConnectionFactory(); connFactory.setHost(rbtHostName); rbtConnection = connFactory.newConnection(); Channel channel = rbtConnection.createChannel(); channel.exchangeDeclare(rbtNotifyExchName, "fanout"); String queueName = channel.queueDeclare().getQueue(); channel.queueBind(queueName, rbtNotifyExchName, ""); QueueingConsumer consumer = new QueueingConsumer(channel); channel.basicConsume(queueName, AUTO_ACK, consumer); return consumer; }
From source file:pl.nask.hsn2.framework.bus.RbtBusTest.java
License:Open Source License
public ConsumeEndPoint setupStub() throws IOException, BusException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("195.187.238.85"); Connection connection = factory.newConnection(); final FireAndForgetEndPoint responseEndPoint = new RbtFireAndForgetEndPoint(connection); final MessageSerializer<Operation> serializer = new ProtoBufMessageSerializer(); return new RbtConsumeEndPoint(connection, new ConsumeEndPointHandler() { @Override// w w w.j av a 2 s.c o m public void handleMessage(Message message) { try { LOGGER.info("STUB got message {}.", message.getType()); if ("ObjectRequest".equals(message.getType())) { ObjectResponse res = new ObjectResponseBuilder(ResponseType.SUCCESS_PUT) .addAllObjects(Arrays.asList(6L)).build(); Message respMessage = serializer.serialize(res); respMessage.setDestination(message.getReplyTo()); respMessage.setReplyTo(new Destination("")); responseEndPoint.sendNotify(respMessage); } } catch (Exception ex) { LOGGER.error("Error with processing message."); } } }, "osHi", false, 10); }
From source file:pl.nask.hsn2.os.ConnectorImpl.java
License:Open Source License
public static void initConnection(String connectorAddress) throws BusException { if (connection == null) { ConnectionFactory factory = new ConnectionFactory(); factory.setHost(connectorAddress); try {/*from w ww . j a va 2 s .c o m*/ connection = factory.newConnection(); } catch (IOException e) { throw new BusException("Can't create connection.", e); } } else { throw new IllegalStateException("Connection already initialized"); } }