/** * Get the MessageChannel to use for sending messages to clients, possibly * a per-session wrapper when {@code preservePublishOrder=true}. * @since 5.1 */ protected MessageChannel getClientOutboundChannelForSession(String sessionId) { return this.preservePublishOrder ? new OrderedMessageSender(getClientOutboundChannel(), logger) : getClientOutboundChannel(); }
/** * Whether the client must receive messages in the order of publication. * <p>By default messages sent to the {@code "clientOutboundChannel"} may * not be processed in the same order because the channel is backed by a * ThreadPoolExecutor that in turn does not guarantee processing in order. * <p>When this flag is set to {@code true} messages within the same session * will be sent to the {@code "clientOutboundChannel"} one at a time in * order to preserve the order of publication. Enable this only if needed * since there is some performance overhead to keep messages in order. * @param preservePublishOrder whether to publish in order * @since 5.1 */ public void setPreservePublishOrder(boolean preservePublishOrder) { OrderedMessageSender.configureOutboundChannel(this.clientOutboundChannel, preservePublishOrder); this.preservePublishOrder = preservePublishOrder; }
public boolean send(Message<?> message) { return send(message, -1); }
private void sendNextMessage() { for (;;) { Message<?> message = this.messages.poll(); if (message != null) { try { addCompletionCallback(message); if (this.channel.send(message)) { return; } } catch (Throwable ex) { if (logger.isErrorEnabled()) { logger.error("Failed to send " + message, ex); } } } else { // We ran out of messages.. this.sendInProgress.set(false); trySend(); break; } } }
@Before public void setup() { this.executor = new ThreadPoolTaskExecutor(); this.executor.setCorePoolSize(Runtime.getRuntime().availableProcessors() * 2); this.executor.setAllowCoreThreadTimeOut(true); this.executor.afterPropertiesSet(); this.channel = new ExecutorSubscribableChannel(this.executor); OrderedMessageSender.configureOutboundChannel(this.channel, true); this.sender = new OrderedMessageSender(this.channel, logger); }
private void trySend() { // Take sendInProgress flag only if queue is not empty if (this.messages.isEmpty()) { return; } if (this.sendInProgress.compareAndSet(false, true)) { sendNextMessage(); } }
@Override public boolean send(Message<?> message, long timeout) { this.messages.add(message); trySend(); return true; }
private void sendNextMessage() { for (;;) { Message<?> message = this.messages.poll(); if (message != null) { try { addCompletionCallback(message); if (this.channel.send(message)) { return; } } catch (Throwable ex) { if (logger.isErrorEnabled()) { logger.error("Failed to send " + message, ex); } } } else { // We ran out of messages.. this.sendInProgress.set(false); trySend(); break; } } }
private void trySend() { // Take sendInProgress flag only if queue is not empty if (this.messages.isEmpty()) { return; } if (this.sendInProgress.compareAndSet(false, true)) { sendNextMessage(); } }
@Override public boolean send(Message<?> message, long timeout) { this.messages.add(message); trySend(); return true; }
private void sendNextMessage() { for (;;) { Message<?> message = this.messages.poll(); if (message != null) { try { addCompletionCallback(message); if (this.channel.send(message)) { return; } } catch (Throwable ex) { if (logger.isErrorEnabled()) { logger.error("Failed to send " + message, ex); } } } else { // We ran out of messages.. this.sendInProgress.set(false); trySend(); break; } } }
accessor.setHeader("seq", i); accessor.setLeaveMutable(true); this.sender.send(MessageBuilder.createMessage("payload", accessor.getMessageHeaders()));
/** * Get the MessageChannel to use for sending messages to clients, possibly * a per-session wrapper when {@code preservePublishOrder=true}. * @since 5.1 */ protected MessageChannel getClientOutboundChannelForSession(String sessionId) { return this.preservePublishOrder ? new OrderedMessageSender(getClientOutboundChannel(), logger) : getClientOutboundChannel(); }
/** * Whether the client must receive messages in the order of publication. * <p>By default messages sent to the {@code "clientOutboundChannel"} may * not be processed in the same order because the channel is backed by a * ThreadPoolExecutor that in turn does not guarantee processing in order. * <p>When this flag is set to {@code true} messages within the same session * will be sent to the {@code "clientOutboundChannel"} one at a time in * order to preserve the order of publication. Enable this only if needed * since there is some performance overhead to keep messages in order. * @param preservePublishOrder whether to publish in order * @since 5.1 */ public void setPreservePublishOrder(boolean preservePublishOrder) { OrderedMessageSender.configureOutboundChannel(this.clientOutboundChannel, preservePublishOrder); this.preservePublishOrder = preservePublishOrder; }
private void trySend() { // Take sendInProgress flag only if queue is not empty if (this.messages.isEmpty()) { return; } if (this.sendInProgress.compareAndSet(false, true)) { sendNextMessage(); } }
@Override public boolean send(Message<?> message, long timeout) { this.messages.add(message); trySend(); return true; }
private void sendNextMessage() { for (;;) { Message<?> message = this.messages.poll(); if (message != null) { try { addCompletionCallback(message); if (this.channel.send(message)) { return; } } catch (Throwable ex) { if (logger.isErrorEnabled()) { logger.error("Failed to send " + message, ex); } } } else { // We ran out of messages.. this.sendInProgress.set(false); trySend(); break; } } }
public boolean send(Message<?> message) { return send(message, -1); }
/** * Get the MessageChannel to use for sending messages to clients, possibly * a per-session wrapper when {@code preservePublishOrder=true}. * @since 5.1 */ protected MessageChannel getClientOutboundChannelForSession(String sessionId) { return this.preservePublishOrder ? new OrderedMessageSender(getClientOutboundChannel(), logger) : getClientOutboundChannel(); }
/** * Whether the client must receive messages in the order of publication. * <p>By default messages sent to the {@code "clientOutboundChannel"} may * not be processed in the same order because the channel is backed by a * ThreadPoolExecutor that in turn does not guarantee processing in order. * <p>When this flag is set to {@code true} messages within the same session * will be sent to the {@code "clientOutboundChannel"} one at a time in * order to preserve the order of publication. Enable this only if needed * since there is some performance overhead to keep messages in order. * @param preservePublishOrder whether to publish in order * @since 5.1 */ public void setPreservePublishOrder(boolean preservePublishOrder) { OrderedMessageSender.configureOutboundChannel(this.clientOutboundChannel, preservePublishOrder); this.preservePublishOrder = preservePublishOrder; }