Annotation Interface JMSListener


@Documented @Retention(RUNTIME) @Target(TYPE) @Bean @DefaultScope(io.micronaut.context.annotation.Context.class) @MessageListener public @interface JMSListener
Declares a class for post-processing. Annotated classes must contain at least one method annotated with Queue or Topic, otherwise an IllegalStateException will be thrown.

Additionally, the value specified by the JMSProducer must correspond to exactly one JMSConnectionFactory or an IllegalStateException will be thrown.

Usage:

 @JMSConnectionFactory("connectionFactoryOne")
 public ConnectionFactory connectionFactoryOne() {
     return new ActiveMqConnectionFactory("vm://localhost?broker.persist=false");
 }

 @JMSConnectionFactory("connectionFactoryTwo")
 public ConnectionFactory connectionFactoryTwo() {
     RMQConnectionFactory connectionFactory = new RMQConnectionFactory();
     connectionFactory.setUsername("guest");
     connectionFactory.setPassword("guest");
     connectionFactory.setVirtualHost("/");
     connectionFactory.setHost("localhost");
     connectionFactory.setPort(5672);
     return connectionFactory;
 }

 @JMSListener("connectionFactoryOne")
 public static class ListenerOne {
      @Queue("my-activemq-queue")
      public void onMessage(String message) {
          // do logic
      }
 }

 @JMSListener("connectionFactoryTwo")
 public static class ListenerTwo {
      @Queue("my-rabbitmq-queue")
      public void handle(Integer message) {
          // do logic
      }
 }
 
Since:
1.0.0
Author:
Elliott Pope
  • Element Details

    • successHandlers

      Class<? extends JMSListenerSuccessHandler>[] successHandlers
      The success handlers to be injected into the message handling logic for all Queue or Topic methods.
      Returns:
      the classes of the success handlers to be added. These handlers must be present as Singleton instances.
      Default:
      {}
    • errorHandlers

      Class<? extends JMSListenerErrorHandler>[] errorHandlers
      The error handlers to be injected into the message handling logic for all Queue or Topic methods.
      Returns:
      the classes of the error handlers to be added. These handlers must be present as Singleton instances.
      Default:
      {}