示例#1
0
 static Task <Table> AmendMessage(HttpContext context, PassthroughMessage message)
 {
     message.ExtraHeaders = new()
     {
         { "MessagePassthrough.Version", AssemblyVersion.Version },
         { "{}\":", "{}\":" }
     };
示例#2
0
    Task <Table> Callback(HttpContext httpContext, PassthroughMessage passthroughMessage)
    {
        //TODO: validate that the message type is allowed
        //TODO: validate that the destination is allowed
        var destinationTable = new Table(passthroughMessage.Destination);

        return(Task.FromResult(destinationTable));
    }
 static Task <Table> AmendMessage(HttpContext context, PassthroughMessage message)
 {
     message.ExtraHeaders = new Dictionary <string, string>
     {
         { "MessagePassthrough.Version", AssemblyVersion.Version },
         { "{}\":", "{}\":" }
     };
     return(Task.FromResult((Table)message.Destination !));
 }
    static string GetMessageName(PassthroughMessage message)
    {
        if (message.Namespace == null)
        {
            return(message.Type);
        }

        return($"{message.Namespace}.{message.Type}");
    }
示例#5
0
 public async Task <long> Send(PassthroughMessage message, Table destination, CancellationToken cancellation)
 {
     try
     {
         return(await InnerSend(message, destination, cancellation));
     }
     catch (Exception exception)
     {
         throw new SendFailureException(message, exception);
     }
 }
示例#6
0
    async Task <long> InnerSend(PassthroughMessage message, Table destination, CancellationToken cancellation)
    {
        await using var connection = await connectionFunc(cancellation);

        await using var transaction = connection.BeginTransaction();
        var rowVersion = await SendInsideTransaction(message, destination, cancellation, transaction);

        await transaction.CommitAsync(cancellation);

        return(rowVersion);
    }
    Task <Table> AmendMessage(HttpContext context, PassthroughMessage message)
    {
        message.ExtraHeaders = new Dictionary <string, string>
        {
            { "CustomHeader", "CustomHeaderValue" }
        };
        //TODO: validate that the destination allowed
        var destinationTable = new Table(message.Destination);

        return(Task.FromResult(destinationTable));
    }
示例#8
0
    Task <Table> Callback(HttpContext httpContext, PassthroughMessage message)
    {
        //TODO: validate that the message type is allowed
        //TODO: validate that the destination is allowed
        if (message.Destination == null)
        {
            var customDestination = new Table("Custom");
            return(Task.FromResult(customDestination));
        }

        var destination = new Table(message.Destination);

        return(Task.FromResult(destination));
    }
示例#9
0
        public UserInterfaceObserver()
        {
            _timer.AutoReset = true;
            _timer.Elapsed  += (sender, args) =>
            {
                if (_batch.messages.Any())
                {
                    Batch batch = null;
                    _lock.Write(() =>
                    {
                        batch  = _batch;
                        _batch = new Batch();
                    });

                    var passthrough = new PassthroughMessage(batch);
                    EventAggregator.SendMessage(passthrough);
                }
            };

            _timer.Enabled = true;
            _timer.Start();

            _readingTask = Task.Factory.StartNew(() =>
            {
                foreach (var message in _messages.GetConsumingEnumerable())
                {
                    if (message is IBatchedMessage)
                    {
                        // Just want this to have a lower priority
                        _lock.Read(() =>
                        {
                            _batch.Add(message);
                            return(string.Empty);
                        });
                    }
                    else
                    {
                        var passthrough = new PassthroughMessage(message);
                        EventAggregator.SendMessage(passthrough);

                        // TODO -- really, really don't like this
                        if (message is SpecExecutionCompleted)
                        {
                            EventAggregator.SendMessage(message);
                        }
                    }
                }
            });
        }
示例#10
0
    void LogSend(PassthroughMessage message)
    {
        if (!logger.IsEnabled(LogLevel.Information))
        {
            return;
        }

        logger.LogInformation("Send passthrough. Id:{id}, Destination:{destination}, Namespace:{namespace}, Type:{type}, Body:{body}, Attachments:{attachments},",
                              message.Id,
                              message.Destination,
                              message.Namespace,
                              message.Type,
                              message.Body,
                              message.Attachments.Select(x => x.FileName));
    }
示例#11
0
    async Task <long> SendInsideTransaction(PassthroughMessage message, Table destination, CancellationToken cancellation, DbTransaction transaction)
    {
        var headersString = headersBuilder.GetHeadersString(message);

        LogSend(message);
        var outgoingMessage = new OutgoingMessage(
            message.Id,
            headers: headersString,
            bodyBytes: Encoding.UTF8.GetBytes(message.Body));
        var queueManager     = new QueueManager(destination, transaction, dedupeTable);
        var attachmentExpiry = DateTime.UtcNow.AddDays(10);

        await SendAttachments(transaction, attachmentExpiry, cancellation, message);

        return(await queueManager.Send(outgoingMessage, cancellation));
    }
        public UserInterfaceObserver()
        {
            _readingTask = Task.Factory.StartNew(() =>
            {
                foreach (var message in _messages.GetConsumingEnumerable())
                {
                    var passthrough = new PassthroughMessage(message);
                    EventAggregator.SendMessage(passthrough);

                    if (message is UsedByUserInterface)
                    {
                        EventAggregator.SendMessage(message);
                    }
                }
            });
        }
        public UserInterfaceObserver()
        {
            _readingTask = Task.Factory.StartNew(() =>
            {
                foreach (var message in _messages.GetConsumingEnumerable())
                {
                    var passthrough = new PassthroughMessage(message);
                    EventAggregator.SendMessage(passthrough);

                    // TODO -- really, really don't like this
                    if (message is SpecExecutionCompleted)
                    {
                        EventAggregator.SendMessage(message);
                    }
                }
            });
        }
    public string GetHeadersString(PassthroughMessage message)
    {
        var messageType   = GetMessageName(message);
        var messageId     = message.Id.ToString();
        var correlationId = message.CorrelationId.ToString();
        var dictionary    = message.ExtraHeaders;

        dictionary.Add("NServiceBus.MessageId", messageId);
        dictionary.Add("NServiceBus.CorrelationId", correlationId);
        dictionary.Add("NServiceBus.EnclosedMessageTypes", messageType);
        dictionary.Add("NServiceBus.TimeSent", Headers.ToWireFormattedString(DateTime.UtcNow));
        dictionary.Add("NServiceBus.OriginatingMachine", originatingMachine);
        dictionary.Add("NServiceBus.OriginatingEndpoint", originatingEndpoint);
        if (message.ClientUrl != null)
        {
            dictionary.Add("MessagePassthrough.ClientUrl", message.ClientUrl);
        }

        return(Headers.Serialize(dictionary));
    }
示例#15
0
    void ProcessClaims(HttpContext context, PassthroughMessage passThroughMessage)
    {
        if (!appendClaims)
        {
            return;
        }

        var user = context.User;

        if (user?.Claims == null)
        {
            return;
        }

        if (!user.Claims.Any())
        {
            return;
        }

        ClaimsAppender.Append(user.Claims, passThroughMessage.ExtraHeaders, claimsHeaderPrefix);
    }
 static Task <Table> Callback(HttpContext httpContext, PassthroughMessage passthroughMessage)
 {
     return(null !);
 }
示例#17
0
    async Task SendAttachments(DbTransaction transaction, DateTime expiry, CancellationToken cancellation, PassthroughMessage message)
    {
        var connection = transaction.Connection;

        foreach (var file in message.Attachments)
        {
            await SendAttachment(transaction, message.Id.ToString(), expiry, cancellation, file, connection);
        }
    }
示例#18
0
 /// <summary>
 /// Initializes a new instance of <see cref="SendFailureException"/>
 /// </summary>
 public SendFailureException(PassthroughMessage passthroughMessage, Exception innerException) :
     base("OutgoingMessage failed to send.", innerException)
 {
     PassthroughMessage = passthroughMessage;
 }