Examples of MessageListenerAdapter


Examples of org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter

            } else if (onMessage instanceof Closure) {
              consume.setDelegate((Closure) onMessage);
            } else if (onMessage instanceof MessageListener) {
              listenerContainer.setMessageListener(onMessage);
            } else {
              listenerContainer.setMessageListener(new MessageListenerAdapter(onMessage));
            }
          }

          if (paramMap.containsKey(ACK)) {
            AcknowledgeMode mode = AcknowledgeMode.valueOf(paramMap.get(ACK).toString().toUpperCase());
View Full Code Here

Examples of org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter

  @Test
  public void testErrorHandlerInvokeExceptionFromPojo() throws Exception {
    int messageCount = 3;
    CountDownLatch latch = new CountDownLatch(messageCount);
    doTest(messageCount, errorHandler, latch, new MessageListenerAdapter(new PojoThrowingExceptionListener(latch,
        new Exception("Pojo exception"))));
  }
View Full Code Here

Examples of org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter

  @Test
  public void testErrorHandlerInvokeRuntimeExceptionFromPojo() throws Exception {
    int messageCount = 3;
    CountDownLatch latch = new CountDownLatch(messageCount);
    doTest(messageCount, errorHandler, latch, new MessageListenerAdapter(new PojoThrowingExceptionListener(latch,
        new RuntimeException("Pojo runtime exception"))));
  }
View Full Code Here

Examples of org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter

  @Test
  public void testRejectingErrorHandler() throws Exception {
    RabbitTemplate template = createTemplate(1);
    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(template.getConnectionFactory());
    MessageListenerAdapter messageListener = new MessageListenerAdapter();
    messageListener.setDelegate(new Object());
    container.setMessageListener(messageListener);

    RabbitAdmin admin = new RabbitAdmin(template.getConnectionFactory());
    Map<String, Object> args = new HashMap<String, Object>();
    args.put("x-dead-letter-exchange", "test.DLE");
View Full Code Here

Examples of org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter

    @Bean
    public SimpleMessageListenerContainer serviceListenerContainer() {
      SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
      container.setConnectionFactory(rabbitConnectionFactory());
      container.setQueues(requestQueue());
      container.setMessageListener(new MessageListenerAdapter(new PojoListener()));
      return container;
    }
View Full Code Here

Examples of org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter

  }

  @Test
  public void testChangeQueues() throws Exception {
    CountDownLatch latch = new CountDownLatch(30);
    container = createContainer(new MessageListenerAdapter(new PojoListener(latch)), queue.getName(), queue1.getName());
    for (int i = 0; i < 10; i++) {
      template.convertAndSend(queue.getName(), i + "foo");
      template.convertAndSend(queue1.getName(), i + "foo");
    }
    container.addQueueNames(queue1.getName());
View Full Code Here

Examples of org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter

  }

  @Test
  public void testDeleteOneQueue() throws Exception {
    CountDownLatch latch = new CountDownLatch(20);
    container = createContainer(new MessageListenerAdapter(new PojoListener(latch)), queue.getName(), queue1.getName());
    for (int i = 0; i < 10; i++) {
      template.convertAndSend(queue.getName(), i + "foo");
      template.convertAndSend(queue1.getName(), i + "foo");
    }
    boolean waited = latch.await(10, TimeUnit.SECONDS);
    assertTrue("Timed out waiting for message", waited);
    BlockingQueueConsumer consumer = (BlockingQueueConsumer) TestUtils
        .getPropertyValue(container, "consumers", Map.class).keySet().iterator().next();
    admin.deleteQueue(queue1.getName());
    latch = new CountDownLatch(10);
    container.setMessageListener(new MessageListenerAdapter(new PojoListener(latch)));
    for (int i = 0; i < 10; i++) {
      template.convertAndSend(queue.getName(), i + "foo");
    }
    waited = latch.await(10, TimeUnit.SECONDS);
    assertTrue("Timed out waiting for message", waited);
    BlockingQueueConsumer newConsumer = (BlockingQueueConsumer) TestUtils
        .getPropertyValue(container, "consumers", Map.class).keySet().iterator().next();
    int n = 0;
    while (n++ < 100 && newConsumer == consumer) {
      Thread.sleep(100);
      newConsumer = (BlockingQueueConsumer) TestUtils
          .getPropertyValue(container, "consumers", Map.class).keySet().iterator().next();
    }
    assertTrue("Failed to restart consumer", n < 100);
    Set<?> missingQueues = TestUtils.getPropertyValue(newConsumer, "missingQueues", Set.class);
    n = 0;
    while (n++ < 100 && missingQueues.size() == 0) {
      Thread.sleep(200);
    }
    assertTrue("Failed to detect missing queue", n < 100);
    DirectFieldAccessor dfa = new DirectFieldAccessor(newConsumer);
    dfa.setPropertyValue("lastRetryDeclaration", 0);
    dfa.setPropertyValue("retryDeclarationInterval", 100);
    admin.declareQueue(queue1);
    n = 0;
    while (n++ < 100 && missingQueues.size() > 0) {
      Thread.sleep(100);
    }
    assertTrue("Failed to redeclare missing queue", n < 100);
    latch = new CountDownLatch(20);
    container.setMessageListener(new MessageListenerAdapter(new PojoListener(latch)));
    for (int i = 0; i < 10; i++) {
      template.convertAndSend(queue.getName(), i + "foo");
      template.convertAndSend(queue1.getName(), i + "foo");
    }
    waited = latch.await(10, TimeUnit.SECONDS);
View Full Code Here

Examples of org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter

  @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.rabbit.listener.adapter.MessageListenerAdapter

  @Test
  public void testExclusive() throws Exception {
    CountDownLatch latch1 = new CountDownLatch(1000);
    SimpleMessageListenerContainer container1 = new SimpleMessageListenerContainer(template.getConnectionFactory());
    container1.setMessageListener(new MessageListenerAdapter(new PojoListener(latch1)));
    container1.setQueueNames(queue.getName());
    GenericApplicationContext context = new GenericApplicationContext();
    context.getBeanFactory().registerSingleton("foo", queue);
    context.refresh();
    container1.setApplicationContext(context);
    container1.setExclusive(true);
    container1.afterPropertiesSet();
    container1.start();
    int n = 0;
    while (n++ < 100 && container1.getActiveConsumerCount() < 1) {
      Thread.sleep(100);
    }
    assertTrue(n < 100);
    CountDownLatch latch2 = new CountDownLatch(1000);
    SimpleMessageListenerContainer container2 = new SimpleMessageListenerContainer(template.getConnectionFactory());
    container2.setMessageListener(new MessageListenerAdapter(new PojoListener(latch2)));
    container2.setQueueNames(queue.getName());
    container2.setApplicationContext(context);
    container2.setRecoveryInterval(500);
    container2.setExclusive(true); // not really necessary, but likely people will make all consumers exlusive.
    container2.afterPropertiesSet();
View Full Code Here

Examples of org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter

  }

  @Test
  public void testInvalidListener() throws Exception {
    PojoListener delegate = new PojoListener(null);
    MessageListenerAdapter messageListenerAdapter = new MessageListenerAdapter(delegate);
    messageListenerAdapter.setDefaultListenerMethod("foo");
    this.container = createContainer(messageListenerAdapter, queue.getName());
    assertTrue(containerStoppedForAbortWithBadListener());
  }
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.