List of usage examples for org.springframework.amqp.core AnonymousQueue AnonymousQueue
public AnonymousQueue()
From source file:vn.topmedia.monitor.rabbit.client.RabbitClientConfiguration.java
@Bean public Queue marketDataQueue() { //!Chu y//from w w w. jav a 2 s .com //Moi client se tao ra queue bat ky dung de chua message duoc gui toi return new AnonymousQueue(); }
From source file:org.opentestsystem.delivery.logging.RabbitConfiguration.java
@Bean public Queue springCloudBusQueue() { return new AnonymousQueue(); }
From source file:org.springframework.amqp.rabbit.core.RabbitAdminTests.java
@Test public void testIgnoreDeclarationExeptionsTimeout() throws Exception { com.rabbitmq.client.ConnectionFactory rabbitConnectionFactory = mock( com.rabbitmq.client.ConnectionFactory.class); TimeoutException toBeThrown = new TimeoutException("test"); doThrow(toBeThrown).when(rabbitConnectionFactory).newConnection(any(ExecutorService.class), anyString()); CachingConnectionFactory ccf = new CachingConnectionFactory(rabbitConnectionFactory); RabbitAdmin admin = new RabbitAdmin(ccf); List<DeclarationExceptionEvent> events = new ArrayList<DeclarationExceptionEvent>(); admin.setApplicationEventPublisher(new EventPublisher(events)); admin.setIgnoreDeclarationExceptions(true); admin.declareQueue(new AnonymousQueue()); admin.declareQueue();/* ww w . j a v a 2 s .c o m*/ admin.declareExchange(new DirectExchange("foo")); admin.declareBinding(new Binding("foo", DestinationType.QUEUE, "bar", "baz", null)); assertThat(events.size(), equalTo(4)); assertThat(events.get(0).getSource(), sameInstance(admin)); assertThat(events.get(0).getDeclarable(), instanceOf(AnonymousQueue.class)); assertSame(toBeThrown, events.get(0).getThrowable().getCause()); assertNull(events.get(1).getDeclarable()); assertSame(toBeThrown, events.get(1).getThrowable().getCause()); assertThat(events.get(2).getDeclarable(), instanceOf(DirectExchange.class)); assertSame(toBeThrown, events.get(2).getThrowable().getCause()); assertThat(events.get(3).getDeclarable(), instanceOf(Binding.class)); assertSame(toBeThrown, events.get(3).getThrowable().getCause()); assertSame(events.get(3), admin.getLastDeclarationExceptionEvent()); }
From source file:org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainerIntegration2Tests.java
@Test public void testListenFromAnonQueue() throws Exception { AnonymousQueue queue = new AnonymousQueue(); CountDownLatch latch = new CountDownLatch(10); SimpleMessageListenerContainer container = new SimpleMessageListenerContainer( template.getConnectionFactory()); container.setMessageListener(new MessageListenerAdapter(new PojoListener(latch))); container.setQueueNames(queue.getName()); container.setConcurrentConsumers(2); GenericApplicationContext context = new GenericApplicationContext(); context.getBeanFactory().registerSingleton("foo", queue); context.refresh();/*w w w. j av a 2s . c o m*/ container.setApplicationContext(context); RabbitAdmin admin = new RabbitAdmin(this.template.getConnectionFactory()); admin.setApplicationContext(context); container.setRabbitAdmin(admin); container.afterPropertiesSet(); container.start(); for (int i = 0; i < 10; i++) { template.convertAndSend(queue.getName(), i + "foo"); } assertTrue(latch.await(10, TimeUnit.SECONDS)); container.stop(); container.start(); latch = new CountDownLatch(10); container.setMessageListener(new MessageListenerAdapter(new PojoListener(latch))); for (int i = 0; i < 10; i++) { template.convertAndSend(queue.getName(), i + "foo"); } assertTrue(latch.await(10, TimeUnit.SECONDS)); container.stop(); }
From source file:org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainerIntegration2Tests.java
@Test public void testRestartConsumerMissingQueue() throws Exception { Queue queue = new AnonymousQueue(); this.template.convertAndSend(queue.getName(), "foo"); ConnectionFactory connectionFactory = new CachingConnectionFactory("localhost", BrokerTestUtils.getPort()); CountDownLatch latch = new CountDownLatch(1); SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory); container.setMessageListener(new MessageListenerAdapter(new PojoListener(latch))); container.setQueues(queue);/*from w w w . j ava 2 s . c o m*/ container.setRecoveryInterval(500); container.setMissingQueuesFatal(false); container.setDeclarationRetries(1); container.setFailedDeclarationRetryInterval(100); container.setRetryDeclarationInterval(30000); container.afterPropertiesSet(); container.start(); new RabbitAdmin(connectionFactory).declareQueue(queue); this.template.convertAndSend(queue.getName(), "foo"); assertTrue(latch.await(10, TimeUnit.SECONDS)); // verify properties propagated to consumer BlockingQueueConsumer consumer = (BlockingQueueConsumer) TestUtils .getPropertyValue(container, "consumers", Map.class).keySet().iterator().next(); assertEquals(1, TestUtils.getPropertyValue(consumer, "declarationRetries")); assertEquals(100L, TestUtils.getPropertyValue(consumer, "failedDeclarationRetryInterval")); assertEquals(30000L, TestUtils.getPropertyValue(consumer, "retryDeclarationInterval")); container.stop(); ((DisposableBean) connectionFactory).destroy(); }
From source file:org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainerLongTests.java
@Test public void testAddQueuesAndStartInCycle() throws Exception { final SingleConnectionFactory connectionFactory = new SingleConnectionFactory("localhost"); final SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory); container.setMessageListener((MessageListener) message -> { });//from www . j ava 2 s .c om container.setConcurrentConsumers(2); container.afterPropertiesSet(); RabbitAdmin admin = new RabbitAdmin(connectionFactory); for (int i = 0; i < 20; i++) { AnonymousQueue anonymousQueue = new AnonymousQueue(); admin.declareQueue(anonymousQueue); container.addQueueNames(anonymousQueue.getName()); if (!container.isRunning()) { container.start(); } } int n = 0; while (n++ < 100 && container.getActiveConsumerCount() != 2) { Thread.sleep(100); } assertEquals(2, container.getActiveConsumerCount()); container.stop(); connectionFactory.destroy(); }
From source file:org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainerTests.java
@Test public void testChangeQueuesSimple() throws Exception { ConnectionFactory connectionFactory = mock(ConnectionFactory.class); final SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory); container.setQueueNames("foo"); List<?> queues = TestUtils.getPropertyValue(container, "queueNames", List.class); assertEquals(1, queues.size());/*from w w w.j a va2 s . co m*/ container.addQueues(new AnonymousQueue(), new AnonymousQueue()); assertEquals(3, queues.size()); container.removeQueues(new Queue("foo")); assertEquals(2, queues.size()); container.stop(); }
From source file:org.springframework.integration.x.rabbit.RabbitMessageBus.java
@Override public void bindPubSubConsumer(String name, MessageChannel moduleInputChannel) { FanoutExchange exchange = new FanoutExchange("topic." + name); rabbitAdmin.declareExchange(exchange); Queue queue = new AnonymousQueue(); this.rabbitAdmin.declareQueue(queue); org.springframework.amqp.core.Binding binding = BindingBuilder.bind(queue).to(exchange); this.rabbitAdmin.declareBinding(binding); // register with context so they will be redeclared after a connection failure this.autoDeclareContext.getBeanFactory().registerSingleton(queue.getName(), queue); if (!autoDeclareContext.containsBean(exchange.getName() + ".binding")) { this.autoDeclareContext.getBeanFactory().registerSingleton(exchange.getName() + ".binding", binding); }/*from w w w . j av a 2s .c o m*/ doRegisterConsumer(name, moduleInputChannel, queue); }