Order property for SimpUserRegistry

Issue:SPR-17142
This commit is contained in:
Rossen Stoyanchev
2018-08-13 10:48:17 +03:00
parent 5322fa0fb7
commit 430065c31d
4 changed files with 97 additions and 9 deletions

View File

@@ -27,6 +27,7 @@ import org.springframework.beans.factory.BeanInitializationException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.event.SmartApplicationListener;
import org.springframework.lang.Nullable;
import org.springframework.messaging.MessageHandler;
import org.springframework.messaging.converter.ByteArrayMessageConverter;
@@ -419,15 +420,32 @@ public abstract class AbstractMessageBrokerConfiguration implements ApplicationC
}
@Bean
@SuppressWarnings("deprecation")
public SimpUserRegistry userRegistry() {
return (getBrokerRegistry().getUserRegistryBroadcast() != null ?
new MultiServerUserRegistry(createLocalUserRegistry()) : createLocalUserRegistry());
SimpUserRegistry registry = createLocalUserRegistry();
if (registry == null) {
registry = createLocalUserRegistry(getBrokerRegistry().getUserRegistryOrder());
}
boolean broadcast = getBrokerRegistry().getUserRegistryBroadcast() != null;
return (broadcast ? new MultiServerUserRegistry(registry) : registry);
}
/**
* Create the user registry that provides access to the local users.
* Create the user registry that provides access to local users.
* @deprecated as of 5.1 in favor of {@link #createLocalUserRegistry(Integer)}
*/
protected abstract SimpUserRegistry createLocalUserRegistry();
@Deprecated
@Nullable
protected SimpUserRegistry createLocalUserRegistry() {
return null;
}
/**
* Create the user registry that provides access to local users.
* @param order the order to use as a {@link SmartApplicationListener}.
* @since 5.1
*/
protected abstract SimpUserRegistry createLocalUserRegistry(@Nullable Integer order);
/**
* Return a {@link org.springframework.validation.Validator

View File

@@ -19,6 +19,7 @@ package org.springframework.messaging.simp.config;
import java.util.Arrays;
import java.util.Collection;
import org.springframework.context.event.SmartApplicationListener;
import org.springframework.lang.Nullable;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.SubscribableChannel;
@@ -54,6 +55,9 @@ public class MessageBrokerRegistry {
@Nullable
private String userDestinationPrefix;
@Nullable
private Integer userRegistryOrder;
@Nullable
private PathMatcher pathMatcher;
@@ -162,6 +166,22 @@ public class MessageBrokerRegistry {
return this.userDestinationPrefix;
}
/**
* Set the order for the
* {@link org.springframework.messaging.simp.user.SimpUserRegistry
* SimpUserRegistry} to use as a {@link SmartApplicationListener}.
* @param order the order value
* @since 5.0.8
*/
public void setUserRegistryOrder(int order) {
this.userRegistryOrder = order;
}
@Nullable
protected Integer getUserRegistryOrder() {
return this.userRegistryOrder;
}
/**
* Configure the PathMatcher to use to match the destinations of incoming
* messages to {@code @MessageMapping} and {@code @SubscribeMapping} methods.