Beispiel #1
0
        /// <inheritdoc />
        public Task Send(string destinationAddress, TransportMessage message, ITransactionContext context)
        {
            var headers           = message.Headers;
            var now               = _rebusTime.Now;
            var priority          = headers.GetMessagePriority();
            var visible           = headers.GetInitialVisibilityDelay(now);
            var ttl               = headers.GetTtlSeconds();
            var serializedHeaders = HeaderSerializer.Serialize(headers);

            var command = context.GetSendCommand(_factory, _sendSql);

            // Lock is blocking, but we're not async anyway (Oracle provider is blocking).
            // As a bonus:
            // (1) Monitor is faster than SemaphoreSlim when there's no contention, which is usually the case;
            // (2) we don't need to allocate any extra object (command is private and not exposed to end-users).
            lock (command)
            {
                new SendCommand(command)
                {
                    Recipient  = destinationAddress,
                    Headers    = serializedHeaders,
                    Body       = message.Body,
                    Priority   = priority,
                    Now        = now,
                    Visible    = visible,
                    TtlSeconds = ttl,
                }
                .ExecuteNonQuery();
            }

            return(Task.CompletedTask);
        }