Created
July 31, 2019 12:11
-
-
Save SzymonPobiega/b8360ec5410e545bcd34ccf066a39922 to your computer and use it in GitHub Desktop.
Testing auditing of SendLocal-sent messages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading.Tasks; | |
using NServiceBus; | |
namespace AuditSendLocalTest | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Start().GetAwaiter().GetResult(); | |
} | |
static async Task Start() | |
{ | |
var config = new EndpointConfiguration("AuditSendLocalTest"); | |
config.AuditProcessedMessagesTo("audit"); | |
config.SendFailedMessagesTo("error"); | |
config.EnableInstallers(); | |
var persistence = config.UsePersistence<InMemoryPersistence>(); | |
var transport = config.UseTransport<SqlServerTransport>(); | |
var routing = transport.Routing(); | |
routing.RouteToEndpoint(typeof(RoutedMessage), "AuditSendLocalTest"); | |
transport.ConnectionString("data source=(local); initial catalog=nservicebus; integrated security=true"); | |
var endpoint = await Endpoint.Start(config); | |
while (true) | |
{ | |
Console.WriteLine("Press <enter> to send messages."); | |
await endpoint.SendLocal(new LocalMessage()); | |
await endpoint.Send(new RoutedMessage()); | |
} | |
} | |
} | |
class LocalMessageHandler : IHandleMessages<LocalMessage> | |
{ | |
public Task Handle(LocalMessage message, IMessageHandlerContext context) | |
{ | |
Console.WriteLine("Local message processed."); | |
return Task.CompletedTask; | |
} | |
} | |
class RoutedMessageHandler : IHandleMessages<RoutedMessage> | |
{ | |
public Task Handle(RoutedMessage message, IMessageHandlerContext context) | |
{ | |
Console.WriteLine("Routed message processed."); | |
return Task.CompletedTask; | |
} | |
} | |
class LocalMessage : IMessage | |
{ | |
} | |
class RoutedMessage : IMessage | |
{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment