I'm trying to get a pair of NSB endpoint (an event publisher and an event subscriber) running on top of Azure Service Bus.
I have created the service bus and the topic through the Azure portal, and my publisher is able to publish events to the topic just fine. Here's the code for that:
public static async Task Main()
{
var endpointConfiguration = new EndpointConfiguration(EndpointName);
endpointConfiguration.SendOnly();
var transport = endpointConfiguration.UseTransport<AzureServiceBusTransport>();
transport.ConnectionString(ServiceBusConnectionString);
transport.TopicName(TopicName);
var startableEndpoint = await Endpoint.Create(endpointConfiguration)
.ConfigureAwait(false);
var endpointInstance = await startableEndpoint.Start().ConfigureAwait(false);
var message = new MyMessage {Data = Guid.NewGuid().ToString()};
Console.WriteLine($"");
Console.WriteLine($"----------------");
Console.WriteLine($"Sending message ({message.Data})");
Console.WriteLine($"----------------");
Console.WriteLine($"");
await endpointInstance.Publish(message);
await endpointInstance.Stop().ConfigureAwait(false);
}
The message class lives in a shared assembly:
namespace NsbAsbPoc.Messages
{
public class MyMessage : IEvent
{
public string Data { get; set; }
}
}
I'm unable to get a subscriber set up for this message though. I've tried the following:
public static async Task Main()
{
var endpointConfiguration = new EndpointConfiguration(EndpointName);
endpointConfiguration
.UseTransport<AzureServiceBusTransport>()
.ConnectionString(ServiceBusConnectionString)
.TopicName(TopicName);
endpointConfiguration.UsePersistence<InMemoryPersistence>();
var startableEndpoint =
await Endpoint.Create(endpointConfiguration).ConfigureAwait(false);
var endpointInstance = await startableEndpoint.Start().ConfigureAwait(false);
Console.ReadLine();
await endpointInstance.Stop().ConfigureAwait(false);
}
public class Handler : IHandleMessages<MyMessage>
{
public Task Handle(MyMessage message, IMessageHandlerContext context)
{
Console.WriteLine($"");
Console.WriteLine($"----------------");
Console.WriteLine($"Received message ({message.Data})");
Console.WriteLine($"----------------");
Console.WriteLine($"");
return Task.CompletedTask;
}
}
But I'm getting the following error on startup:
ERROR NServiceBus.Features.AutoSubscribe AutoSubscribe was unable
to subscribe to event 'NsbAsbPoc.Messages.MyMessage': The messaging entity
'xxxx:Topic:rich-test-topic|rich-test-vs-receiver-nsb|NsbAsbPoc.Messages.MyMessage'
could not be found. TrackingId:150fa682-205a-4dc1-a2fb-af6ddf8c1b4f_B2, SystemTracker:NoSystemTracker, Timestamp:2019-07-23T14:25:16
Note that in the above message I've redacted the name of the bus instance. Note also that rich-test-topic
is the name of my topic and rich-test-vs-receiver-nsb
is the name of my receiving endpoint.
I'm completely stuck as to how to continue since this new version of the NServiceBus.Transport.AzureServiceBus library appears to have almost no documentation and almost no samples. I don't know what it's doing; am I supposed to manually configure the subscription? Should I be letting NSB create the topic itself? Is the endpoint name significant in any way?