Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Testing auditing of SendLocal-sent messages
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