001/* 002 * Copyright 2002-2018 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.web.socket.config.annotation; 018 019import java.util.List; 020 021import org.springframework.messaging.converter.MessageConverter; 022import org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver; 023import org.springframework.messaging.handler.invocation.HandlerMethodReturnValueHandler; 024import org.springframework.messaging.simp.config.ChannelRegistration; 025import org.springframework.messaging.simp.config.MessageBrokerRegistry; 026 027/** 028 * Defines methods for configuring message handling with simple messaging 029 * protocols (e.g. STOMP) from WebSocket clients. 030 * 031 * <p>Typically used to customize the configuration provided via 032 * {@link EnableWebSocketMessageBroker @EnableWebSocketMessageBroker}. 033 * 034 * @author Rossen Stoyanchev 035 * @since 4.0 036 */ 037public interface WebSocketMessageBrokerConfigurer { 038 039 /** 040 * Register STOMP endpoints mapping each to a specific URL and (optionally) 041 * enabling and configuring SockJS fallback options. 042 */ 043 default void registerStompEndpoints(StompEndpointRegistry registry) { 044 } 045 046 /** 047 * Configure options related to the processing of messages received from and 048 * sent to WebSocket clients. 049 */ 050 default void configureWebSocketTransport(WebSocketTransportRegistration registry) { 051 } 052 053 /** 054 * Configure the {@link org.springframework.messaging.MessageChannel} used for 055 * incoming messages from WebSocket clients. By default the channel is backed 056 * by a thread pool of size 1. It is recommended to customize thread pool 057 * settings for production use. 058 */ 059 default void configureClientInboundChannel(ChannelRegistration registration) { 060 } 061 062 /** 063 * Configure the {@link org.springframework.messaging.MessageChannel} used for 064 * outbound messages to WebSocket clients. By default the channel is backed 065 * by a thread pool of size 1. It is recommended to customize thread pool 066 * settings for production use. 067 */ 068 default void configureClientOutboundChannel(ChannelRegistration registration) { 069 } 070 071 /** 072 * Add resolvers to support custom controller method argument types. 073 * <p>This does not override the built-in support for resolving handler 074 * method arguments. To customize the built-in support for argument 075 * resolution, configure {@code SimpAnnotationMethodMessageHandler} directly. 076 * @param argumentResolvers the resolvers to register (initially an empty list) 077 * @since 4.1.1 078 */ 079 default void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) { 080 } 081 082 /** 083 * Add handlers to support custom controller method return value types. 084 * <p>Using this option does not override the built-in support for handling 085 * return values. To customize the built-in support for handling return 086 * values, configure {@code SimpAnnotationMethodMessageHandler} directly. 087 * @param returnValueHandlers the handlers to register (initially an empty list) 088 * @since 4.1.1 089 */ 090 default void addReturnValueHandlers(List<HandlerMethodReturnValueHandler> returnValueHandlers) { 091 } 092 093 /** 094 * Configure the message converters to use when extracting the payload of 095 * messages in annotated methods and when sending messages (e.g. through the 096 * "broker" SimpMessagingTemplate). 097 * <p>The provided list, initially empty, can be used to add message converters 098 * while the boolean return value is used to determine if default message should 099 * be added as well. 100 * @param messageConverters the converters to configure (initially an empty list) 101 * @return whether to also add default converter or not 102 */ 103 default boolean configureMessageConverters(List<MessageConverter> messageConverters) { 104 return true; 105 } 106 107 /** 108 * Configure message broker options. 109 */ 110 default void configureMessageBroker(MessageBrokerRegistry registry) { 111 } 112 113}