Polishing

This commit is contained in:
Juergen Hoeller
2014-08-23 02:02:38 +02:00
parent 93ad7f8def
commit eb3509a37c
3 changed files with 34 additions and 41 deletions

View File

@@ -41,12 +41,12 @@ public class MessageBrokerRegistry {
private StompBrokerRelayRegistration brokerRelayRegistration;
private final ChannelRegistration brokerChannelRegistration = new ChannelRegistration();
private String[] applicationDestinationPrefixes;
private String userDestinationPrefix;
private ChannelRegistration brokerChannelRegistration = new ChannelRegistration();
public MessageBrokerRegistry(SubscribableChannel clientInboundChannel, MessageChannel clientOutboundChannel) {
Assert.notNull(clientInboundChannel);
@@ -55,6 +55,7 @@ public class MessageBrokerRegistry {
this.clientOutboundChannel = clientOutboundChannel;
}
/**
* Enable a simple message broker and configure one or more prefixes to filter
* destinations targeting the broker (e.g. destinations prefixed with "/topic").
@@ -76,6 +77,21 @@ public class MessageBrokerRegistry {
return this.brokerRelayRegistration;
}
/**
* Customize the channel used to send messages from the application to the message
* broker. By default, messages from the application to the message broker are sent
* synchronously, which means application code sending a message will find out
* if the message cannot be sent through an exception. However, this can be changed
* if the broker channel is configured here with task executor properties.
*/
public ChannelRegistration configureBrokerChannel() {
return this.brokerChannelRegistration;
}
protected ChannelRegistration getBrokerChannelRegistration() {
return this.brokerChannelRegistration;
}
/**
* Configure one or more prefixes to filter destinations targeting application
* annotated methods. For example destinations prefixed with "/app" may be
@@ -91,6 +107,11 @@ public class MessageBrokerRegistry {
return this;
}
protected Collection<String> getApplicationDestinationPrefixes() {
return (this.applicationDestinationPrefixes != null ?
Arrays.asList(this.applicationDestinationPrefixes) : null);
}
/**
* Configure the prefix used to identify user destinations. User destinations
* provide the ability for a user to subscribe to queue names unique to their
@@ -108,19 +129,13 @@ public class MessageBrokerRegistry {
return this;
}
/**
* Customize the channel used to send messages from the application to the message
* broker. By default messages from the application to the message broker are sent
* synchronously, which means application code sending a message will find out
* if the message cannot be sent through an exception. However, this can be changed
* if the broker channel is configured here with task executor properties.
*/
public ChannelRegistration configureBrokerChannel() {
return this.brokerChannelRegistration;
protected String getUserDestinationPrefix() {
return this.userDestinationPrefix;
}
protected SimpleBrokerMessageHandler getSimpleBroker(SubscribableChannel brokerChannel) {
if ((this.simpleBrokerRegistration == null) && (this.brokerRelayRegistration == null)) {
if (this.simpleBrokerRegistration == null && this.brokerRelayRegistration == null) {
enableSimpleBroker();
}
if (this.simpleBrokerRegistration != null) {
@@ -136,16 +151,4 @@ public class MessageBrokerRegistry {
return null;
}
protected Collection<String> getApplicationDestinationPrefixes() {
return (this.applicationDestinationPrefixes != null)
? Arrays.asList(this.applicationDestinationPrefixes) : null;
}
protected String getUserDestinationPrefix() {
return this.userDestinationPrefix;
}
protected ChannelRegistration getBrokerChannelRegistration() {
return this.brokerChannelRegistration;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,14 +28,10 @@ import org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler;
*/
public class SimpleBrokerRegistration extends AbstractBrokerRegistration {
public SimpleBrokerRegistration(SubscribableChannel clientInboundChannel,
MessageChannel clientOutboundChannel, String[] destinationPrefixes) {
super(clientInboundChannel, clientOutboundChannel, destinationPrefixes);
public SimpleBrokerRegistration(SubscribableChannel inChannel, MessageChannel outChannel, String[] prefixes) {
super(inChannel, outChannel, prefixes);
}
@Override
protected SimpleBrokerMessageHandler getMessageHandler(SubscribableChannel brokerChannel) {
return new SimpleBrokerMessageHandler(getClientInboundChannel(),

View File

@@ -74,12 +74,10 @@ public class StompBrokerRelayRegistration extends AbstractBrokerRegistration {
return this;
}
/**
* Set the login to use when creating connections to the STOMP broker on
* behalf of connected clients.
* <p>
* By default this is set to "guest".
* <p>By default this is set to "guest".
*/
public StompBrokerRelayRegistration setClientLogin(String login) {
Assert.hasText(login, "clientLogin must not be empty");
@@ -90,8 +88,7 @@ public class StompBrokerRelayRegistration extends AbstractBrokerRegistration {
/**
* Set the passcode to use when creating connections to the STOMP broker on
* behalf of connected clients.
* <p>
* By default this is set to "guest".
* <p>By default this is set to "guest".
*/
public StompBrokerRelayRegistration setClientPasscode(String passcode) {
Assert.hasText(passcode, "clientPasscode must not be empty");
@@ -103,8 +100,7 @@ public class StompBrokerRelayRegistration extends AbstractBrokerRegistration {
* Set the login for the shared "system" connection used to send messages to
* the STOMP broker from within the application, i.e. messages not associated
* with a specific client session (e.g. REST/HTTP request handling method).
* <p>
* By default this is set to "guest".
* <p>By default this is set to "guest".
*/
public StompBrokerRelayRegistration setSystemLogin(String login) {
Assert.hasText(login, "systemLogin must not be empty");
@@ -116,8 +112,7 @@ public class StompBrokerRelayRegistration extends AbstractBrokerRegistration {
* Set the passcode for the shared "system" connection used to send messages to
* the STOMP broker from within the application, i.e. messages not associated
* with a specific client session (e.g. REST/HTTP request handling method).
* <p>
* By default this is set to "guest".
* <p>By default this is set to "guest".
*/
public StompBrokerRelayRegistration setSystemPasscode(String passcode) {
Assert.hasText(passcode, "systemPasscode must not be empty");
@@ -173,7 +168,6 @@ public class StompBrokerRelayRegistration extends AbstractBrokerRegistration {
protected StompBrokerRelayMessageHandler getMessageHandler(SubscribableChannel brokerChannel) {
StompBrokerRelayMessageHandler handler = new StompBrokerRelayMessageHandler(getClientInboundChannel(),
getClientOutboundChannel(), brokerChannel, getDestinationPrefixes());