Endpoint Specific Operations
You can also explicitly send any message to a named endpoint in the system. You might do this to programmatically distribute work in your system, or when you need to do more programmatic routing as to what downstream system should handle the outgoing message.
Regardless, that usage is shown below. Just note that you can give a name to any type of Wolverine endpoint:
cs
using var host = await Host.CreateDefaultBuilder()
.UseWolverine(opts =>
{
opts.PublishAllMessages().ToPort(5555)
.Named("One");
opts.PublishAllMessages().ToPort(5555)
.Named("Two");
}).StartAsync();
var bus = host.Services
.GetRequiredService<IMessageBus>();
// Explicitly send a message to a named endpoint
await bus.EndpointFor("One").SendAsync(new SomeMessage());
// Or invoke remotely
await bus.EndpointFor("One").InvokeAsync(new SomeMessage());
// Or request/reply
var answer = bus.EndpointFor("One")
.InvokeAsync<Answer>(new Question());
There's another option to reference a messaging endpoint by Uri
as shown below:
cs
// Or access operations on a specific endpoint using a Uri
await bus.EndpointFor(new Uri("rabbitmq://queue/rabbit-one"))
.InvokeAsync(new SomeMessage());