List of usage examples for com.rabbitmq.client ConnectionFactory setHost
public void setHost(String host)
From source file:mains.RaspiSensorModule_0.java
public static void main(String[] argv) throws Exception { //________ Basic subscribe direct (Routing) __________ ConnectionFactory factory = new ConnectionFactory(); factory.setHost(host); factory.setUsername("piadmin"); factory.setPassword("3828"); Connection connection = factory.newConnection(); System.setProperty("java.rmi.server.hostname", thisIp); ControllerPublisher conPub = new ControllerPublisher(connection, NODE_ID); LED_Controller ledCon = new LED_Controller("ledControllerRealTest"); LCD_Controller lcdCon = new LCD_Controller("lcdController_messeges"); // NodeController ledCon1 = new NodeController("ledControllerFloor"); // NodeController ledCon2 = new NodeController("ledControllerCabin"); conPub.publishController(ledCon);/* w w w .j a va 2 s. co m*/ conPub.publishController(lcdCon); // conPub.publishController(ledCon1); // conPub.publishController(ledCon2); NodeSensorHandler nodeSensors = new NodeSensorHandler(connection, SENSOR_EXCHANGE, SENSOR_ROUT_KEY_BASE + NODE_ID); System.out.println("Sensors up"); // BusRMIConnector rmiConnection = new BusRMIConnector(connection, SENSOR_EXCHANGE, SENSOR_ROUT_KEY_BASE + NODE_ID); // System.out.println("RMI up"); System.in.read(); connection.close(); }
From source file:mapas.Mapas.java
public static void main(String[] args) throws Exception { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("localhost"); factory.setPassword("test"); factory.setUsername("test"); final Connection connection = factory.newConnection(); final Channel channel = connection.createChannel(); channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null); System.out.println(" [*] Waiting for messages. To exit press CTRL+C"); channel.basicQos(1);//from w w w . ja v a 2s. c o m final Consumer consumer = new DefaultConsumer(channel) { @Override public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException { String message = new String(body, "UTF-8"); System.out.println(" [x] Received '" + message + "'"); try { doWork(message); } catch (Exception e) { System.out.println(e.getMessage()); } System.out.println(" [x] Done"); channel.basicAck(envelope.getDeliveryTag(), false); } }; channel.basicConsume(TASK_QUEUE_NAME, false, consumer); }
From source file:messaging.Worker.java
License:Apache License
public static void sendMessage(String message) throws java.io.IOException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost(ConfigurationLoader.getInstance().getRabbitmqNodename()); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null); channel.basicPublish("", TASK_QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN, message.getBytes()); System.out.println(" [x] Sent '" + message + "'"); channel.close();//from ww w.j a va 2 s . c o m connection.close(); }
From source file:mx.bigdata.utils.amqp.AMQPClientHelperImpl.java
License:Apache License
public ConnectionFactory createConnectionFactory(String key) throws Exception { ConnectionFactory factory = new ConnectionFactory(); String username = getValueOrDefault("amqp_username", key); if (username != null) { factory.setUsername(username);//from w w w. jav a 2 s. c om } String password = getValueOrDefault("amqp_password", key); if (password != null) { factory.setPassword(password); } String virtualHost = getValueOrDefault("amqp_virtual_host", key); if (virtualHost != null) { factory.setVirtualHost(virtualHost); } String host = getValueOrDefault("amqp_host", key); if (host != null) { factory.setHost(host); } Integer port = getIntegerOrDefault("amqp_port", key); if (port != null) { factory.setPort(port); } return factory; }
From source file:net.duckling.falcon.api.mq.DFMQManager.java
License:Apache License
public DFMQManager(String userName, String password, String host) { ConnectionFactory factory = new ConnectionFactory(); try {/*from ww w . ja va 2 s . c o m*/ factory.setUsername(userName); factory.setPassword(password); factory.setHost(host); connection = factory.newConnection(); channel = connection.createChannel(); } catch (Exception e) { e.printStackTrace(); } }
From source file:net.duckling.falcon.api.mq.impl.DFMQBasePublisherClient.java
License:Apache License
public DFMQBasePublisherClient(String username, String password, String host) { this.host = host; this.password = password; this.username = username; ConnectionFactory factory = new ConnectionFactory(); factory.setHost(host); factory.setPassword(password);//from w ww . j a v a 2 s. c o m factory.setUsername(username); try { connection = factory.newConnection(); channel = connection.createChannel(); } catch (IOException e) { LOG.error(e.getMessage(), e); } }
From source file:net.duckling.falcon.api.mq.impl.DFMQBaseSubscriberClient.java
License:Apache License
public DFMQBaseSubscriberClient(String username, String password, String host) { this.host = host; this.username = username; this.password = password; this.ssm = new SimpleStringMatch(); this.handlerMap = new HashMap<String, IDFMessageHandler>(); ConnectionFactory factory = new ConnectionFactory(); try {// w w w . j a v a 2 s. c om factory.setHost(host); factory.setUsername(username); factory.setPassword(password); connection = factory.newConnection(); channel = connection.createChannel(); } catch (IOException e) { LOG.error(e.getMessage(), e); } catch (ShutdownSignalException e) { LOG.error(e.getMessage(), e); } catch (ConsumerCancelledException e) { LOG.error(e.getMessage(), e); } }
From source file:net.echinopsii.ariane.community.messaging.rabbitmq.Client.java
License:Open Source License
/** * Initialize RabbitMQ connection with provided properties and this client ServiceFactory. * <br/>// w ww .j ava 2 s . co m * Following properties fields MUST be defined : * {@link net.echinopsii.ariane.community.messaging.api.MomClient#MOM_HOST} * {@link net.echinopsii.ariane.community.messaging.api.MomClient#MOM_PORT} * {@link net.echinopsii.ariane.community.messaging.api.MomClient#RBQ_VHOST} * <br/> * Following properties fields MAY be defined: * {@link net.echinopsii.ariane.community.messaging.api.MomClient#MOM_USER} * {@link net.echinopsii.ariane.community.messaging.api.MomClient#MOM_PSWD} * {@link net.echinopsii.ariane.community.messaging.api.MomClient#MOM_CLI_MSG_DEBUG_ON_TIMEOUT} * {@link net.echinopsii.ariane.community.messaging.api.MomClient#MOM_CLI_ROUTEES_NB_PER_SERVICE} * {@link net.echinopsii.ariane.community.messaging.api.MomClient#MOM_CLI_RPC_TIMEOUT} * {@link net.echinopsii.ariane.community.messaging.api.MomClient#MOM_CLI_RPC_RETRY} * {@link net.echinopsii.ariane.community.messaging.api.MomClient#RBQ_INFORMATION_KEY} * {@link net.echinopsii.ariane.community.messaging.api.MomClient#RBQ_PRODUCT_KEY} * {@link net.echinopsii.ariane.community.messaging.api.MomClient#RBQ_PLATFORM_KEY} * {@link net.echinopsii.ariane.community.messaging.api.MomClient#RBQ_COPYRIGHT_KEY} * {@link net.echinopsii.ariane.community.messaging.api.MomClient#RBQ_VERSION_KEY} * {@link net.echinopsii.ariane.community.messaging.api.MomClient#ARIANE_APP_KEY} * {@link net.echinopsii.ariane.community.messaging.api.MomClient#ARIANE_CMP_KEY} * {@link net.echinopsii.ariane.community.messaging.api.MomClient#ARIANE_OSI_KEY} * {@link net.echinopsii.ariane.community.messaging.api.MomClient#ARIANE_OTM_KEY} * {@link net.echinopsii.ariane.community.messaging.api.MomClient#ARIANE_PGURL_KEY} * {@link net.echinopsii.ariane.community.messaging.api.MomClient#ARIANE_PID_KEY} * @param properties configuration properties * @throws IOException if problems to join NATS server */ @Override public void init(Dictionary properties) throws IOException { if (properties.get(MomClient.RBQ_INFORMATION_KEY) != null) super.setClientID((String) properties.get(MomClient.RBQ_INFORMATION_KEY)); if (properties.get(MOM_CLI_MSG_DEBUG_ON_TIMEOUT) != null && (((String) properties.get(MOM_CLI_MSG_DEBUG_ON_TIMEOUT)).toLowerCase().equals("true"))) super.setMsgDebugOnTimeout(true); if (properties.get(MOM_CLI_ROUTEES_NB_PER_SERVICE) != null) super.setRouteesCountPerService(new Integer((String) properties.get(MOM_CLI_ROUTEES_NB_PER_SERVICE))); try { if (Class.forName("akka.osgi.ActorSystemActivator") != null && MessagingAkkaSystemActivator.getSystem() != null) super.setActorSystem(MessagingAkkaSystemActivator.getSystem()); else super.setActorSystem(ActorSystem.create("MySystem")); } catch (ClassNotFoundException e) { super.setActorSystem(ActorSystem.create("MySystem")); } ConnectionFactory factory = new ConnectionFactory(); factory.setHost((String) properties.get(MOM_HOST)); factory.setPort(new Integer((String) properties.get(MOM_PORT))); if (properties.get(RBQ_VHOST) != null) factory.setVirtualHost((String) properties.get(RBQ_VHOST)); if (properties.get(MOM_USER) != null) factory.setUsername((String) properties.get(MOM_USER)); if (properties.get(MOM_PSWD) != null) factory.setPassword((String) properties.get(MOM_PSWD)); Map<String, Object> factoryProperties = factory.getClientProperties(); if (properties.get(MomClient.RBQ_PRODUCT_KEY) != null) factoryProperties.put(RBQ_PRODUCT_KEY, properties.get(MomClient.RBQ_PRODUCT_KEY)); if (properties.get(MomClient.RBQ_INFORMATION_KEY) != null) factoryProperties.put(RBQ_INFORMATION_KEY, super.getClientID()); if (properties.get(MomClient.RBQ_PLATFORM_KEY) != null) factoryProperties.put(RBQ_PLATFORM_KEY, properties.get(MomClient.RBQ_PLATFORM_KEY)); else factoryProperties.put(RBQ_PLATFORM_KEY, "Java " + System.getProperty("java.version")); if (properties.get(MomClient.RBQ_COPYRIGHT_KEY) != null) factoryProperties.put(RBQ_COPYRIGHT_KEY, properties.get(MomClient.RBQ_COPYRIGHT_KEY)); if (properties.get(MomClient.RBQ_VERSION_KEY) != null) factoryProperties.put(RBQ_VERSION_KEY, properties.get(MomClient.RBQ_VERSION_KEY)); Enumeration keys = properties.keys(); while (keys.hasMoreElements()) { Object key = keys.nextElement(); if (key instanceof String && ((String) key).startsWith(MomClient.ARIANE_KEYS)) factoryProperties.put((String) key, properties.get((String) key)); } connection = factory.newConnection(); super.setServiceFactory(new ServiceFactory(this)); }
From source file:net.es.netshell.controller.impl.SdnController.java
License:Open Source License
public SdnController() { try {/*ww w. ja va2 s .c o 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); factory.setUsername(user);/* w w w . j a va 2 s . c o m*/ 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; }