C
C#11mo ago
Tim_

MassTransit: Consumers not getting called

I'm having trouble setting up masstransit. For some reason my consumers aren't getting called. The published events are saved to the database but they're not getting sent to rabbitmq for some reason.
services.AddMassTransit(opt =>
{
opt.SetKebabCaseEndpointNameFormatter();

opt.AddConsumer<UserRegisteredEventHandler>();

opt.AddEntityFrameworkOutbox<TContext>(o =>
{
o.QueryDelay = TimeSpan.FromSeconds(1);

o.UsePostgres();
o.UseBusOutbox();
});


opt.UsingRabbitMq((context, o) =>
{
o.Host("localhost", "/", h =>
{
h.Username("user123");
h.Password("pass123");
});

o.ConfigureEndpoints(context);
});
});
services.AddMassTransit(opt =>
{
opt.SetKebabCaseEndpointNameFormatter();

opt.AddConsumer<UserRegisteredEventHandler>();

opt.AddEntityFrameworkOutbox<TContext>(o =>
{
o.QueryDelay = TimeSpan.FromSeconds(1);

o.UsePostgres();
o.UseBusOutbox();
});


opt.UsingRabbitMq((context, o) =>
{
o.Host("localhost", "/", h =>
{
h.Username("user123");
h.Password("pass123");
});

o.ConfigureEndpoints(context);
});
});
public class UserRegisteredEventHandler : IConsumer<UserRegisteredEvent>
{
private readonly ILogger<UserRegisteredEvent> _logger;

public UserRegisteredEventHandler(ILogger<UserRegisteredEvent> logger)
{
_logger = logger;
}

public Task Consume(ConsumeContext<UserRegisteredEvent> context)
{
_logger.LogInformation(context.Message.ToString());
return Task.CompletedTask;
}
}
public class UserRegisteredEventHandler : IConsumer<UserRegisteredEvent>
{
private readonly ILogger<UserRegisteredEvent> _logger;

public UserRegisteredEventHandler(ILogger<UserRegisteredEvent> logger)
{
_logger = logger;
}

public Task Consume(ConsumeContext<UserRegisteredEvent> context)
{
_logger.LogInformation(context.Message.ToString());
return Task.CompletedTask;
}
}
Output when publishing an event
17:32 [Information] (Users) MassTransit
Configured endpoint "user-registered-event-handler", Consumer: "Shared.Infrastructure.Messaging.UserRegisteredEventHandler"
17:32 [Information] (Users) Users.Application.Commands.RegisterUser.Handler
At RegisterUser
17:32 [Information] (Users) MassTransit
Configured endpoint "user-registered-event-handler", Consumer: "Shared.Infrastructure.Messaging.UserRegisteredEventHandler"
17:32 [Information] (Users) Users.Application.Commands.RegisterUser.Handler
At RegisterUser
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server