im using Outbox Pattern with MassTransit
, when i publish message, it will remain in the OutboxMessages table in the data base and it wont deliverd to broker and here is the configuration:
packages:
<PackageReference Include="MassTransit" Version="8.0.15" />
<PackageReference Include="MassTransit.EntityFrameworkCore" Version="8.0.14" />
<PackageReference Include="MassTransit.RabbitMQ" Version="8.0.14" />
Program.cs
private static void AddMessagingConfiguration(IServiceCollection services, WebApplicationBuilder builder)
{
services.AddMassTransit(busConfigurator =>
{
busConfigurator.AddConsumer<GtsDocumentConsumer>();
busConfigurator.AddEntityFrameworkOutbox<CompanyGoodsDbContext>(outboxConfigurator =>
{
outboxConfigurator.UseSqlServer();
outboxConfigurator.UseBusOutbox();
outboxConfigurator.QueryMessageLimit = 10;
outboxConfigurator.QueryDelay = TimeSpan.FromSeconds(5);
outboxConfigurator.QueryTimeout = TimeSpan.FromSeconds(2);
});
busConfigurator.UsingRabbitMq((busContext, transportConfigurator) =>
{ transportConfigurator.Host(builder.Configuration["EventBusSettings:HostAddress"], hostConfiguration =>
{
hostConfiguration.Username(builder.Configuration["EventBusSettings:Username"]);
hostConfiguration.Password(builder.Configuration["EventBusSettings:Password"]);
});
transportConfigurator.AutoStart = true;
transportConfigurator.UseMessageRetry(r => r.Immediate(5));
transportConfigurator.UseScheduledRedelivery(r =>
r.Intervals(TimeSpan.FromSeconds(5), TimeSpan.FromMinutes(15), TimeSpan.FromMinutes(30)));
transportConfigurator.ConfigureEndpoints(busContext);
});
});
}
appSetting.json:
"EventBusSettings": {
"HostAddress": "sgms-broker",
"Username": "guest",
"Password": "guest"
}
Note that I dockerize
the app and its work perfectly fine, the term sgms-broker
is the host name that sign to my local host message broker
Controller:
private readonly IPublishEndpoint _publish;
public GtsDocumentsController(IPublishEndpoint publish)
{
_publish = publish;
}
[HttpPut("add-seen")]
public async Task<IActionResult> AddSeenHistory([FromBody] AddSeenHistoryCommand command)
{
await _publish.Publish(command);
await documentCommandFacade.AddSeenHistory(command);
return Ok();
}
outbox pattern work fine if my Message broker
is Down
but when its Up
its like delivery service
does not
deliver messages to the broker
i have no idea why it does not work.
after 5 hours i fixed the bug with updating the nuget packages