Tabnine Logo
DirectMessageListenerContainer.setMessageListener
Code IndexAdd Tabnine to your IDE (free)

How to use
setMessageListener
method
in
org.springframework.amqp.rabbit.listener.DirectMessageListenerContainer

Best Java code snippets using org.springframework.amqp.rabbit.listener.DirectMessageListenerContainer.setMessageListener (Showing top 14 results out of 315)

origin: spring-projects/spring-amqp

@Override
public void setMessageListener(MessageListener messageListener) {
  if (messageListener instanceof ChannelAwareMessageListener) {
    super.setMessageListener((ChannelAwareMessageListener) (message, channel) -> {
      try {
        ((ChannelAwareMessageListener) messageListener).onMessage(message, channel);
      }
      finally {
        this.inUseConsumerChannels.remove(channel);
      }
    });
  }
  else {
    super.setMessageListener((ChannelAwareMessageListener) (message, channel) -> {
      try {
        messageListener.onMessage(message);
      }
      finally {
        this.inUseConsumerChannels.remove(channel);
      }
    });
  }
}
origin: org.springframework.amqp/spring-rabbit

@Override
public void setMessageListener(MessageListener messageListener) {
  if (messageListener instanceof ChannelAwareMessageListener) {
    super.setMessageListener((ChannelAwareMessageListener) (message, channel) -> {
      try {
        ((ChannelAwareMessageListener) messageListener).onMessage(message, channel);
      }
      finally {
        this.inUseConsumerChannels.remove(channel);
      }
    });
  }
  else {
    super.setMessageListener((ChannelAwareMessageListener) (message, channel) -> {
      try {
        messageListener.onMessage(message);
      }
      finally {
        this.inUseConsumerChannels.remove(channel);
      }
    });
  }
}
origin: spring-projects/spring-amqp

@Test
public void testEvents() throws Exception {
  CachingConnectionFactory cf = new CachingConnectionFactory("localhost");
  DirectMessageListenerContainer container = new DirectMessageListenerContainer(cf);
  container.setQueueNames(EQ1, EQ2);
  final List<Long> times = new ArrayList<>();
  final CountDownLatch latch1 = new CountDownLatch(2);
  final CountDownLatch latch2 = new CountDownLatch(2);
  container.setApplicationEventPublisher(event -> {
    if (event instanceof ListenerContainerIdleEvent) {
      times.add(System.currentTimeMillis());
      latch1.countDown();
    }
    else if (event instanceof ListenerContainerConsumerTerminatedEvent) {
      latch2.countDown();
    }
  });
  container.setMessageListener(m -> { });
  container.setIdleEventInterval(50L);
  container.setBeanName("events");
  container.setConsumerTagStrategy(new Tag());
  container.afterPropertiesSet();
  container.start();
  assertTrue(latch1.await(10, TimeUnit.SECONDS));
  assertThat(times.get(1) - times.get(0), greaterThanOrEqualTo(50L));
  brokerRunning.deleteQueues(EQ1, EQ2);
  assertTrue(latch2.await(10, TimeUnit.SECONDS));
  container.stop();
  cf.destroy();
}
origin: spring-projects/spring-amqp

@Test
public void testDeferredAcks() throws Exception {
  CachingConnectionFactory cf = new CachingConnectionFactory("localhost");
  DirectMessageListenerContainer container = new DirectMessageListenerContainer(cf);
  final CountDownLatch latch = new CountDownLatch(2);
  container.setMessageListener(m -> {
    latch.countDown();
  });
  container.setQueueNames(Q1);
  container.setBeanName("deferredAcks");
  container.setMessagesPerAck(2);
  container.afterPropertiesSet();
  container.start();
  RabbitTemplate rabbitTemplate = new RabbitTemplate(cf);
  rabbitTemplate.convertAndSend(Q1, "foo");
  rabbitTemplate.convertAndSend(Q1, "bar");
  assertTrue(latch.await(10, TimeUnit.SECONDS));
  container.stop();
  cf.destroy();
}
origin: spring-projects/spring-amqp

container.setMessagesPerAck(10);
container.setAckTimeout(100);
container.setMessageListener(m -> {
  if (m.getMessageProperties().getDeliveryTag() == 19L) {
    throw new RuntimeException("TestNackAndPendingAcks");
origin: spring-projects/spring-amqp

@Test
public void testNonManagedContainerStopsWhenConnectionFactoryDestroyed() throws Exception {
  CachingConnectionFactory cf = new CachingConnectionFactory("localhost");
  ApplicationContext context = mock(ApplicationContext.class);
  cf.setApplicationContext(context);
  DirectMessageListenerContainer container = new DirectMessageListenerContainer(cf);
  final CountDownLatch latch = new CountDownLatch(1);
  container.setMessageListener(m -> {
    latch.countDown();
  });
  container.setQueueNames(Q1);
  container.setBeanName("stopAfterDestroy");
  container.setIdleEventInterval(500);
  container.setFailedDeclarationRetryInterval(500);
  container.afterPropertiesSet();
  container.start();
  new RabbitTemplate(cf).convertAndSend(Q1, "foo");
  assertTrue(latch.await(10, TimeUnit.SECONDS));
  cf.onApplicationEvent(new ContextClosedEvent(context));
  cf.destroy();
  int n = 0;
  while (n++ < 100 && container.isRunning()) {
    Thread.sleep(100);
  }
  assertFalse(container.isRunning());
}
origin: spring-projects/spring-amqp

@Test
public void testAdvice() throws Exception {
  CachingConnectionFactory cf = new CachingConnectionFactory("localhost");
  DirectMessageListenerContainer container = new DirectMessageListenerContainer(cf);
  container.setQueueNames(Q1, Q2);
  container.setConsumersPerQueue(2);
  final CountDownLatch latch = new CountDownLatch(2);
  container.setMessageListener(m -> latch.countDown());
  final CountDownLatch adviceLatch = new CountDownLatch(2);
  MethodInterceptor advice = i -> {
    adviceLatch.countDown();
    return i.proceed();
  };
  container.setAdviceChain(advice);
  container.setBeanName("advice");
  container.setConsumerTagStrategy(new Tag());
  container.afterPropertiesSet();
  container.start();
  RabbitTemplate template = new RabbitTemplate(cf);
  template.convertAndSend(Q1, "foo");
  template.convertAndSend(Q1, "bar");
  assertTrue(latch.await(10, TimeUnit.SECONDS));
  assertTrue(adviceLatch.await(10, TimeUnit.SECONDS));
  container.stop();
  assertTrue(consumersOnQueue(Q1, 0));
  assertTrue(consumersOnQueue(Q2, 0));
  assertTrue(activeConsumerCount(container, 0));
  assertEquals(0, TestUtils.getPropertyValue(container, "consumersByQueue", MultiValueMap.class).size());
  cf.destroy();
}
origin: spring-projects/spring-amqp

@Test
public void testNonManagedContainerDoesntStartWhenConnectionFactoryDestroyed() throws Exception {
  CachingConnectionFactory cf = new CachingConnectionFactory("localhost");
  ApplicationContext context = mock(ApplicationContext.class);
  cf.setApplicationContext(context);
  cf.addConnectionListener(connection -> {
    cf.onApplicationEvent(new ContextClosedEvent(context));
    cf.destroy();
  });
  DirectMessageListenerContainer container = new DirectMessageListenerContainer(cf);
  container.setMessageListener(m -> { });
  container.setQueueNames(Q1);
  container.setBeanName("stopAfterDestroyBeforeStart");
  container.afterPropertiesSet();
  container.start();
  int n = 0;
  while (n++ < 100 && container.isRunning()) {
    Thread.sleep(100);
  }
  assertFalse(container.isRunning());
}
origin: spring-projects/spring-amqp

container.setQueueNames(Q1, Q2);
container.setConsumersPerQueue(2);
container.setMessageListener(new MessageListenerAdapter((ReplyingMessageListener<String, String>) in -> {
  if ("foo".equals(in) || "bar".equals(in)) {
    return in.toUpperCase();
origin: spring-projects/spring-amqp

container.setConsumersPerQueue(2);
final AtomicReference<Channel> channel = new AtomicReference<>();
container.setMessageListener((ChannelAwareMessageListener) (m, c) -> {
  channel.set(c);
  throw new MessageConversionException("intended - should be wrapped in an AmqpRejectAndDontRequeueException");
origin: spring-projects/spring-amqp

DirectMessageListenerContainer container = new DirectMessageListenerContainer(cf);
container.setConsumersPerQueue(2);
container.setMessageListener(new MessageListenerAdapter((ReplyingMessageListener<String, String>) in -> {
  if ("foo".equals(in) || "bar".equals(in)) {
    return in.toUpperCase();
origin: spring-projects/spring-amqp

container.setQueueNames(Q1, Q2);
container.setConsumersPerQueue(4);
container.setMessageListener(new MessageListenerAdapter((ReplyingMessageListener<String, String>) in -> {
  if ("foo".equals(in) || "bar".equals(in)) {
    return in.toUpperCase();
origin: spring-projects/spring-amqp

DirectMessageListenerContainer container = new DirectMessageListenerContainer(cf);
container.setConsumersPerQueue(2);
container.setMessageListener(new MessageListenerAdapter((ReplyingMessageListener<String, String>) in -> {
  if ("foo".equals(in) || "bar".equals(in)) {
    return in.toUpperCase();
origin: spring-projects/spring-amqp

container.setConsumersPerQueue(2);
container.setConsumersPerQueue(2);
container.setMessageListener(m -> { });
container.setFailedDeclarationRetryInterval(500);
container.setBeanName("deleteQauto=" + autoDeclare);
org.springframework.amqp.rabbit.listenerDirectMessageListenerContainersetMessageListener

Popular methods of DirectMessageListenerContainer

  • <init>
    Create an instance with the provided connection factory.
  • setConsumersPerQueue
    Each queue runs in its own consumer; set this property to create multiple consumers for each queue.
  • setAckTimeout
    An approximate timeout; when #setMessagesPerAck(int) is greater than 1, and this time elapses since
  • setMessagesPerAck
    Set the number of messages to receive before acknowledging (success). A failed message will short-ci
  • addQueues
  • afterPropertiesSet
  • getAcknowledgeMode
  • getConnectionFactory
  • getQueueNames
  • isActive
  • isRunning
  • removeQueues
  • isRunning,
  • removeQueues,
  • setIdleEventInterval,
  • setMissingQueuesFatal,
  • setMonitorInterval,
  • setPrefetchCount,
  • setQueueNames,
  • actualShutDown,
  • actualStart

Popular in Java

  • Updating database using SQL prepared statement
  • setScale (BigDecimal)
  • onCreateOptionsMenu (Activity)
  • compareTo (BigDecimal)
  • GridBagLayout (java.awt)
    The GridBagLayout class is a flexible layout manager that aligns components vertically and horizonta
  • URLEncoder (java.net)
    This class is used to encode a string using the format required by application/x-www-form-urlencoded
  • Date (java.sql)
    A class which can consume and produce dates in SQL Date format. Dates are represented in SQL as yyyy
  • JButton (javax.swing)
  • JOptionPane (javax.swing)
  • Scheduler (org.quartz)
    This is the main interface of a Quartz Scheduler. A Scheduler maintains a registry of org.quartz.Job
  • Best IntelliJ plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now