Timeout = new TimeSpan(0, 0, 90),
IsolationLevel = IsolationLevel.ReadCommitted
e.UseRetry(x => x.Interval(5, new TimeSpan(0, 0, 30)));
--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-discuss+unsub...@googlegroups.com.
To post to this group, send email to masstransit-discuss@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/masstransit-discuss/19ebdb73-f7b0-4633-9509-fc63fc335b24%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
public class BusConfigurator
{
public static void ConfigureBus(IKernel kernel)
{
string url = ConfigurationManager.AppSettings["rabbitUrl"];
string workflowsQueueName = ConfigurationManager.AppSettings["workflowsQueueName"];
var bus = Bus.Factory.CreateUsingRabbitMq(config =>
{
var host = config.Host(new Uri(url), hst =>
{
hst.Username("guest");
hst.Password("guest");
});
ConfigureConsumer<WorkflowMessageConsumer>(host, workflowsQueueName, config, kernel);
config.UseRetry(x => x.Interval(5, new TimeSpan(0, 0, 30)));
config.UseNLog();
});
var observer = new ReceiveObserver();
bus.ConnectReceiveObserver(observer);
var consumeObserver = new ConsumeObserver();
bus.ConnectConsumeObserver(consumeObserver);
bus.Start();
kernel.Bind<IBus>().ToConstant(bus);
}
private static void ConfigureConsumer<T>(IRabbitMqHost host, string queueName,
IRabbitMqBusFactoryConfigurator cfg, IKernel kernel) where T : class, IConsumer
{
cfg.ReceiveEndpoint(host, queueName, e =>
{
e.UseTransaction(x => GetTransactionConfigurator());
e.Consumer<T>(kernel);
});
}
private static ITransactionConfigurator GetTransactionConfigurator()
{
return new MyTransactionConfigurator
{
Timeout = new TimeSpan(0, 0, 90),
IsolationLevel = IsolationLevel.ReadCommitted
};
}
}
public class MyTransactionConfigurator : ITransactionConfigurator
{
public TimeSpan Timeout { get; set; }
public System.Transactions.IsolationLevel IsolationLevel { get; set; }
}
Is the transaction middleware configured after the retry middleware?
On Tue, Sep 26, 2017 at 12:30 PM, Adrian Wright <adrian...@gmail.com> wrote:
I am using the TransactionContext to enlist the MassTransit transaction into EntityFramework. However, I find that in a retry scenario, TransactionContext.Transaction throws an ObjectDisposedException. Is there a way to reset the transaction so that I get a new transaction when the retry is processed?Here are my transactionality settings:
Timeout = new TimeSpan(0, 0, 90),
IsolationLevel = IsolationLevel.ReadCommittedAnd the retry settings:
e.UseRetry(x => x.Interval(5, new TimeSpan(0, 0, 30)));Here's the error:Cannot access a disposed object.Object name: 'Transaction'.at System.Transactions.Transaction.get_IsolationLevel()at System.Data.SqlClient.SqlDelegatedTransaction..ctor(SqlInternalConnection connection, Transaction tx)at System.Data.SqlClient.SqlInternalConnection.EnlistNonNull(Transaction tx)at System.Data.SqlClient.SqlInternalConnection.Enlist(Transaction tx)at System.Data.SqlClient.SqlInternalConnection.EnlistTransaction(Transaction transaction)at System.Data.SqlClient.SqlConnection.EnlistTransaction(Transaction transaction)
--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-discuss+unsub...@googlegroups.com.
To post to this group, send email to masstrans...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-discuss+unsubscribe...@googlegroups.com.
To post to this group, send email to masstrans...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/masstransit-discuss/19ebdb73-f7b0-4633-9509-fc63fc335b24%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-discuss+unsub...@googlegroups.com.
To post to this group, send email to masstransit-discuss@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/masstransit-discuss/7714f4ac-9fbe-454e-bcb5-56e8e9c24232%40googlegroups.com.
public static void ConfigureBus(IKernel kernel)
{
string url = ConfigurationManager.AppSettings["rabbitUrl"];
string workflowsQueueName = ConfigurationManager.AppSettings["workflowsQueueName"];
var bus = Bus.Factory.CreateUsingRabbitMq(config =>
{
var host = config.Host(new Uri(url), hst =>
{
hst.Username("guest");
hst.Password("guest");
});
config.UseRetry(x => x.Interval(5, new TimeSpan(0, 0, 30)));
config.UseTransaction(x =>
{
x.Timeout = TimeSpan.FromSeconds(90);
x.IsolationLevel = IsolationLevel.ReadCommitted;
});
ConfigureConsumer<WorkflowMessageConsumer>(host, workflowsQueueName, config, kernel);
config.UseNLog();
});
var observer = new ReceiveObserver();
bus.ConnectReceiveObserver(observer);
var consumeObserver = new ConsumeObserver(kernel.Get<ISurveyService>());
bus.ConnectConsumeObserver(consumeObserver);
bus.Start();
kernel.Bind<IBus>().ToConstant(bus);
}
private static void ConfigureConsumer<T>(IRabbitMqHost host, string queueName,
IRabbitMqBusFactoryConfigurator cfg, IKernel kernel) where T : class, IConsumer
{
cfg.ReceiveEndpoint(host, queueName, e =>
{
e.Consumer<T>(kernel);
});
}
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-discuss+unsub...@googlegroups.com.
To post to this group, send email to masstrans...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/masstransit-discuss/19ebdb73-f7b0-4633-9509-fc63fc335b24%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-discuss+unsub...@googlegroups.com.
To post to this group, send email to masstrans...@googlegroups.com.
class Program
{
static void Main(string[] args)
{
var bus = Bus.Factory.CreateUsingRabbitMq(config =>
{
var host = config.Host(new Uri("rabbitmq://my-rabbit"), hst =>
{
hst.Username("guest");
hst.Password("guest");
});
config.UseRetry(x => x.Interval(5, new TimeSpan(0, 0, 30)));
config.UseTransaction(x =>
{
x.Timeout = TimeSpan.FromSeconds(90);
x.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
});
config.ReceiveEndpoint(host, "testRetry", e =>
{
e.Consumer<Consumer>();
});
});
bus.Start();
var sendToUri = new Uri("rabbitmq://my-rabbit/testRetry");
var endPoint = bus.GetSendEndpoint(sendToUri).Result;
endPoint.Send<Message>(new Message {Id = Guid.NewGuid()});
}
public class Consumer : IConsumer<Message>
{
public Task Consume(ConsumeContext<Message> context)
{
TransactionContext transactionContext;
context.TryGetPayload(out transactionContext);
// verify that I have a valid transaction. On the first retry, this line will throw an exception because the transaction has been disposed.
var isolationLevel = transactionContext.Transaction.IsolationLevel;
throw new Exception("throwing an exception to trigger a retry");
}
}
public class Message
{
public Guid Id { get; set; }
}
}
--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-discuss+unsub...@googlegroups.com.
To post to this group, send email to masstransit-discuss@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/masstransit-discuss/fbebf0a1-fd97-448d-a602-ef8c2d96b3af%40googlegroups.com.
To post to this group, send email to masstrans...@googlegroups.com.