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 -
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionintThe client ID of the listener's connection.intThe 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 aDeserializerin the bean context that a listener method uses to convert eachMessageof the topic into its@MessageBodyargument.booleanWhether the subscription is durable, so messages published while the listener is not connected are kept for it.Class<? extends JMSListenerErrorHandler>[]The error handlers to be injected into the message handling logic.intThe priority, from 0 (lowest) to 9, of the messages that a producer method sends.The name of aSerializerin the bean context to use to serialize an object into aMessagewhen sending.booleanWhether the subscription is shared, so its messages are spread over every listener with the same subscription name.The name of the subscription.Class<? extends JMSListenerSuccessHandler>[]The success handlers to be injected into the message handling logic.booleanWhether the session is transacted.
-
Element Details
-
value
@AliasFor(annotation=io.micronaut.messaging.annotation.MessageMapping.class, member="value") String valueThe name of the topic to target.- Returns:
- the name
-
serializer
String serializerThe name of aSerializerin the bean context to use to serialize an object into aMessagewhen sending. If not specified, defaults toDefaultSerializerDeserializer.- Returns:
- the serializer bean name
- Default:
""
-
acknowledgeMode
-
transacted
boolean transactedWhether 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:
- Default:
false
-
messageSelector
-
consumers
int consumersThe 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 ashared()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 deliveryModeThe delivery mode of the messages that a producer method sends. Ignored by listeners. AMessageDeliveryModeargument overrides it.- Returns:
- the delivery mode
- Since:
- 5.2.0
- Default:
PERSISTENT
-
priority
int priorityThe priority, from 0 (lowest) to 9, of the messages that a producer method sends. Ignored by listeners. AMessagePriorityargument overrides it.- Returns:
- the priority
- Since:
- 5.2.0
- Default:
4
-
subscription
-
durable
boolean durableWhether 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 theclientId()as its client ID.- Returns:
- whether the subscription is durable
- Since:
- 5.2.0
- Default:
false
-
clientId
String clientIdThe client ID of the listener's connection. Defaults to thesubscription()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 deserializerThe name of aDeserializerin the bean context that a listener method uses to convert eachMessageof the topic into its@MessageBodyargument. If not specified, defaults toDefaultSerializerDeserializer.- Returns:
- the deserializer bean name
- Since:
- 5.2.0
- Default:
""
-
successHandlers
Class<? extends JMSListenerSuccessHandler>[] successHandlersThe 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
Singletoninstances. - Since:
- 3.0.0
- Default:
{}
-
errorHandlers
Class<? extends JMSListenerErrorHandler>[] errorHandlersThe 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
Singletoninstances. - Since:
- 3.0.0
- Default:
{}
-