@SuppressWarnings("unchecked") private Map<String, List<String>> getNativeHeaders(Message<?> message) { return (Map<String, List<String>>) message.getHeaders().get( NativeMessageHeaderAccessor.NATIVE_HEADERS); }
/** * Create a new message with the given payload. * @param payload the message payload (never {@code null}) */ public GenericMessage(T payload) { this(payload, new MessageHeaders(null)); }
@Override public final void stop() { synchronized (this.lifecycleMonitor) { this.running = false; this.clientInboundChannel.unsubscribe(this); } }
private void assertTextMessage(Message<?> message) { assertNotNull("message should not be null", message); assertEquals("Wrong payload", "Hello", message.getPayload()); assertEquals("Invalid foo property", "bar", message.getHeaders().get("foo")); }
@Override public void handleMessage(Message<?> message) throws MessagingException { MessageChannel replyChannel = (MessageChannel) message.getHeaders().getReplyChannel(); replyChannel.send(new GenericMessage<>("response")); } });
private void sendInternal(Message<?> message) { String destination = SimpMessageHeaderAccessor.getDestination(message.getHeaders()); Assert.notNull(destination, "Destination header required"); long timeout = this.sendTimeout; boolean sent = (timeout >= 0 ? this.messageChannel.send(message, timeout) : this.messageChannel.send(message)); if (!sent) { throw new MessageDeliveryException(message, "Failed to send message to destination '" + destination + "' within timeout: " + timeout); } }
@Override public ListenableFuture<Void> forward(Message<?> message, StompHeaderAccessor accessor) { try { ListenableFuture<Void> future = super.forward(message, accessor); if (message.getHeaders().get(SimpMessageHeaderAccessor.IGNORE_ERROR) == null) { future.get(); } return future; } catch (Throwable ex) { throw new MessageDeliveryException(message, ex); } } }
private long sendTimeout(Message<?> requestMessage) { Long sendTimeout = headerToLong(requestMessage.getHeaders().get(this.sendTimeoutHeader)); return (sendTimeout != null ? sendTimeout : this.sendTimeout); }
protected void handleInboundMessage(Message<?> message) { if (this.isRemoteClientSession) { this.outboundChannel.send(message); } }
@Override public final void start() { synchronized (this.lifecycleMonitor) { this.clientInboundChannel.subscribe(this); this.running = true; } }
@Override public void afterMessageHandled( Message<?> msg, MessageChannel ch, MessageHandler handler, @Nullable Exception ex) { Runnable task = (Runnable) msg.getHeaders().get(OrderedMessageSender.COMPLETION_TASK_HEADER); if (task != null) { task.run(); } } }
private long receiveTimeout(Message<?> requestMessage) { Long receiveTimeout = headerToLong(requestMessage.getHeaders().get(this.receiveTimeoutHeader)); return (receiveTimeout != null ? receiveTimeout : this.receiveTimeout); }
/** * Send a {@link Message} to this channel. If the message is sent successfully, * the method returns {@code true}. If the message cannot be sent due to a * non-fatal reason, the method returns {@code false}. The method may also * throw a RuntimeException in case of non-recoverable errors. * <p>This method may block indefinitely, depending on the implementation. * To provide a maximum wait time, use {@link #send(Message, long)}. * @param message the message to send * @return whether or not the message was sent */ default boolean send(Message<?> message) { return send(message, INDEFINITE_TIMEOUT); }
/** * Create a new message with the given payload and headers. * The content of the given header map is copied. * @param payload the message payload (never {@code null}) * @param headers message headers to use for initialization */ public GenericMessage(T payload, Map<String, Object> headers) { this(payload, new MessageHeaders(headers)); }
@Override public final void stop() { synchronized (this.lifecycleMonitor) { this.running = false; this.clientInboundChannel.unsubscribe(this); this.brokerChannel.unsubscribe(this); } }
@Override @Nullable protected Object resolveArgumentInternal(MethodParameter parameter, Message<?> message, String name) throws Exception { @SuppressWarnings("unchecked") Map<String, String> vars = (Map<String, String>) message.getHeaders().get(DESTINATION_TEMPLATE_VARIABLES_HEADER); return (vars != null ? vars.get(name) : null); }
/** * Return a copy of the underlying header values as a {@link MessageHeaders} object. * <p>This method can be invoked many times, with modifications in between * where each new call returns a fresh copy of the current header values. * @since 4.1 */ public MessageHeaders toMessageHeaders() { return new MessageHeaders(this.headers); }
@Override protected String getDestination(Message<?> message) { return (String) message.getHeaders().get(DESTINATION_HEADER); }
protected Object writeReplace() { // Serialize as regular MessageHeaders (without MessageHeaderAccessor reference) return new MessageHeaders(this); } }