BEagle1984 / silverback

Silverback is a simple but feature-rich message bus for .NET core (it currently supports Kafka, RabbitMQ and MQTT).
https://silverback-messaging.net
MIT License
255 stars 37 forks source link

Is it possible to use outbox without overwriting SaveChanges #164

Open RomanOlegovich opened 2 years ago

RomanOlegovich commented 2 years ago

There are cron jobs, which are produce events. So I want to push event into outobox without using of DbContext (just to handle if queue doesn't work). Does Silverback help to me?)

RomanOlegovich commented 2 years ago
  1. SetUp outbox DbContext and ProduceToOutBoxTable
  2. Call publisher.Push()
  3. What I should do to send events to outbox?
BEagle1984 commented 2 years ago

Overriding the SaveChanges method is necessary only to automatically publish the domain events embedded in the models (aggregates) being saved. The outbox works independently of that and you just need to call a SaveChanges after you published the messages in order for them to be persisted.

await publisher.PublishAsync(message1);
await publisher.PublishAsync(message2);
await publisher.PublishAsync(message3);

await dbContext.SaveChangesAsync();

Using the outbox without the DbContext altogether is not possible. Currently, the only way to write to the database is through a DbContext. Again, this will change in Silverback 4. :wink: