private boolean doSend(Message<?> message, MessageChannel channel) { Assert.notNull(channel, "channel must not be null"); long timeout = this.sendTimeout; boolean sent = (timeout >= 0) ? channel.send(message, timeout) : channel.send(message); if (!sent && this.logger.isTraceEnabled()) { this.logger.trace("failed to send message to channel '" + channel + "' within timeout: " + timeout); } return sent; }
/** * Intercept the Message and, <em>if accepted</em> by the {@link MessageSelector}, * send it to the secondary target. If this wire tap's {@link MessageSelector} is * <code>null</code>, it will accept all messages. */ @Override public Message<?> preSend(Message<?> message, MessageChannel channel) { if (this.running && (this.selector == null || this.selector.accept(message))) { boolean sent = (this.timeout >= 0) ? this.channel.send(message, this.timeout) : this.channel.send(message); if (!sent && logger.isWarnEnabled()) { logger.warn("failed to send message to WireTap channel '" + this.channel + "'"); } } return message; }
@Override public Collection<String> determineTargetChannelNames(Integer payload, Map<String, Object> headers) throws InterruptProcessingException { if (payload==0) { throw new InterruptProcessingException("cannot determine for 0!"); } if (payload % 2 == 0) { return Arrays.asList(evenNumbersChannel.getName()); } else { return Arrays.asList(oddNumbersChannel.getName()); } }
public final void handle(Throwable t) { Message<?> failedMessage = (t instanceof MessagingException) ? ((MessagingException) t).getFailedMessage() : null; MessageChannel errorChannel = this.resolveErrorChannel(failedMessage); boolean sent = false; if (errorChannel != null) { try { if (this.sendTimeout >= 0) { sent = errorChannel.send(new ErrorMessage(t), this.sendTimeout); } else { sent = errorChannel.send(new ErrorMessage(t)); } } catch (Throwable errorDeliveryError) { // message will be logged only if (logger.isWarnEnabled()) { logger.warn("Error message was not delivered.", errorDeliveryError); } } } if (!sent && logger.isErrorEnabled()) { if (failedMessage != null) { logger.error("failure occurred in messaging task with message: " + failedMessage, t); } else { logger.error("failure occurred in messaging task", t); } } }
public boolean send(Message<?> message, long timeout) { Object replyChannelHeader = message.getHeaders().getReplyChannel(); if (replyChannelHeader == null) { throw new MessageHandlingException(message, "no replyChannel header available"); } MessageChannel replyChannel = null; if (replyChannelHeader instanceof MessageChannel) { replyChannel = (MessageChannel) replyChannelHeader; } else if (replyChannelHeader instanceof String) { Assert.notNull(getChannelResolver(), "ChannelResolver is required"); replyChannel = getChannelResolver().resolveChannelName((String) replyChannelHeader); } else { throw new MessageHandlingException(message, "invalid replyChannel type [" + replyChannelHeader.getClass() + "]"); } return (timeout >= 0) ? replyChannel.send(message, timeout) : replyChannel.send(message); } }
protected boolean processFinishing(String pid) { try { // cleaning iterator iterator.clean(); final Message<GenericProcessOrchestrationPayload> finishingMessage = messageRegistry.finish(pid); // send PROCESS_FINISHING message if (finishingMessage != null) { boolean sentSuccessfully = outputChannel.send(finishingMessage); if (!sentSuccessfully) { log.info("finishing error, failed to send reply Message"); errorHandler.handle(new MessageDeliveryException( finishingMessage, "failed to send reply Message")); } return sentSuccessfully; } else { log.error("got null finishing message from MessageRegistry!"); return false; } } catch (Exception e) { log.error("Error ocurred in MessageRegistry" + " during process finishing",e); return false; } }
protected boolean processInterrupting(String processId) { if (iterator==null) { // iterator builder does not finished its job, postponing interruption interruptPostponedWhileBuildingIterator = true; return true; } else { iterator.clean(); try { final Message<GenericProcessOrchestrationPayload> interruptingMessage = messageRegistry .interrupt(processId); // send PROCESS_INTERRUPTING message if (interruptingMessage != null) { boolean sentSuccessfully = outputChannel.send(interruptingMessage); if (!sentSuccessfully) { errorHandler.handle(new MessageDeliveryException( interruptingMessage, "failed to send reply Message")); } return sentSuccessfully; } else { log.error("got null interrupting message from MessageRegistry!"); return false; } } catch (Exception e) { log.error("Error ocurred in MessageRegistry" + " while interrupting process", e); return false; } } }