001/*
002 * Copyright 2002-2015 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.messaging.simp.annotation;
018
019import java.lang.annotation.Documented;
020import java.lang.annotation.ElementType;
021import java.lang.annotation.Retention;
022import java.lang.annotation.RetentionPolicy;
023import java.lang.annotation.Target;
024
025/**
026 * Annotation for mapping subscription messages onto specific handler methods based
027 * on the destination of a subscription. Supported with STOMP over WebSocket only
028 * (e.g. STOMP SUBSCRIBE frame).
029 *
030 * <p>This is a method-level annotation that can be combined with a type-level
031 * {@link org.springframework.messaging.handler.annotation.MessageMapping @MessageMapping}.
032 *
033 * <p>Supports the same method arguments as {@code @MessageMapping}; however,
034 * subscription messages typically do not have a body.
035 *
036 * <p>The return value also follows the same rules as for {@code @MessageMapping},
037 * except if the method is not annotated with
038 * {@link org.springframework.messaging.handler.annotation.SendTo SendTo} or
039 * {@link SendToUser}, the message is sent directly back to the connected
040 * user and does not pass through the message broker. This is useful for
041 * implementing a request-reply pattern.
042 *
043 * <p><b>NOTE:</b> When using controller interfaces (e.g. for AOP proxying),
044 * make sure to consistently put <i>all</i> your mapping annotations - such as
045 * {@code @MessageMapping} and {@code @SubscribeMapping} - on
046 * the controller <i>interface</i> rather than on the implementation class.
047 *
048 * @author Rossen Stoyanchev
049 * @since 4.0
050 * @see org.springframework.messaging.handler.annotation.MessageMapping
051 * @see org.springframework.messaging.handler.annotation.SendTo
052 * @see org.springframework.messaging.simp.annotation.SendToUser
053 */
054@Target(ElementType.METHOD)
055@Retention(RetentionPolicy.RUNTIME)
056@Documented
057public @interface SubscribeMapping {
058
059        /**
060         * Destination-based mapping expressed by this annotation.
061         * <p>This is the destination of the STOMP message (e.g. {@code "/positions"}).
062         * Ant-style path patterns (e.g. {@code "/price.stock.*"}) and path template
063         * variables (e.g. <code>"/price.stock.{ticker}"</code>) are also supported.
064         */
065        String[] value() default {};
066
067}