spring-framework / org.springframework.messaging.simp.annotation / SubscribeMapping

SubscribeMapping

@Target([AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER]) class SubscribeMapping

Annotation for mapping subscription messages onto specific handler methods based on the destination of a subscription. Supported with STOMP over WebSocket only (e.g. STOMP SUBSCRIBE frame).

This is a method-level annotation that can be combined with a type-level org.springframework.messaging.handler.annotation.MessageMapping.

Supports the same method arguments as @MessageMapping; however, subscription messages typically do not have a body.

The return value also follows the same rules as for @MessageMapping, except if the method is not annotated with org.springframework.messaging.handler.annotation.SendTo or SendToUser, the message is sent directly back to the connected user and does not pass through the message broker. This is useful for implementing a request-reply pattern.

NOTE: When using controller interfaces (e.g. for AOP proxying), make sure to consistently put all your mapping annotations - such as @MessageMapping and @SubscribeMapping - on the controller interface rather than on the implementation class.

Author
Rossen Stoyanchev

Since
4.0

See Also
org.springframework.messaging.handler.annotation.MessageMappingorg.springframework.messaging.handler.annotation.SendToorg.springframework.messaging.simp.annotation.SendToUser

Constructors

<init>

SubscribeMapping(vararg value: String)

Annotation for mapping subscription messages onto specific handler methods based on the destination of a subscription. Supported with STOMP over WebSocket only (e.g. STOMP SUBSCRIBE frame).

This is a method-level annotation that can be combined with a type-level org.springframework.messaging.handler.annotation.MessageMapping.

Supports the same method arguments as @MessageMapping; however, subscription messages typically do not have a body.

The return value also follows the same rules as for @MessageMapping, except if the method is not annotated with org.springframework.messaging.handler.annotation.SendTo or SendToUser, the message is sent directly back to the connected user and does not pass through the message broker. This is useful for implementing a request-reply pattern.

NOTE: When using controller interfaces (e.g. for AOP proxying), make sure to consistently put all your mapping annotations - such as @MessageMapping and @SubscribeMapping - on the controller interface rather than on the implementation class.

Properties

value

val value: Array<String>

Destination-based mapping expressed by this annotation.

This is the destination of the STOMP message (e.g. "/positions"). Ant-style path patterns (e.g. "/price.stock.*") and path template variables (e.g. "/price.stock.{ticker}") are also supported.