Exemplo n.º 1
0
        /// <summary>
        /// Sends a new message to an existing queue
        /// </summary>
        /// <param name="messageToSend">The message to send.</param>
        /// <param name="data">The data.</param>
        /// <returns></returns>
        /// <exception cref="DotNetWorkQueueException">An error occurred while sending a message</exception>
        public async Task <IQueueOutputMessage> SendAsync(IMessage messageToSend, IAdditionalMessageData data)
        {
            try
            {
                var id = await _dataStorage.SendMessageAsync(messageToSend, data).ConfigureAwait(false);

                return(new QueueOutputMessage(_sentMessageFactory.Create(new MessageQueueId(id), data.CorrelationId)));
            }
            catch (Exception exception)
            {
                return(new QueueOutputMessage(_sentMessageFactory.Create(null, data.CorrelationId), exception));
            }
        }
Exemplo n.º 2
0
        /// <inheritdoc />
        public async Task <Guid> SendMessageAsync(IMessage messageToSend, IAdditionalMessageData data)
        {
            using (var scope = _tracer.StartActivity("SendMessage"))
            {
                scope?.AddCommonTags(data, _connectionInformation);
                if (scope?.Context != null)
                {
                    messageToSend.Inject(_tracer, scope.Context, _headers.StandardHeaders);
                }
                try
                {
                    var id = await _handler.SendMessageAsync(messageToSend, data).ConfigureAwait(false);

                    if (id == Guid.Empty)
                    {
                        scope?.SetStatus(Status.Error);
                    }
                    ;
                    scope?.AddMessageIdTag(id.ToString());
                    return(id);
                }
                catch (Exception e)
                {
                    scope?.SetStatus(Status.Error);;
                    scope?.RecordException(e);
                    throw;
                }
            }
        }