I'm using MassTransit v.3.2.0.0. I'd like to complete a simple test project where my goal is send Commands and Events to a Azure Service Bus.
I'm using following code and I'm getting exception on the line:
busControl.GetSendEndpoint(serviceUri).Result;
I'm getting following exception:
"The argument Path is null or empty. Nome parametro: Path"
The events are send successfully, the following line complete with success
busControl.Publish
Thank you
static void Main(string[] args)
{
var serviceUri = ServiceBusEnvironment.CreateServiceUri("sb", "{MyNamespace}", "{MyQueueName}");
var busControl = Bus.Factory.CreateUsingAzureServiceBus(x =>
{
var host = x.Host(serviceUri, h =>
{
h.SharedAccessSignature(s =>
{
s.KeyName = "RootManageSharedAccessKey";
s.SharedAccessKey = "{MySharedAccessKey}";
s.TokenTimeToLive = TimeSpan.FromDays(1);
s.TokenScope = TokenScope.Namespace;
});
});
});
Console.WriteLine("Write Message. Type quit to exit.");
string text = "";
while (text != "quit")
{
Console.Write("Enter a message: ");
text = Console.ReadLine();
var eventMessage = new CustomerAddressUpdated() { UpdatedBy = text };
busControl.Publish<CustomerAddressUpdated>(eventMessage);
var message = new UpdateCustomerAddress() { CustomerId = text };
var sep = busControl.GetSendEndpoint(serviceUri).Result;
sep.Send<UpdateCustomerAddress>(message);
}
Console.WriteLine("Exiting. Press any key to close.");
Console.ReadKey();
}
When you're sending message via Mass Transit you should specify destination queue name. If you have Azure Service Bus endpoint something like: "sb://blahblah.servicebus.windows.net/", queue name should be specified as "sb://blahblah.servicebus.windows.net/target_queue_name".
If target queue does not exist, Mass Transit will create one and put the message to the new queue. Then, whenever consumer for the queue will be create, started and connected to service bus, the consumer will start working on the messages.
As mentioned above, the ServiceUri should be the path to your service bus namespace.
sb://your-namespace.servicebus.windows.net/
Then, to specify an endpoint to send:
sb://your-namespace.servicebus.windows.net/your-queue-name
You can also (and should) specify a namespace for your service, such as making your serviceUri:
sb://your-namespace.servicebus.windows.net/my-service
Then your queue name would be:
sb://your-namespace.servicebus.windows.net/your-service/your-queue-name
That is how it's recommend to be used.
Most helpful comment
As mentioned above, the ServiceUri should be the path to your service bus namespace.
Then, to specify an endpoint to send:
You can also (and should) specify a namespace for your service, such as making your serviceUri:
Then your queue name would be:
That is how it's recommend to be used.