Annotation Interface Topic


@Documented @Retention(RUNTIME) @Target(METHOD) @Executable(processOnStartup=true) @MessageMapping public @interface Topic
Annotation to bind a Topic to a method for receiving or sending a Message.

Usage:

@JMSListener("myConnectionFactory")
public class Listener {
     @Topic("my-topic")
     public <T> void handle(@MessageBody T body, @MessageHeader(JMSHeaders.JMS_MESSAGE_ID) String messageID) {
         // do some logic with body and messageID
     }

     @Topic(value = "my-topic-2", subscription = "my-subscription", shared = true, consumers = 3)
     public <T> void handleConcurrently(@MessageBody T body, @MessageHeader("X-Arbitrary-Header") String arbitraryHeader) {
         // do some logic with body and arbitraryHeader
     }
}
Since:
1.0.0
Author:
Elliott Pope
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    The name of the topic to target.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    int
     
    The client ID of the listener's connection.
    int
    The number of consumers of the listener method, each with its own session, so that messages are handled concurrently.
    The delivery mode of the messages that a producer method sends.
    The name of a Deserializer in the bean context that a listener method uses to convert each Message of the topic into its @MessageBody argument.
    boolean
    Whether the subscription is durable, so messages published while the listener is not connected are kept for it.
    The error handlers to be injected into the message handling logic.
     
    int
    The priority, from 0 (lowest) to 9, of the messages that a producer method sends.
    The name of a Serializer in the bean context to use to serialize an object into a Message when sending.
    boolean
    Whether the subscription is shared, so its messages are spread over every listener with the same subscription name.
    The name of the subscription.
    The success handlers to be injected into the message handling logic.
    boolean
    Whether the session is transacted.
  • Element Details

    • value

      @AliasFor(annotation=io.micronaut.messaging.annotation.MessageMapping.class, member="value") String value
      The name of the topic to target.
      Returns:
      the name
    • serializer

      String serializer
      The name of a Serializer in the bean context to use to serialize an object into a Message when sending. If not specified, defaults to DefaultSerializerDeserializer.
      Returns:
      the serializer bean name
      Default:
      ""
    • acknowledgeMode

      int acknowledgeMode
      Returns:
      the acknowledge mode for the JMSListener.
      See Also:
      • Session
      Default:
      1
    • transacted

      boolean transacted
      Whether the session is transacted. The broker must support transacted sessions.

      On a listener, message receipt is transacted: the session is committed once the method returns and rolled back if it fails. On a producer method, each message is sent on a transacted session of its own, committed after the send. That transaction is the producer's own: a producer method called from a transacted listener does not join the listener's transaction, so its message is committed even if the listener's transaction is rolled back. To send in the listener's transaction, send with the listener's Session.

      Returns:
      true if transacted
      See Also:
      • Session
      Default:
      false
    • messageSelector

      String messageSelector
      Returns:
      the message selector for the topic
      Default:
      ""
    • consumers

      int consumers
      The number of consumers of the listener method, each with its own session, so that messages are handled concurrently. The consumers share one connection. The listener bean is a single instance whose method is then called on several threads at once, so it must be thread-safe, and messages are no longer processed in the order they were sent. More than one consumer requires a shared() subscription: every consumer of a topic listener without a subscription would receive every message, and an unshared durable subscription allows only one consumer. Ignored by producers.
      Returns:
      the number of consumers
      Since:
      5.2.0
      Default:
      1
    • deliveryMode

      JMSDeliveryMode deliveryMode
      The delivery mode of the messages that a producer method sends. Ignored by listeners. A MessageDeliveryMode argument overrides it.
      Returns:
      the delivery mode
      Since:
      5.2.0
      Default:
      PERSISTENT
    • priority

      int priority
      The priority, from 0 (lowest) to 9, of the messages that a producer method sends. Ignored by listeners. A MessagePriority argument overrides it.
      Returns:
      the priority
      Since:
      5.2.0
      Default:
      4
    • subscription

      String subscription
      The name of the subscription. Required when durable(), shared() or clientId() is set, and requires durable() or shared() in turn; ignored on producers.
      Returns:
      the subscription name
      Since:
      5.2.0
      Default:
      ""
    • durable

      boolean durable
      Whether the subscription is durable, so messages published while the listener is not connected are kept for it. An unshared durable subscription gets a connection of its own, with the clientId() as its client ID.
      Returns:
      whether the subscription is durable
      Since:
      5.2.0
      Default:
      false
    • shared

      boolean shared
      Whether the subscription is shared, so its messages are spread over every listener with the same subscription name. Requires a JMS 2.0 provider.
      Returns:
      whether the subscription is shared
      Since:
      5.2.0
      Default:
      false
    • clientId

      String clientId
      The client ID of the listener's connection. Defaults to the subscription() name for an unshared durable subscription. When set, the listener gets a connection of its own.
      Returns:
      the client ID
      Since:
      5.2.0
      Default:
      ""
    • deserializer

      String deserializer
      The name of a Deserializer in the bean context that a listener method uses to convert each Message of the topic into its @MessageBody argument. If not specified, defaults to DefaultSerializerDeserializer.
      Returns:
      the deserializer bean name
      Since:
      5.2.0
      Default:
      ""
    • successHandlers

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

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