@Bean public ConnectionFactory connectionFactory() { return new CachingConnectionFactory(brokerRunning.getConnectionFactory()); }
public RabbitAvailableCTORInjectionTests(BrokerRunning brokerRunning) { this.connectionFactory = brokerRunning.getConnectionFactory(); }
@Bean BrokerRunning brokerRunning(final RabbitMqSetupService rabbitmqSetupService) { final BrokerRunning brokerRunning = BrokerRunning.isRunning(); brokerRunning.setHostName(rabbitmqSetupService.getHostname()); brokerRunning.getConnectionFactory().setUsername(rabbitmqSetupService.getUsername()); brokerRunning.getConnectionFactory().setPassword(rabbitmqSetupService.getPassword()); return brokerRunning; }
public void isUp() throws IOException, TimeoutException, URISyntaxException { Connection connection = getConnectionFactory().newConnection(); // NOSONAR - closeResources() Channel channel = null; try { channel = createQueues(connection); } finally { closeResources(connection, channel); } }
public void isUp() throws IOException, TimeoutException, URISyntaxException { Connection connection = getConnectionFactory().newConnection(); // NOSONAR - closeResources() Channel channel = null; try { channel = createQueues(connection); } finally { closeResources(connection, channel); } }
@Bean BrokerRunning brokerRunning(final RabbitMqSetupService rabbitmqSetupService) { final BrokerRunning brokerRunning = BrokerRunning.isRunning(); brokerRunning.setHostName(rabbitmqSetupService.getHostname()); brokerRunning.getConnectionFactory().setUsername(rabbitmqSetupService.getUsername()); brokerRunning.getConnectionFactory().setPassword(rabbitmqSetupService.getPassword()); return brokerRunning; }
@Override public Object resolveParameter(ParameterContext parameterContext, ExtensionContext context) throws ParameterResolutionException { // in parent for method injection, Composite key causes a store miss BrokerRunning brokerRunning = getParentStore(context).get(BROKER_RUNNING_BEAN, BrokerRunning.class) == null ? getStore(context).get(BROKER_RUNNING_BEAN, BrokerRunning.class) : getParentStore(context).get(BROKER_RUNNING_BEAN, BrokerRunning.class); Assert.state(brokerRunning != null, "Could not find brokerRunning instance"); Class<?> type = parameterContext.getParameter().getType(); return type.equals(ConnectionFactory.class) ? brokerRunning.getConnectionFactory() : brokerRunning; }
@Override public Object resolveParameter(ParameterContext parameterContext, ExtensionContext context) throws ParameterResolutionException { // in parent for method injection, Composite key causes a store miss BrokerRunning brokerRunning = getParentStore(context).get(BROKER_RUNNING_BEAN, BrokerRunning.class) == null ? getStore(context).get(BROKER_RUNNING_BEAN, BrokerRunning.class) : getParentStore(context).get(BROKER_RUNNING_BEAN, BrokerRunning.class); Assert.state(brokerRunning != null, "Could not find brokerRunning instance"); Class<?> type = parameterContext.getParameter().getType(); return type.equals(ConnectionFactory.class) ? brokerRunning.getConnectionFactory() : brokerRunning; }
@Bean public CachingConnectionFactory cf() { return new CachingConnectionFactory( RabbitAvailableCondition.getBrokerRunning().getConnectionFactory()); }
@Bean public CachingConnectionFactory cf() { return new CachingConnectionFactory(RabbitAvailableCondition.getBrokerRunning() .getConnectionFactory()); }
@Bean public ConnectionFactory connectionFactory() { return new CachingConnectionFactory(RabbitAvailableCondition.getBrokerRunning().getConnectionFactory()); }
@Bean public CachingConnectionFactory ccf() { return new CachingConnectionFactory(RabbitAvailableCondition.getBrokerRunning().getConnectionFactory()); }
/** * Delete arbitrary exchanges from the broker. * @param exchanges the exchanges to delete. */ public void deleteExchanges(String... exchanges) { Connection connection = null; // NOSONAR (closeResources()) Channel channel = null; try { connection = getConnection(getConnectionFactory()); connection.setId(generateId() + ".exchangeDelete"); channel = connection.createChannel(); for (String exchange : exchanges) { channel.exchangeDelete(exchange); } } catch (Exception e) { logger.warn("Failed to delete queues", e); } finally { closeResources(connection, channel); } }
/** * Delete arbitrary exchanges from the broker. * @param exchanges the exchanges to delete. */ public void deleteExchanges(String... exchanges) { Connection connection = null; // NOSONAR (closeResources()) Channel channel = null; try { connection = getConnection(getConnectionFactory()); connection.setId(generateId() + ".exchangeDelete"); channel = connection.createChannel(); for (String exchange : exchanges) { channel.exchangeDelete(exchange); } } catch (Exception e) { logger.warn("Failed to delete queues", e); } finally { closeResources(connection, channel); } }
/** * Delete arbitrary queues from the broker. * @param queues the queues to delete. */ public void deleteQueues(String... queues) { Connection connection = null; // NOSONAR (closeResources()) Channel channel = null; try { connection = getConnection(getConnectionFactory()); connection.setId(generateId() + ".queueDelete"); channel = connection.createChannel(); for (String queue : queues) { channel.queueDelete(queue); } } catch (Exception e) { logger.warn("Failed to delete queues", e); } finally { closeResources(connection, channel); } }
/** * Delete arbitrary queues from the broker. * @param queues the queues to delete. */ public void deleteQueues(String... queues) { Connection connection = null; // NOSONAR (closeResources()) Channel channel = null; try { connection = getConnection(getConnectionFactory()); connection.setId(generateId() + ".queueDelete"); channel = connection.createChannel(); for (String queue : queues) { channel.queueDelete(queue); } } catch (Exception e) { logger.warn("Failed to delete queues", e); } finally { closeResources(connection, channel); } }
@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(); }
@Test public void testArgumentsQueue() throws Exception { Queue queue = beanFactory.getBean("arguments", Queue.class); assertNotNull(queue); CachingConnectionFactory connectionFactory = new CachingConnectionFactory( brokerIsRunning.getConnectionFactory()); RabbitTemplate template = new RabbitTemplate(connectionFactory); RabbitAdmin rabbitAdmin = new RabbitAdmin(connectionFactory); rabbitAdmin.deleteQueue(queue.getName()); rabbitAdmin.declareQueue(queue); assertEquals(100L, queue.getArguments().get("x-message-ttl")); template.convertAndSend(queue.getName(), "message"); Properties props = rabbitAdmin.getQueueProperties("arguments"); if (props != null) { int n = 0; while (n++ < 200 && (Integer) props.get(RabbitAdmin.QUEUE_MESSAGE_COUNT) > 0) { Thread.sleep(50); props = rabbitAdmin.getQueueProperties("arguments"); } assertThat((Integer) props.get(RabbitAdmin.QUEUE_MESSAGE_COUNT), equalTo(0)); } connectionFactory.destroy(); brokerIsRunning.deleteQueues("arguments"); }
@Test public void testMasterLocator() throws Exception { CachingConnectionFactory cf = new CachingConnectionFactory(brokerIsRunning.getConnectionFactory()); RabbitAdmin admin = new RabbitAdmin(cf); AnonymousQueue queue = new AnonymousQueue(); admin.declareQueue(queue); Client client = new Client("http://guest:guest@localhost:15672/api"); QueueInfo info = client.getQueue("?", queue.getName()); int n = 0; while (n++ < 100 && info == null) { Thread.sleep(100); info = client.getQueue("/", queue.getName()); } assertNotNull(info); assertThat(info.getArguments().get(Queue.X_QUEUE_MASTER_LOCATOR), equalTo("client-local")); queue = new AnonymousQueue(); queue.setMasterLocator(null); admin.declareQueue(queue); info = client.getQueue("?", queue.getName()); n = 0; while (n++ < 100 && info == null) { Thread.sleep(100); info = client.getQueue("/", queue.getName()); } assertNotNull(info); assertNull(info.getArguments().get(Queue.X_QUEUE_MASTER_LOCATOR)); cf.destroy(); }
@Test public void testVars() { BrokerRunning brokerRunning = BrokerRunning.isBrokerAndManagementRunning(); brokerRunning.setAdminPassword("foo"); brokerRunning.setAdminUser("bar"); brokerRunning.setHostName("baz"); brokerRunning.setPassword("qux"); brokerRunning.setPort(1234); 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()); }