Skip to content

[Feature] Does Outbox supports multiple connections? #2104

Open
@IlSocio

Description

@IlSocio

Hello,
I'm trying to use the Outbox implementation of Brighter, but it is not clear to use the Outbox when we have multiple SQL connections.

eg.

        [HttpGet]
        [Route("greeting")]
        public async Task<HttpResponseMessage> TestPubCtx1Async(CancellationToken cancellationToken)
        {
            using (var trx1 = _greetingsCtx.Database.BeginTransaction())
            {
                var entity = new GreetingEntity() { GreetingText = "asdasd1" };
                _greetingsCtx.Greetings.Add(entity);
                _greetingsCtx.SaveChanges();

                var integrEvent = new GreetingChangedEvent("Hello from the web1");
                await _outbox.DepositPostAsync(integrEvent);
                trx1.Commit();
            }
            return new HttpResponseMessage(System.Net.HttpStatusCode.NoContent);
        }

        [HttpGet]
        [Route("another")]
        public async Task<HttpResponseMessage> TestCtx2Async(CancellationToken cancellationToken)
        {
            using (var trx2 = _anotherCtx.Database.BeginTransaction())
            {
                var entity = new TestEntity() { Text = "asdasd2" };
                _anotherCtx.SomeEntities.Add(entity);
                _anotherCtx.SaveChanges();

                var integrEvent = new TestChangedEvent("Hello from the web2");
                await _outbox.DepositPostAsync(integrEvent);
                trx2.Commit();
            }
            return new HttpResponseMessage(System.Net.HttpStatusCode.NoContent);
        }

In the IOC I'm registering the ConnectionProvider using
.UseMsSqlTransactionConnectionProvider()
Which will point to only 1 of the 2 possible Contexts.

Ideally, there exists this overload, which would allow me to explicitly provide the transaction, but, for some reason, it is marked as "private"

private Guid DepositPost<T>(T request, IAmABoxTransactionConnectionProvider connectionProvider) where T : class, IRequest

Would you accept a pull-request to make it available as Public, so that I use the Outbox on multiple connections?
Or there exists other way to archive the same result?

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions