List of usage examples for com.rabbitmq.client ConnectionFactory getUsername
public String getUsername()
From source file:javarpc_server.JavaRPC_Server.java
/** * @param args the command line arguments * @throws java.io.IOException/*from w ww.j a v a 2 s . co m*/ * @throws java.lang.InterruptedException */ public static void main(String[] args) throws IOException, InterruptedException { // TODO code application logic here ConnectionFactory factory = new ConnectionFactory(); System.out.println(factory.getUsername() + " " + factory.getPassword()); factory.setHost("localhost"); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.queueDeclare(RPC_QUEUE_NAME, false, false, false, null); channel.basicQos(1); QueueingConsumer consumer = new QueueingConsumer(channel); channel.basicConsume(RPC_QUEUE_NAME, false, consumer); System.out.println(" [x] Awaiting RPC requests"); while (true) { QueueingConsumer.Delivery delivery = consumer.nextDelivery(); BasicProperties props = delivery.getProperties(); BasicProperties replyProps = new BasicProperties.Builder().correlationId(props.getCorrelationId()) .build(); String message = new String(delivery.getBody()); System.out.println(" [.] convert(" + message + ")"); String response = "" + convert(message); channel.basicPublish("", props.getReplyTo(), replyProps, response.getBytes()); channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false); } }
From source file:net.roboconf.messaging.internal.utils.RabbitMqUtilsTest.java
License:Apache License
@Test public void testConfigureFactory() throws Exception { String address = "http://roboconf.net/some/path"; int port = 18547; String username = "toto"; String password = "123456789"; ConnectionFactory factory = new ConnectionFactory(); Assert.assertNotSame(address, factory.getHost()); Assert.assertNotSame(port, factory.getPort()); RabbitMqUtils.configureFactory(factory, "http://roboconf.net:" + port + "/some/path", username, password); Assert.assertEquals(address, factory.getHost()); Assert.assertEquals(port, factory.getPort()); Assert.assertEquals(username, factory.getUsername()); Assert.assertEquals(password, factory.getPassword()); }
From source file:net.roboconf.messaging.rabbitmq.internal.utils.RabbitMqUtilsTest.java
License:Apache License
@Test public void testConfigureFactory() throws Exception { String address = "http://roboconf.net/some/path"; int port = 18547; String username = "toto"; String password = "123456789"; ConnectionFactory factory = new ConnectionFactory(); Assert.assertNotSame(address, factory.getHost()); Assert.assertNotSame(port, factory.getPort()); Map<String, String> configuration = new HashMap<>(); configuration.put(RABBITMQ_SERVER_IP, "http://roboconf.net:" + port + "/some/path"); configuration.put(RABBITMQ_SERVER_USERNAME, username); configuration.put(RABBITMQ_SERVER_PASSWORD, password); RabbitMqUtils.configureFactory(factory, configuration); Assert.assertEquals(address, factory.getHost()); Assert.assertEquals(port, factory.getPort()); Assert.assertEquals(username, factory.getUsername()); Assert.assertEquals(password, factory.getPassword()); }
From source file:net.roboconf.messaging.rabbitmq.internal.utils.RabbitMqUtilsTest.java
License:Apache License
@Test public void testConfigureFactory_nullIp() throws Exception { ConnectionFactory factory = new ConnectionFactory(); String username = "toto"; String password = "123456789"; Map<String, String> configuration = new HashMap<>(); configuration.put(RABBITMQ_SERVER_IP, null); configuration.put(RABBITMQ_SERVER_USERNAME, username); configuration.put(RABBITMQ_SERVER_PASSWORD, password); RabbitMqUtils.configureFactory(factory, configuration); Assert.assertEquals(username, factory.getUsername()); Assert.assertEquals(password, factory.getPassword()); }
From source file:org.apache.flume.amqp.AmqpSourceTest.java
License:Apache License
@Test public void testCreateConnectionFactoryFrom() throws Exception { Context ctx = createContext(); ConnectionFactory connectionFactory = AmqpSource.createConnectionFactoryFrom(ctx); assertThat(connectionFactory.getHost(), is(HOST_NAME)); assertThat(connectionFactory.getPort(), is(PORT)); assertThat(connectionFactory.getVirtualHost(), is(VIRTUAL_HOST)); assertThat(connectionFactory.getUsername(), is(USER_NAME)); assertThat(connectionFactory.getPassword(), is(PASSWORD)); assertThat(connectionFactory.getConnectionTimeout(), is(CONNECTION_TIMEOUT)); assertThat(connectionFactory.getRequestedHeartbeat(), is(REQUEST_HEARTBEAT)); }
From source file:org.apache.flume.RabbitMQUtilTest.java
License:Apache License
@Test public void getFactory() { ConnectionFactory factory = RabbitMQUtil.getFactory(context); Assert.assertNotNull("factory should not be null", context); Assert.assertEquals("Host does not match", context.getString(RabbitMQConstants.CONFIG_HOSTNAME), factory.getHost());/* w w w. j a v a 2 s .c o m*/ Assert.assertEquals("Port does not match", context.getInteger(RabbitMQConstants.CONFIG_PORT), (Integer) factory.getPort()); Assert.assertEquals("ConnectionTimeout does not match", context.getInteger(RabbitMQConstants.CONFIG_CONNECTIONTIMEOUT), (Integer) factory.getConnectionTimeout()); Assert.assertEquals("Password does not match", context.getString(RabbitMQConstants.CONFIG_PASSWORD), factory.getPassword()); Assert.assertEquals("Username does not match", context.getString(RabbitMQConstants.CONFIG_USERNAME), factory.getUsername()); Assert.assertEquals("VirtualHost does not match", context.getString(RabbitMQConstants.CONFIG_VIRTUALHOST), factory.getVirtualHost()); }
From source file:org.apache.synapse.message.store.RabbitMQStoreTest.java
License:Open Source License
/** * call init method with dummy values and validating connectionFactory object * * @throws NoSuchFieldException//from www. j a v a 2 s . c om * @throws IllegalAccessException */ @Test public void testInit() throws NoSuchFieldException, IllegalAccessException { ConnectionFactory factory = (ConnectionFactory) connectionFactory.get(rabbitMQStore); Assert.assertEquals("should return previously stored values", factory.getPort(), Integer.parseInt(PORT)); Assert.assertEquals("should return previously stored values", factory.getHost(), HOST); Assert.assertEquals("should return previously stored values", factory.getPassword(), PASSWORD); Assert.assertEquals("should return previously stored values", factory.getUsername(), USERNAME); Assert.assertEquals("should return previously stored values", factory.getVirtualHost(), VIRTUAL_HOST); }
From source file:org.cloudfoundry.reconfiguration.spring.RabbitCloudServiceBeanFactoryPostProcessorTest.java
License:Apache License
private void assertConfiguration(CachingConnectionFactory factory, String username, String password, String host, int port, String virtualHost) { ConnectionFactory connectionFactory = (ConnectionFactory) ReflectionTestUtils.getField(factory, "rabbitConnectionFactory"); assertEquals(username, connectionFactory.getUsername()); assertEquals(password, connectionFactory.getPassword()); assertEquals(host, factory.getHost()); assertEquals(port, factory.getPort()); assertEquals(virtualHost, factory.getVirtualHost()); }
From source file:org.springframework.amqp.rabbit.junit.BrokerRunningTests.java
License:Apache License
@Test public void testVars() { BrokerRunning brokerRunning = BrokerRunning.isBrokerAndManagementRunning(); brokerRunning.setAdminPassword("foo"); brokerRunning.setAdminUser("bar"); brokerRunning.setHostName("baz"); brokerRunning.setPassword("qux"); brokerRunning.setPort(1234);/*ww w .j a v a2 s . c om*/ brokerRunning.setUser("fiz"); assertEquals("http://baz:15672/api/", brokerRunning.getAdminUri()); ConnectionFactory connectionFactory = brokerRunning.getConnectionFactory(); assertEquals("baz", connectionFactory.getHost()); assertEquals(1234, connectionFactory.getPort()); assertEquals("fiz", connectionFactory.getUsername()); assertEquals("qux", connectionFactory.getPassword()); }
From source file:org.springframework.amqp.rabbit.junit.BrokerRunningTests.java
License:Apache License
@Test public void testEnvironmentVars() { Map<String, String> vars = new HashMap<>(); vars.put("RABBITMQ_TEST_ADMIN_PASSWORD", "FOO"); vars.put("RABBITMQ_TEST_ADMIN_URI", "http://foo/bar"); vars.put("RABBITMQ_TEST_ADMIN_USER", "BAR"); vars.put("RABBITMQ_TEST_HOSTNAME", "BAZ"); vars.put("RABBITMQ_TEST_PASSWORD", "QUX"); vars.put("RABBITMQ_TEST_PORT", "2345"); vars.put("RABBITMQ_TEST_USER", "FIZ"); BrokerRunning.setEnvironmentVariableOverrides(vars); BrokerRunning brokerRunning = BrokerRunning.isBrokerAndManagementRunning(); assertEquals("http://foo/bar", brokerRunning.getAdminUri()); ConnectionFactory connectionFactory = brokerRunning.getConnectionFactory(); assertEquals("BAZ", connectionFactory.getHost()); assertEquals(2345, connectionFactory.getPort()); assertEquals("FIZ", connectionFactory.getUsername()); assertEquals("QUX", connectionFactory.getPassword()); DirectFieldAccessor dfa = new DirectFieldAccessor(brokerRunning); assertEquals("BAR", dfa.getPropertyValue("adminUser")); assertEquals("FOO", dfa.getPropertyValue("adminPassword")); BrokerRunning.clearEnvironmentVariableOverrides(); }