protected internal virtual void SendMessage(IMessage messageArg)
        {
            var message = messageArg;

            if (message == null)
            {
                throw new MessagingException("cannot send a null message");
            }

            try
            {
                if (OutputChannel == null)
                {
                    throw new InvalidOperationException("The 'outputChannel' or `outputChannelName` must be configured");
                }

                _messagingTemplate.Send(OutputChannel, message);
            }
            catch (Exception e)
            {
                if (!SendErrorMessageIfNecessary(message, e))
                {
                    throw;
                }
            }
        }
예제 #2
0
        public bool HandleError(Exception exception)
        {
            var errorChannel = ResolveErrorChannel(exception);
            var sent         = false;

            if (errorChannel != null)
            {
                try
                {
                    MessagingTemplate.Send(errorChannel, ErrorMessageStrategy.BuildErrorMessage(exception, null));
                    sent = true;
                }
                catch (Exception errorDeliveryError)
                {
                    _logger?.LogWarning("Error message was not delivered.", errorDeliveryError);
                }
            }

            if (!sent)
            {
                var failedMessage = (exception is MessagingException) ? ((MessagingException)exception).FailedMessage : null;
                if (failedMessage != null)
                {
                    _logger?.LogError("failure occurred in messaging task with message: " + failedMessage, exception);
                }
                else
                {
                    _logger?.LogError("failure occurred in messaging task", exception);
                }
            }

            return(sent);
        }
예제 #3
0
        protected virtual void SendOutput(object output, object replyChannelArg, bool useArgChannel)
        {
            var replyChannel = replyChannelArg;
            var outChannel   = OutputChannel;

            if (!useArgChannel && outChannel != null)
            {
                replyChannel = outChannel;
            }

            if (replyChannel == null)
            {
                throw new DestinationResolutionException("no output-channel or replyChannel header available");
            }

            var outputAsMessage = output as IMessage;

            if (replyChannel is IMessageChannel)
            {
                if (outputAsMessage != null)
                {
                    _messagingTemplate.Send((IMessageChannel)replyChannel, outputAsMessage);
                }
                else
                {
                    _messagingTemplate.ConvertAndSend((IMessageChannel)replyChannel, output);
                }
            }
            else if (replyChannel is string)
            {
                if (outputAsMessage != null)
                {
                    _messagingTemplate.Send((string)replyChannel, outputAsMessage);
                }
                else
                {
                    _messagingTemplate.ConvertAndSend((string)replyChannel, output);
                }
            }
            else
            {
                throw new MessagingException("replyChannel must be a IMessageChannel or String");
            }
        }
        protected internal virtual void SendMessage(IMessage messageArg)
        {
            var message = messageArg;

            if (message == null)
            {
                throw new MessagingException("cannot send a null message");
            }

            try
            {
                _messagingTemplate.Send(OutputChannel, message);
            }
            catch (Exception e)
            {
                if (!SendErrorMessageIfNecessary(message, e))
                {
                    throw;
                }
            }
        }