List of usage examples for com.rabbitmq.client ConnectionFactory ConnectionFactory
ConnectionFactory
From source file:net.es.netshell.controller.impl.SdnController.java
License:Open Source License
public SdnController() { try {//from ww w. j a v a 2 s . co m // Get a connection to the AMPQ broker (e.g. RabbitMQ server) ConnectionFactory factory = new ConnectionFactory(); factory.setHost("localhost"); connection = factory.newConnection(); channel = connection.createChannel(); // Create the SDN controller queue, non-durable, non-exclusive, non-auto-delete, no other args channel.queueDeclare(Common.controllerRequestQueueName, false, false, false, null); channel.basicQos(1); // what does this do? // Set up a consumer who will read messages from the queue consumer = new QueueingConsumer(channel); channel.basicConsume(Common.controllerRequestQueueName, false, consumer); // Create exchange for notifications channel.exchangeDeclare(Common.notificationExchangeName, "fanout"); // XXX we need to do some error-checking here to handle the case that the AMPQ server is dead // or unreachable. // JSON parser setup mapper = new ObjectMapper(); // OpenFlow controller setup controller = Controller.getInstance(); logger.info(SdnController.class.getName() + " ready"); } catch (Exception e) { e.printStackTrace(); } }
From source file:net.es.netshell.rabbitmq.SSLConnection.java
License:Open Source License
public ConnectionFactory createConnection() throws Exception { ConnectionFactory factory = new ConnectionFactory(); factory.setHost(host);/* ww w .j a v a2 s .co m*/ factory.setUsername(user); factory.setPassword(password); factory.setPort(port); if (ssl) { char[] keyPassphrase = KEYPASS.toCharArray(); KeyStore ks = KeyStore.getInstance("PKCS12"); ks.load(new FileInputStream(KEYCERT), keyPassphrase); KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509"); kmf.init(ks, keyPassphrase); char[] trustPassphrase = TRUSTPASS.toCharArray(); KeyStore tks = KeyStore.getInstance("JKS"); tks.load(new FileInputStream(KEYSTORE), trustPassphrase); TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509"); tmf.init(tks); SSLContext c = SSLContext.getInstance("SSLv3"); c.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null); factory.useSslProtocol(c); } return factory; }
From source file:net.lshift.accent.AccentTestUtils.java
License:Apache License
/** * Given the reconnection logic in Accent, a missing AMQP server during testing can cause tests to hang. This method * tries a direct AMQP connection first, so we can ensure that an AMQP host is available. *///from ww w. j a v a 2s. c o m public static void ensureAMQPServer() throws IOException { ConnectionFactory cf = new ConnectionFactory(); cf.newConnection().close(); }
From source file:net.lshift.accent.ConnectionSmokeTest.java
License:Apache License
private static ConnectionFactory directFactory() { return new ConnectionFactory(); }
From source file:net.lshift.accent.ConnectionSmokeTest.java
License:Apache License
private static ConnectionFactory controlledFactory(int port) { ConnectionFactory controlledFactory = new ConnectionFactory(); controlledFactory.setPort(port);//from www . j ava 2 s . com return controlledFactory; }
From source file:net.lshift.camcapture.AMQPacketProducer.java
License:Open Source License
public AMQPacketProducer(String host, String exchange, String routingKey) throws IOException { this.host = host; this.exchange = exchange; this.routingKey = routingKey; ConnectionFactory cf = new ConnectionFactory(); cf.setHost(host);// w w w .j a v a 2s. c o m this.conn = cf.newConnection(); this.ch = conn.createChannel(); ch.exchangeDeclare(exchange, "fanout"); }
From source file:net.lshift.camdisplay.Main.java
License:Open Source License
public Main(String host, String exch, String nickname, final String mixerSpec) throws IOException { frame = new JFrame("RabbitCam: " + host + "/" + exch); panel = new JPanel(); componentMap = new HashMap(); setupWindowDressing(exch, nickname, frame, panel); frame.pack();/*from w w w. j a v a2 s .c o m*/ frame.show(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); textInput.requestFocusInWindow(); ConnectionFactory cf = new ConnectionFactory(); cf.setHost(host); cf.setRequestedHeartbeat(0); conn = cf.newConnection(); ch = conn.createChannel(); ch.exchangeDeclare(exch, "fanout"); String queueName = ch.queueDeclare().getQueue(); ch.queueBind(queueName, exch, ""); ch.basicConsume(queueName, true, new DefaultConsumer(ch) { public void handleShutdownSignal(String consumerTag, ShutdownSignalException s) { if (s.getReason() instanceof java.io.EOFException) { JOptionPane.showMessageDialog(frame, "AMQP server disconnected.", "Connection closed", JOptionPane.ERROR_MESSAGE); } else { SwingUtil.complain("Connection closed", null, s); } System.exit(1); } public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException { String routingKey = envelope.getRoutingKey(); String contentType = properties.getContentType(); if (contentType.equals("text/plain")) { handleText(routingKey, new String(body)); return; } CamstreamComponent comp; if (!componentMap.containsKey(routingKey)) { comp = new CamstreamComponent(mixerSpec); addComponent(routingKey, comp); frame.pack(); } else { comp = (CamstreamComponent) componentMap.get(routingKey); } if (comp.handleDelivery(contentType, body)) { frame.pack(); } } }); }
From source file:net.nzcorp.hbase.tableevent_signaler.TableEventSignaler.java
License:Apache License
@Override public void start(final CoprocessorEnvironment env) throws IOException { destinationTable = env.getConfiguration().get("destination_table"); if (Strings.isNullOrEmpty(destinationTable)) { String err = "No value for 'destination_tables' specified, aborting coprocessor"; LOGGER.fatal(err);/*from www . java 2s .com*/ throw new IllegalArgumentException(err); } LOGGER.info(String.format("destination table set to %s", destinationTable)); secondaryIndexTable = env.getConfiguration().get("secondary_index_table"); if (Strings.isNullOrEmpty(secondaryIndexTable)) { String err = "No value for 'secondary_index_table' specified, aborting coprocessor"; LOGGER.fatal(err); throw new IllegalArgumentException(err); } try (final Table _table = env.getTable(TableName.valueOf(secondaryIndexTable))) { } catch (IOException e) { String err = "Table " + secondaryIndexTable + " does not exist"; LOGGER.fatal(err); throw e; } LOGGER.info(String.format("Using secondary index table %s", secondaryIndexTable)); secondaryIndexCF = env.getConfiguration().get("secondary_index_cf"); if (Strings.isNullOrEmpty(secondaryIndexCF)) { String err = "No 'secondary_index_cf' specified, cannot continue. Please set secondary_index_cf=some_sensible_value for the coprocessor"; LOGGER.fatal(err); throw new IllegalArgumentException(err); } // the column family name to take all values from sourceCF = env.getConfiguration().get("source_column_family"); // the column family name to put values into in the destinationTable targetCf = env.getConfiguration().get("target_column_family"); //option to run *expensive* debugging f_debug = Boolean.parseBoolean(env.getConfiguration().get("full_debug")); //light-weight messages? anything other than -i "tRuE" is false: sendValue = Boolean.parseBoolean(env.getConfiguration().get("send_value")); String fqs = env.getConfiguration().get("filter_qualifiers"); if (fqs == null || fqs.length() == 0) { LOGGER.info("No filter qualifiers set, signaling on every event"); filterQualifiers = new HashSet<>(); } else { filterQualifiers = Sets.newHashSet(fqs.split("\\|")); LOGGER.info(String.format("%s filters loaded", filterQualifiers.size())); } /* * The fully qualified amqpConn string to the amqp server * * e.g. amqp://guest:guest@rabbitmq:5672/hbase_events */ final String amqpAddress = env.getConfiguration().get("amq_address"); if (Strings.isNullOrEmpty(amqpAddress)) { String err = "missing value for parameter amqpAddress"; LOGGER.fatal(err); throw new IOException(err); } factory = new ConnectionFactory(); try { factory.setUri(amqpAddress); } catch (URISyntaxException | NoSuchAlgorithmException | KeyManagementException e) { throw new IOException(e); } ensureAmqpConnection(); tableCache = new HashMap<>(); LOGGER.info(String.format("Sending from %s#%s: --> %s#%s", secondaryIndexTable, sourceCF, destinationTable, targetCf)); }
From source file:net.orzo.queue.AmqpConnection.java
License:Apache License
@Override public void start() throws Exception { ConnectionFactory factory = new ConnectionFactory(); factory.setHost(this.conf.host); factory.setPort(this.conf.port); factory.setVirtualHost(this.conf.virtualHost); factory.setUsername(this.conf.user); factory.setPassword(this.conf.password); this.connection = factory.newConnection(); }
From source file:net.praqma.tracey.tracey_rabbitmq_neo4j_bridge.AMQPFacade.java
public AMQPFacade(Properties prop) throws IOException { this.prop = prop; connfac = new ConnectionFactory(); connfac.setHost(prop.getProperty("server_host")); connfac.setPort(Integer.parseInt(prop.getProperty("server_port", "5672"))); connfac.setUsername(prop.getProperty("username")); connfac.setPassword(prop.getProperty("password")); conn = connfac.newConnection();/*www . j a v a 2 s.c o m*/ chan = conn.createChannel(); chan.exchangeDeclare(prop.getProperty("exchange_name"), prop.getProperty("exchange_type")); }