Package org.springframework.amqp.rabbit.core

Examples of org.springframework.amqp.rabbit.core.RabbitAdmin


  @Test
  public void testListenerSendsMessageAndThenContainerCommits() throws Exception {

    ConnectionFactory connectionFactory = createConnectionFactory();
    RabbitTemplate template = new RabbitTemplate(connectionFactory);
    new RabbitAdmin(connectionFactory).declareQueue(sendQueue);

    acknowledgeMode = AcknowledgeMode.AUTO;
    transactional = true;

    CountDownLatch latch = new CountDownLatch(1);
View Full Code Here


  @Test
  public void testListenerSendsMessageAndThenRollback() throws Exception {

    ConnectionFactory connectionFactory = createConnectionFactory();
    RabbitTemplate template = new RabbitTemplate(connectionFactory);
    new RabbitAdmin(connectionFactory).declareQueue(sendQueue);

    acknowledgeMode = AcknowledgeMode.AUTO;
    transactional = true;

    CountDownLatch latch = new CountDownLatch(1);
View Full Code Here

    concurrentConsumers = 3;
    CountDownLatch latch = new CountDownLatch(messageCount);

    ConnectionFactory connectionFactory = createConnectionFactory();
    RabbitAdmin admin = new RabbitAdmin(connectionFactory);
    admin.deleteQueue("nonexistent");

    try {
      container = createContainer("nonexistent", new VanillaListener(latch), connectionFactory);
    }
    finally {
View Full Code Here

     */
    concurrentConsumers = 1;
    CountDownLatch latch = new CountDownLatch(messageCount);

    ConnectionFactory connectionFactory = createConnectionFactory();
    RabbitAdmin admin = new RabbitAdmin(connectionFactory);
    admin.deleteQueue("nonexistent");
    try {
      container = createContainer("nonexistent", new VanillaListener(latch), connectionFactory);
    }
    finally {
      ((DisposableBean) connectionFactory).destroy();
View Full Code Here

  public void testSingleListenerDoesRecoverFromMissingQueueWhenNotFatal() throws Exception {
    concurrentConsumers = 1;
    CountDownLatch latch = new CountDownLatch(messageCount);

    ConnectionFactory connectionFactory = createConnectionFactory();
    RabbitAdmin admin = new RabbitAdmin(connectionFactory);
    admin.deleteQueue("nonexistent");
    try {
      container = doCreateContainer("nonexistent", new VanillaListener(latch), connectionFactory);
      container.setMissingQueuesFatal(false);
      container.start();
      testRecoverMissingQueues(latch, connectionFactory);
    }
    finally {
      if (container != null) {
        container.stop();
      }
      admin.deleteQueue("nonexistent");
      ((DisposableBean) connectionFactory).destroy();
    }
  }
View Full Code Here

  public void testSingleListenerDoesRecoverFromMissingQueueWhenNotFatalGlobalProps() throws Exception {
    concurrentConsumers = 1;
    CountDownLatch latch = new CountDownLatch(messageCount);

    ConnectionFactory connectionFactory = createConnectionFactory();
    RabbitAdmin admin = new RabbitAdmin(connectionFactory);
    admin.deleteQueue("nonexistent");
    try {
      container = doCreateContainer("nonexistent", new VanillaListener(latch), connectionFactory);
      Properties properties = new Properties();
      properties.setProperty("smlc.missing.queues.fatal", "false");
      GenericApplicationContext context = new GenericApplicationContext();
      context.getBeanFactory().registerSingleton("spring.amqp.global.properties", properties);
      context.refresh();
      container.setApplicationContext(context);
      container.start();
      testRecoverMissingQueues(latch, connectionFactory);
    }
    finally {
      if (container != null) {
        container.stop();
      }
      admin.deleteQueue("nonexistent");
      ((DisposableBean) connectionFactory).destroy();
    }
  }
View Full Code Here

    }
  }

  private void testRecoverMissingQueues(CountDownLatch latch, ConnectionFactory connectionFactory)
      throws InterruptedException {
    RabbitAdmin admin = new RabbitAdmin(connectionFactory);
    // queue doesn't exist during startup - verify we started, create queue and verify recovery
    Thread.sleep(5000);
    assertEquals(messageCount, latch.getCount());
    admin.declareQueue(new Queue("nonexistent"));
    RabbitTemplate template = new RabbitTemplate(connectionFactory);
    for (int i = 0; i < messageCount; i++) {
      template.convertAndSend("nonexistent", "foo" + i);
    }
    assertTrue(latch.await(10, TimeUnit.SECONDS));
    Map<?,?> consumers = TestUtils.getPropertyValue(container, "consumers", Map.class);
    assertEquals(1, consumers.size());
    Object consumer = consumers.keySet().iterator().next();

    // delete the queue and verify we recover again when it is recreated.
    admin.deleteQueue("nonexistent");
    Thread.sleep(3000);
    latch = new CountDownLatch(messageCount);
    container.setMessageListener(new MessageListenerAdapter(new VanillaListener(latch)));
    assertEquals(messageCount, latch.getCount());
    admin.declareQueue(new Queue("nonexistent"));
    for (int i = 0; i < messageCount; i++) {
      template.convertAndSend("nonexistent", "foo" + i);
    }
    assertTrue(latch.await(10, TimeUnit.SECONDS));
    assertEquals(1, consumers.size());
View Full Code Here

  @Test
  public void testSendAndReceiveFromVolatileQueue() throws Exception {

    RabbitTemplate template = new RabbitTemplate(connectionFactory);

    RabbitAdmin admin = new RabbitAdmin(connectionFactory);
    Queue queue = admin.declareQueue();
    template.convertAndSend(queue.getName(), "message");
    String result = (String) template.receiveAndConvert(queue.getName());
    assertEquals("message", result);

  }
View Full Code Here

  @Test
  public void testSendAndReceiveFromVolatileQueueAfterImplicitRemoval() throws Exception {

    RabbitTemplate template = new RabbitTemplate(connectionFactory);

    RabbitAdmin admin = new RabbitAdmin(connectionFactory);
    Queue queue = admin.declareQueue();
    template.convertAndSend(queue.getName(), "message");

    // Force a physical close of the channel
    connectionFactory.destroy();
View Full Code Here

    RabbitTemplate template1 = new RabbitTemplate(connectionFactory);
    RabbitTemplate template2 = new RabbitTemplate(connectionFactory);
    template1.setChannelTransacted(true);

    RabbitAdmin admin = new RabbitAdmin(connectionFactory);
    Queue queue = admin.declareQueue();

    template1.convertAndSend(queue.getName(), "message");
    String result = (String) template2.receiveAndConvert(queue.getName());
    assertEquals("message", result);
View Full Code Here

TOP

Related Classes of org.springframework.amqp.rabbit.core.RabbitAdmin

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.