rebus-org / Rebus.Oracle

:bus: Oracle transport for Rebus
https://mookid.dk/category/rebus
Other
5 stars 10 forks source link

Ambient transaction scope support missing #7

Closed thomasdc closed 5 years ago

thomasdc commented 5 years ago

Rebus.Oracle is missing support for enlisting in an ambient transaction scope via Rebus.TransactionScopes.

Minimal sample to reproduce the issue:

async Task Main()
{
  using (var activator = new BuiltinHandlerActivator())
  {
    activator.Handle<string>(async msg => Console.WriteLine($"Got a message: {msg}"));

    var oracleConnectionString = string.Format("Data Source={0};User Id={1};Password={2};Pooling=true;",
      "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=32769))(CONNECT_DATA=(SERVICE_NAME=ORCLCDB.LOCALDOMAIN)))",
      "rebus_oracle_poc",
      "rebus_oracle_poc");

    Configure.With(activator)
      .Transport(t =>
        t.UseOracle(oracleConnectionString, "transports", "rebus_oracle_poc"))
      .Routing(r => r.TypeBased().Map<string>("rebus_oracle_poc"))
      .Start();

    using (var scope = new TransactionScope(
      TransactionScopeOption.Required,
      new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted },
      TransactionScopeAsyncFlowOption.Enabled))
    {
      scope.EnlistRebus();

      await activator.Bus.Send("Dag allemaal!");

      scope.Complete();
    }

    await Task.Delay(1000);
  }
}

NuGet packages referenced:

I get the following error: Connection is already part of a local or a distributed transaction.

The problem lies in OracleConnectionHelper that always begins a new transaction causing it to be nested.

In Rebus.SqlServer support was added in commit 6c72dd32b182554dbee3f542fd0fb299d731b592. Can we do the same for Rebus.Oracle?

Ps: nowadays, you can easily spin up an Oracle database in a local Docker container via this image to test the sample above.

docker run -d -it -p 32769:1521 -p 32768:5500 --name oracle-loves-docker store/oracle/database-enterprise:12.2.0.1
thomasdc commented 5 years ago

@mookid8000, I see you have self-assigned this issue. Do you want me to create a pull request or will you fix it yourself?

mookid8000 commented 5 years ago

@thomasdc oh please send a PR 😁 I guess I self-assigned out of reflex

mookid8000 commented 5 years ago

Fixed by #8

It's out Rebus.Oracle 2.0.0-a2 and Rebus.Oracle.Devart 2.0.0-a2