예제 #1
0
        /// <summary>
        /// Sends a new message to an existing queue
        /// </summary>
        /// <param name="messageToSend">The message to send.</param>
        /// <param name="data">The additional data.</param>
        /// <returns></returns>
        public async Task <IQueueOutputMessage> SendAsync(IMessage messageToSend, IAdditionalMessageData data)
        {
            //lets add a bit more information to the active span if possible
            using (var scope = _tracer.StartActivity("SendMessage"))
            {
                scope?.AddCommonTags(data, _connectionInformation);
                scope?.Add(data);
                scope?.SetTag("IsBatch", false);
                if (scope?.Context != null)
                {
                    messageToSend.Inject(_tracer, scope.Context, _headers.StandardHeaders);
                }
                try
                {
                    var outputMessage = await _handler.SendAsync(messageToSend, data);

                    if (outputMessage.HasError)
                    {
                        scope?.SetStatus(Status.Error);
                        if (outputMessage.SendingException != null)
                        {
                            scope?.RecordException(outputMessage.SendingException);
                        }
                    }
                    scope?.AddMessageIdTag(outputMessage.SentMessage.MessageId);
                    return(outputMessage);
                }
                catch (Exception e)
                {
                    scope?.SetStatus(Status.Error);
                    scope?.RecordException(e);
                    throw;
                }
            }
        }
        /// <summary>
        /// Sends a new message to an existing queue
        /// </summary>
        /// <param name="messageToSend">The message to send.</param>
        /// <param name="data">The additional data.</param>
        /// <returns></returns>
        public async Task <IQueueOutputMessage> SendAsync(IMessage messageToSend, IAdditionalMessageData data)
        {
            //lets add a bit more information to the active span if possible
            using (IScope scope = _tracer.BuildSpan("SendMessage").StartActive(finishSpanOnDispose: true))
            {
                scope.Span.AddCommonTags(data, _connectionInformation);
                scope.Span.Add(data);
                scope.Span.SetTag("IsBatch", false);
                messageToSend.Inject(_tracer, scope.Span.Context, _headers.StandardHeaders);
                try
                {
                    var outputMessage = await _handler.SendAsync(messageToSend, data);

                    if (outputMessage.HasError)
                    {
                        Tags.Error.Set(scope.Span, true);
                        if (outputMessage.SendingException != null)
                        {
                            scope.Span.Log(outputMessage.SendingException.ToString());
                        }
                    }
                    scope.Span.AddMessageIdTag(outputMessage.SentMessage.MessageId);
                    return(outputMessage);
                }
                catch (Exception e)
                {
                    Tags.Error.Set(scope.Span, true);
                    scope.Span.Log(e.ToString());
                    throw;
                }
            }
        }
 /// <summary>
 /// Sends a new message to an existing queue
 /// </summary>
 /// <param name="messageToSend">The message to send.</param>
 /// <param name="data">The additional data.</param>
 /// <returns></returns>
 public async Task<IQueueOutputMessage> SendAsync(IMessage messageToSend, IAdditionalMessageData data)
 {
     using (_sendAsyncTimer.NewContext())
     {
         var result = await _handler.SendAsync(messageToSend, data).ConfigureAwait(false);
         if (!result.HasError)
         {
             _sendMeter.Mark("SendMessageAsync", 1);
         }
         else
         {
             _sendErrorMeter.Mark("SendMessageAsync", 1);
         }
         return result;
     }
 }
예제 #4
0
        /// <summary>
        /// Sends the specified message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="data">The data.</param>
        /// <returns></returns>
        private async Task <IQueueOutputMessage> InternalSendAsync(T message, IAdditionalMessageData data)
        {
            Guard.NotNull(() => message, message);
            Guard.NotNull(() => data, data);

            if (!Configuration.IsReadOnly)
            {
                Configuration.SetReadOnly();
            }

            var additionalHeaders = _generateMessageHeaders.HeaderSetup(data);
            var messageToSend     = _messageFactory.Create(message, additionalHeaders);

            _addStandardMessageHeaders.AddHeaders(messageToSend, data);

            //send the message to the transport
            return(await _sendMessages.SendAsync(messageToSend, data).ConfigureAwait(false));
        }
        /// <summary>
        /// Sends a new message to an existing queue
        /// </summary>
        /// <param name="messageToSend">The message to send.</param>
        /// <param name="data">The additional data.</param>
        /// <returns></returns>
        public async Task <IQueueOutputMessage> SendAsync(IMessage messageToSend, IAdditionalMessageData data)
        {
            IQueueOutputMessage result = null;

            if (_policyAsync == null)
            {
                _policies.Registry.TryGet(_policies.Definition.SendMessageAsync, out _policyAsync);
            }

            if (_policyAsync != null)
            {
                await _policyAsync.ExecuteAsync(async() => result = await _handler.SendAsync(messageToSend, data).ConfigureAwait(false)).ConfigureAwait(false);
            }
            else //no policy found
            {
                result = await _handler.SendAsync(messageToSend, data).ConfigureAwait(false);
            }

            return(result);
        }
예제 #6
0
        /// <summary>
        /// Sends the specified message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="responseId">The response identifier.</param>
        /// <param name="inputData">The additional message data.</param>
        /// <returns></returns>
        public async Task <IQueueOutputMessage> SendAsync(T message, IResponseId responseId, IAdditionalMessageData inputData)
        {
            ThrowIfDisposed();

            Guard.NotNull(() => message, message);
            Guard.NotNull(() => responseId, responseId);

            var data = SetupForSend(message, responseId, inputData);

            //send the message to the transport
            return(await _sendMessages.SendAsync(data.Item1, data.Item2).ConfigureAwait(false));
        }
예제 #7
0
        public async Task Invoke(OutgoingTransportContext context, Func <Task> next)
        {
            var sendOptions = context.Options as SendOptions;

            if (sendOptions != null)
            {
                await sender.SendAsync(context.OutgoingTransportMessage, sendOptions)
                .ConfigureAwait(false);
            }

            var publishOptions = context.Options as PublishOptions;

            if (publishOptions != null)
            {
                await publisher.PublishAsync(context.OutgoingTransportMessage, publishOptions)
                .ConfigureAwait(false);
            }

            await next()
            .ConfigureAwait(false);
        }
예제 #8
0
 public async Task SuccessAsync(Replicatable replicatable, TimeSpan replicatedIn = default, CancellationToken cancellationToken = default)
 {
     await _messageSender.SendAsync(replicatable, SuccessQueueName, cancellationToken);
 }