|
|
|
@ -84,22 +84,21 @@ public class SimpMessagingTemplate extends AbstractMessageSendingTemplate<String |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Configure a {@link MessageHeaderInitializer} to apply to the headers of all |
|
|
|
* Configure a {@link MessageHeaderInitializer} to apply to the headers of all |
|
|
|
* messages created through the {@code SimpMessagingTemplate}. |
|
|
|
* messages created through the {@code SimpMessagingTemplate}. |
|
|
|
* |
|
|
|
* <p>By default, this property is not set. |
|
|
|
* <p>By default this property is not set. |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void setHeaderInitializer(MessageHeaderInitializer headerInitializer) { |
|
|
|
public void setHeaderInitializer(MessageHeaderInitializer headerInitializer) { |
|
|
|
this.headerInitializer = headerInitializer; |
|
|
|
this.headerInitializer = headerInitializer; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @return the configured header initializer. |
|
|
|
* Return the configured header initializer. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public MessageHeaderInitializer getHeaderInitializer() { |
|
|
|
public MessageHeaderInitializer getHeaderInitializer() { |
|
|
|
return this.headerInitializer; |
|
|
|
return this.headerInitializer; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @return the messageChannel |
|
|
|
* Return the configured message channel. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public MessageChannel getMessageChannel() { |
|
|
|
public MessageChannel getMessageChannel() { |
|
|
|
return this.messageChannel; |
|
|
|
return this.messageChannel; |
|
|
|
@ -107,7 +106,6 @@ public class SimpMessagingTemplate extends AbstractMessageSendingTemplate<String |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Specify the timeout value to use for send operations. |
|
|
|
* Specify the timeout value to use for send operations. |
|
|
|
* |
|
|
|
|
|
|
|
* @param sendTimeout the send timeout in milliseconds |
|
|
|
* @param sendTimeout the send timeout in milliseconds |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void setSendTimeout(long sendTimeout) { |
|
|
|
public void setSendTimeout(long sendTimeout) { |
|
|
|
@ -115,7 +113,7 @@ public class SimpMessagingTemplate extends AbstractMessageSendingTemplate<String |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @return the sendTimeout |
|
|
|
* Return the configured send timeout. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public long getSendTimeout() { |
|
|
|
public long getSendTimeout() { |
|
|
|
return this.sendTimeout; |
|
|
|
return this.sendTimeout; |
|
|
|
@ -127,13 +125,11 @@ public class SimpMessagingTemplate extends AbstractMessageSendingTemplate<String |
|
|
|
* {@link org.springframework.messaging.simp.SimpMessageHeaderAccessor#DESTINATION_HEADER |
|
|
|
* {@link org.springframework.messaging.simp.SimpMessageHeaderAccessor#DESTINATION_HEADER |
|
|
|
* SimpMessageHeaderAccessor#DESTINATION_HEADER} then the message is sent without |
|
|
|
* SimpMessageHeaderAccessor#DESTINATION_HEADER} then the message is sent without |
|
|
|
* further changes. |
|
|
|
* further changes. |
|
|
|
* |
|
|
|
|
|
|
|
* <p>If a destination header is not already present ,the message is sent |
|
|
|
* <p>If a destination header is not already present ,the message is sent |
|
|
|
* to the configured {@link #setDefaultDestination(Object) defaultDestination} |
|
|
|
* to the configured {@link #setDefaultDestination(Object) defaultDestination} |
|
|
|
* or an exception an {@code IllegalStateException} is raised if that isn't |
|
|
|
* or an exception an {@code IllegalStateException} is raised if that isn't |
|
|
|
* configured. |
|
|
|
* configured. |
|
|
|
* |
|
|
|
* @param message the message to send (never {@code null}) |
|
|
|
* @param message the message to send, never {@code null} |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void send(Message<?> message) { |
|
|
|
public void send(Message<?> message) { |
|
|
|
@ -149,7 +145,6 @@ public class SimpMessagingTemplate extends AbstractMessageSendingTemplate<String |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected void doSend(String destination, Message<?> message) { |
|
|
|
protected void doSend(String destination, Message<?> message) { |
|
|
|
|
|
|
|
|
|
|
|
Assert.notNull(destination, "Destination must not be null"); |
|
|
|
Assert.notNull(destination, "Destination must not be null"); |
|
|
|
|
|
|
|
|
|
|
|
SimpMessageHeaderAccessor simpAccessor = |
|
|
|
SimpMessageHeaderAccessor simpAccessor = |
|
|
|
@ -181,14 +176,11 @@ public class SimpMessagingTemplate extends AbstractMessageSendingTemplate<String |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void sendInternal(Message<?> message) { |
|
|
|
private void sendInternal(Message<?> message) { |
|
|
|
|
|
|
|
|
|
|
|
String destination = SimpMessageHeaderAccessor.getDestination(message.getHeaders()); |
|
|
|
String destination = SimpMessageHeaderAccessor.getDestination(message.getHeaders()); |
|
|
|
Assert.notNull(destination); |
|
|
|
Assert.notNull(destination); |
|
|
|
|
|
|
|
|
|
|
|
long timeout = this.sendTimeout; |
|
|
|
long timeout = this.sendTimeout; |
|
|
|
boolean sent = (timeout >= 0) |
|
|
|
boolean sent = (timeout >= 0 ? this.messageChannel.send(message, timeout) : this.messageChannel.send(message)); |
|
|
|
? this.messageChannel.send(message, timeout) |
|
|
|
|
|
|
|
: this.messageChannel.send(message); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!sent) { |
|
|
|
if (!sent) { |
|
|
|
throw new MessageDeliveryException(message, |
|
|
|
throw new MessageDeliveryException(message, |
|
|
|
@ -204,21 +196,21 @@ public class SimpMessagingTemplate extends AbstractMessageSendingTemplate<String |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void convertAndSendToUser(String user, String destination, Object payload) throws MessagingException { |
|
|
|
public void convertAndSendToUser(String user, String destination, Object payload) throws MessagingException { |
|
|
|
this.convertAndSendToUser(user, destination, payload, (MessagePostProcessor) null); |
|
|
|
convertAndSendToUser(user, destination, payload, (MessagePostProcessor) null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void convertAndSendToUser(String user, String destination, Object payload, |
|
|
|
public void convertAndSendToUser(String user, String destination, Object payload, |
|
|
|
Map<String, Object> headers) throws MessagingException { |
|
|
|
Map<String, Object> headers) throws MessagingException { |
|
|
|
|
|
|
|
|
|
|
|
this.convertAndSendToUser(user, destination, payload, headers, null); |
|
|
|
convertAndSendToUser(user, destination, payload, headers, null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void convertAndSendToUser(String user, String destination, Object payload, |
|
|
|
public void convertAndSendToUser(String user, String destination, Object payload, |
|
|
|
MessagePostProcessor postProcessor) throws MessagingException { |
|
|
|
MessagePostProcessor postProcessor) throws MessagingException { |
|
|
|
|
|
|
|
|
|
|
|
this.convertAndSendToUser(user, destination, payload, null, postProcessor); |
|
|
|
convertAndSendToUser(user, destination, payload, null, postProcessor); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
@ -235,11 +227,9 @@ public class SimpMessagingTemplate extends AbstractMessageSendingTemplate<String |
|
|
|
* {@link org.springframework.messaging.support.NativeMessageHeaderAccessor#NATIVE_HEADERS NATIVE_HEADERS NATIVE_HEADERS NATIVE_HEADERS}. |
|
|
|
* {@link org.springframework.messaging.support.NativeMessageHeaderAccessor#NATIVE_HEADERS NATIVE_HEADERS NATIVE_HEADERS NATIVE_HEADERS}. |
|
|
|
* effectively treats the input header map as headers to be sent out to the |
|
|
|
* effectively treats the input header map as headers to be sent out to the |
|
|
|
* destination. |
|
|
|
* destination. |
|
|
|
* |
|
|
|
|
|
|
|
* <p>However if the given headers already contain the key |
|
|
|
* <p>However if the given headers already contain the key |
|
|
|
* {@code NATIVE_HEADERS NATIVE_HEADERS} then the same headers instance is |
|
|
|
* {@code NATIVE_HEADERS NATIVE_HEADERS} then the same headers instance is |
|
|
|
* returned without changes. |
|
|
|
* returned without changes. |
|
|
|
* |
|
|
|
|
|
|
|
* <p>Also if the given headers were prepared and obtained with |
|
|
|
* <p>Also if the given headers were prepared and obtained with |
|
|
|
* {@link SimpMessageHeaderAccessor#getMessageHeaders()} then the same headers |
|
|
|
* {@link SimpMessageHeaderAccessor#getMessageHeaders()} then the same headers |
|
|
|
* instance is also returned without changes. |
|
|
|
* instance is also returned without changes. |
|
|
|
|