Examples of AnonymousQueue


Examples of org.springframework.amqp.core.AnonymousQueue

//    //add as many declare statements as needed like a script.
//  }
 
  @Bean
  public Queue marketDataQueue() {   
    return new AnonymousQueue();
  }
View Full Code Here

Examples of org.springframework.amqp.core.AnonymousQueue

  /**
   * This queue does not need a binding, since it relies on the default exchange.
   */ 
  @Bean
  public Queue traderJoeQueue() { 
    return new AnonymousQueue();
  }
View Full Code Here

Examples of org.springframework.amqp.core.AnonymousQueue

    Queue queue = new Queue("", false, false, true, args);
    String testQueueName = admin.declareQueue(queue);
    // Create a DeadLetterExchange and bind a queue to it with the original routing key
    DirectExchange dle = new DirectExchange("test.DLE", false, true);
    admin.declareExchange(dle);
    Queue dlq = new AnonymousQueue();
    admin.declareQueue(dlq);
    admin.declareBinding(BindingBuilder.bind(dlq).to(dle).with(testQueueName));

    container.setQueueNames(testQueueName);
    container.afterPropertiesSet();
    container.start();

    Message message = MessageBuilder.withBody("foo".getBytes())
        .setContentType("text/plain")
        .setContentEncoding("junk")
        .build();
    template.send("", testQueueName, message);

    Message rejected = template.receive(dlq.getName());
    int n = 0;
    while (n++ < 100 && rejected == null) {
      Thread.sleep(100);
      rejected = template.receive(dlq.getName());
    }
    assertTrue("Message did not arrive in DLQ", n < 100);
    assertEquals("foo", new String(rejected.getBody()));


    // Verify that the exception strategy has access to the message
    final AtomicReference<Message> failed = new AtomicReference<Message>();
    ConditionalRejectingErrorHandler eh = new ConditionalRejectingErrorHandler(new FatalExceptionStrategy() {

      @Override
      public boolean isFatal(Throwable t) {
        if (t instanceof ListenerExecutionFailedException) {
          failed.set(((ListenerExecutionFailedException) t).getFailedMessage());
        }
        return t instanceof ListenerExecutionFailedException
            && t.getCause() instanceof MessageConversionException;
      }
    });
    container.setErrorHandler(eh);

    template.send("", testQueueName, message);

    rejected = template.receive(dlq.getName());
    n = 0;
    while (n++ < 100 && rejected == null) {
      Thread.sleep(100);
      rejected = template.receive(dlq.getName());
    }
    assertTrue("Message did not arrive in DLQ", n < 100);
    assertEquals("foo", new String(rejected.getBody()));
    assertNotNull(failed.get());
View Full Code Here

Examples of org.springframework.amqp.core.AnonymousQueue

    /**
     * @return an anonymous (auto-delete) queue.
     */
    @Bean
    public Queue requestQueue() {
      return new AnonymousQueue();
    }
View Full Code Here

Examples of org.springframework.amqp.core.AnonymousQueue

    /**
     * @return an anonymous (auto-delete) queue.
     */
    @Bean
    public Queue replyQueue() {
      return new AnonymousQueue();
    }
View Full Code Here

Examples of org.springframework.amqp.core.AnonymousQueue

    assertNull(template.receiveAndConvert(queue.getName()));
  }

  @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();
    container.setApplicationContext(context);
    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();
  }
View Full Code Here

Examples of org.springframework.amqp.core.AnonymousQueue

    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());
    container.addQueues(new AnonymousQueue(), new AnonymousQueue());
    assertEquals(3, queues.size());
    container.removeQueues(new Queue("foo"));
    assertEquals(2, queues.size());
    container.stop();
  }
View Full Code Here

Examples of org.springframework.amqp.core.AnonymousQueue

    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();
      }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.