List of usage examples for com.rabbitmq.client ConnectionFactory setUri
public void setUri(String uriString) throws URISyntaxException, NoSuchAlgorithmException, KeyManagementException
From source file:uniko.west.test.TwitterLogSender.java
public static void main(String[] args) { /* String strJSONFilePaths = { "/home/ubuntu/data/rawtweet-log-short.log", "/home/ubuntu/data/IITNNO-prepare-json-example.json", "/home/ubuntu/data/json/IITNNO-raw-JSON-example.json", "/home/ubuntu/data/json/ITINNO-aggregated-geoparse-example.json" "/home/ubuntu/data/json/CERTH-RSS-example.json" }; */// w w w. j a va 2s. com // String strJSONFilePath = "/home/ubuntu/data/rawtweet-log-short.log"; //short twitter log // String strJSONFilePath = "/home/ubuntu/data/json/IITNNO-prepare-json-example.json"; //String strJSONFilePath = "/home/ubuntu/data/json/IITNNO-raw-JSON-example.json"; //short itinno // example // String strJSONFilePath = "/home/ubuntu/data/json/ITINNO-aggregated-geoparse-example.json"; //another itinno example String strJSONFilePath = "/home/ubuntu/data/json/simplified-ITINNO-aggregated-geoparse-example.json"; String exchangeName = "ukob_test"; // for (String strJSONFilePath : strJSONFilePaths) { try (BufferedReader br = new BufferedReader(new FileReader(strJSONFilePath))) { // send a UTF-8 encoded JSON tweet to the RabbitMQ (for // stormspout // to pick up and send to bolt) // read UTF-8 JSON text from file Logger.getLogger(TwitterLogSender.class.getName()).log(Level.INFO, "ExampleRabbitmqClient started"); // connect to rabbitmq broker // first of all create connection factory ConnectionFactory factory = new ConnectionFactory(); factory.setUri("amqp://guest:guest@localhost:5672/%2F"); // initialise connection and define channel Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); String jsonLine; while ((jsonLine = br.readLine()) != null) { long timestampSinceEpoch = System.currentTimeMillis() / 1000; // initialise amqp basic peoperties object BasicProperties.Builder basicProperties = new AMQP.BasicProperties.Builder(); basicProperties.build(); basicProperties.timestamp(new Date(timestampSinceEpoch)).build(); basicProperties.contentType("text/json").build(); basicProperties.deliveryMode(1).build(); // publish message channel.basicPublish(exchangeName, "test-routing", basicProperties.build(), jsonLine.getBytes("UTF-8")); } // close connection and channel channel.close(); connection.close(); Logger.getLogger(TwitterLogSender.class.getName()).log(Level.INFO, "ExampleRabbitmqClient finished"); } catch (URISyntaxException | NoSuchAlgorithmException | KeyManagementException | IOException ex) { Logger.getLogger(TwitterLogSender.class.getName()).log(Level.SEVERE, null, ex); // } } }
From source file:ws.ament.hammock.rabbitmq.ConnectionFactoryProducer.java
License:Apache License
@Produces @ApplicationScoped/*w w w . j a va2 s .c o m*/ public ConnectionFactory createConnectionFactory(RabbitMQConfiguration rabbitMQConfiguration) { ConnectionFactory connectionFactory = new ConnectionFactory(); connectionFactory.setAutomaticRecoveryEnabled(rabbitMQConfiguration.isAutomaticRecovery()); connectionFactory.setClientProperties(rabbitMQConfiguration.getClientProperties()); connectionFactory.setConnectionTimeout(rabbitMQConfiguration.getConnectionTimeout()); connectionFactory.setExceptionHandler(rabbitMQConfiguration.getExceptionHandler()); connectionFactory.setHandshakeTimeout(rabbitMQConfiguration.getHandshakeTimeout()); connectionFactory.setHeartbeatExecutor(rabbitMQConfiguration.getHeartbeatExecutor()); connectionFactory.setMetricsCollector(rabbitMQConfiguration.getMetricsCollector()); connectionFactory.setHost(rabbitMQConfiguration.getHost()); connectionFactory.setNetworkRecoveryInterval(rabbitMQConfiguration.getNetworkRecoveryInterval()); if (rabbitMQConfiguration.isNio()) { connectionFactory.useNio(); connectionFactory.setNioParams(rabbitMQConfiguration.getNioParams()); } connectionFactory.setPassword(rabbitMQConfiguration.getPassword()); connectionFactory.setPort(rabbitMQConfiguration.getPort()); connectionFactory.setRequestedChannelMax(rabbitMQConfiguration.getRequestedChannelMax()); connectionFactory.setRequestedFrameMax(rabbitMQConfiguration.getRequestedFrameMax()); connectionFactory.setRequestedHeartbeat(rabbitMQConfiguration.getRequestedHeartbeat()); connectionFactory.setSaslConfig(rabbitMQConfiguration.getSaslConfig()); connectionFactory.setSharedExecutor(rabbitMQConfiguration.getSharedExecutor()); connectionFactory.setShutdownExecutor(rabbitMQConfiguration.getShutdownExecutor()); connectionFactory.setShutdownTimeout(rabbitMQConfiguration.getShutdownTimeout()); connectionFactory.setSocketConfigurator(rabbitMQConfiguration.getSocketConf()); connectionFactory.setSocketFactory(rabbitMQConfiguration.getFactory()); connectionFactory.setThreadFactory(rabbitMQConfiguration.getThreadFactory()); connectionFactory.setTopologyRecoveryEnabled(rabbitMQConfiguration.isTopologyRecovery()); try { connectionFactory.setUri(rabbitMQConfiguration.getUri()); } catch (Exception e) { throw new RuntimeException("Unable to populate URI ", e); } connectionFactory.setUsername(rabbitMQConfiguration.getUsername()); connectionFactory.setVirtualHost(rabbitMQConfiguration.getVirtualHost()); if (rabbitMQConfiguration.getSslContext() != null) { connectionFactory.useSslProtocol(rabbitMQConfiguration.getSslContext()); } return connectionFactory; }
From source file:xyz.cloudbans.barker.amqp.AmqpBarkerTest.java
License:Apache License
@BeforeClass public static void prepare() throws Throwable { String amqpUri = System.getenv("AMQP_URI"); Assume.assumeNotNull("AMQP_URI is not set.", amqpUri, CoreMatchers.notNullValue()); ConnectionFactory connectionFactory = new ConnectionFactory(); connectionFactory.setUri(amqpUri); try {/* w ww . jav a2 s. co m*/ connection = connectionFactory.newConnection(); } catch (IOException e) { Assume.assumeNoException("Connection to AMQP broker cannot be established.", e); } }
From source file:ylj.demo.mq.amqp.rabbitmq_client.DemoConsumer.java
License:Apache License
public static void doConsume() throws Exception { ExecutorService consumeES = Executors.newFixedThreadPool(2); ConnectionFactory factory = new ConnectionFactory(); factory.setUri("amqp://guest:guest@newsrec10.photo.163.org:5672"); // factory.setUri("amqp://guest:guest@/?brokerlist='tcp://newsrec10.photo.163.org:5672'"); factory.setAutomaticRecoveryEnabled(true); factory.setNetworkRecoveryInterval(10000); factory.setExceptionHandler(new MyExceptionHandler()); AutorecoveringConnection conn = (AutorecoveringConnection) factory.newConnection(consumeES); conn.addRecoveryListener(new MyRecoveryListener()); // ?queue??// w w w. j a v a 2s. c om Channel channel = conn.createChannel(); // channel.close(); // channel.queueDeclare("recsys.news.userfeed.usermodel", false, false, false, null); // channel.basicConsume("recsys.news.userfeed.usermodel", true, null, new MyConsumer()); channel.basicConsume("recsys.news.userfeed.usermodel", new MyConsumer()); // conn.close(); /* * work??work???? channel.basicConsume("hello",false,consumer); channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false); * */ }
From source file:zipkin2.autoconfigure.collector.rabbitmq.ZipkinRabbitMQCollectorProperties.java
License:Apache License
public RabbitMQCollector.Builder toBuilder() throws KeyManagementException, NoSuchAlgorithmException, URISyntaxException { final RabbitMQCollector.Builder result = RabbitMQCollector.builder(); ConnectionFactory connectionFactory = new ConnectionFactory(); if (concurrency != null) result.concurrency(concurrency); if (connectionTimeout != null) connectionFactory.setConnectionTimeout(connectionTimeout); if (queue != null) result.queue(queue);//from w w w. j a v a2 s . c o m if (uri != null) { connectionFactory.setUri(uri); } else { if (addresses != null) result.addresses(addresses); if (password != null) connectionFactory.setPassword(password); if (username != null) connectionFactory.setUsername(username); if (virtualHost != null) connectionFactory.setVirtualHost(virtualHost); if (useSsl != null && useSsl) connectionFactory.useSslProtocol(); } result.connectionFactory(connectionFactory); return result; }