Reputation: 404
I have a backend where a simple string object event is being published. The event publishing service (SimpleSend) do show up in the rabbitmq dashboard but not the receiving/handling (SimpleReceive) service's. Also the event is not being received by the handler.
The event being as below
public class TransTest : IEvent
{
public string TimeSlots { get; set; }
public TransTest(string timeSlots)
{
TimeSlots = timeSlots;
}
}
And the dependency injection on the startup (dotnet 5 was upgraded to 6) is as follows. (Mind you that I have tested this on a local rabbitmq and a hosted one)
services.AddSingleton<IMessageSession>(provider =>
{
var endpointConfiguration = new EndpointConfiguration("SimpleSender");
endpointConfiguration.UseSerialization<SystemJsonSerializer>();
endpointConfiguration.AutoSubscribe();
var transport = endpointConfiguration.UseTransport<RabbitMQTransport>();
//transport.ConnectionString("host=localhost");
transport.ConnectionString("host=rabbitmq;username=dev;password=dev");
transport.UseConventionalRoutingTopology(QueueType.Quorum);
//transport.UseDirectRoutingTopology(
// QueueType.Classic,
// exchangeNameConvention: () => "name_event_bus"
//);
transport.Routing().RouteToEndpoint(typeof(TransTest), "SimpleReceiver");
endpointConfiguration.EnableInstallers();
var endpointInstance = NServiceBus.Endpoint.Start(endpointConfiguration).GetAwaiter().GetResult();
return endpointInstance;
});
I publish the event through an API endpoint like below
[HttpGet("/Test")]
public async Task<ActionResult> GetTestTrans()
{
var sendOptions = new SendOptions();
sendOptions.SetDestination("SimpleReceiver");
Console.WriteLine("Sending message to calendar");
var saga = new TransTest("MESSAGE");
await _messageSession.Publish(saga);
return Ok();
}
The receiving/handling services DI is as below, implemented in the startup,
services.AddSingleton<IMessageSession>(provider =>
{
var endpointConfiguration = new EndpointConfiguration("SimpleReceiver");
endpointConfiguration.UseSerialization<SystemJsonSerializer>();
endpointConfiguration.AutoSubscribe();
var transport = endpointConfiguration.UseTransport<RabbitMQTransport>();
//transport.ConnectionString("host=localhost");
transport.ConnectionString("host=rabbitmq;username:dev;password:dev");
transport.UseConventionalRoutingTopology(QueueType.Quorum);
//transport.UseDirectRoutingTopology(
// QueueType.Classic,
// exchangeNameConvention: () => "name_event_bus"
// );
endpointConfiguration.EnableInstallers();
var endpointInstance = NServiceBus.Endpoint.Start(endpointConfiguration).GetAwaiter().GetResult();
return endpointInstance;
});
and the handler for this is as below.
public class SagaTimeSlotsHandler : IHandleMessages<TransTest>
{
static ILog log = LogManager.GetLogger<SagaTimeSlotsHandler>();
public async Task Handle(TransTest message, IMessageHandlerContext context)
{
Console.WriteLine("SAGA HANDLED");
Console.WriteLine(message.TimeSlots);
log.Info($"Hello from {nameof(SagaTimeSlotsHandler)}");
Task.Completed;
}
}
I have attached a screenshot of the rabbitmq dashboard below
Upvotes: 0
Views: 78
Reputation: 54819
I suspect that the Endpoint.Start
call in your receiver is never executed. It is inside of the factory method for IMessageSession
but nothing in that application ever resolves IMessageSession
and so the factory method is never run.
To add NServiceBus to a host and ensure that it is properly started, you should use the UseNServiceBus(..)
method found in the NServiceBus.Extensions.Hosting package.
If you are hosting an NServiceBus endpoint in a web application there are samples showing how to do that.
Upvotes: 2