I'm new to nServiceBus.
If the bus is configured with IsTransactional(true) and the handler has a lot of db interaction, the asp.net mvc application hangs up.
Here - http://adamfyles.blogspot.com/2010/08/getting-started-with-nservicebus-part-2_25.html - I found a tip: "IsTransactional(false) - we don't want to hang a web app up in transactions, so turn this off"
And it helped - the page is refreshing quickly. On the other side, if an exception happens, the msmq queue is lost.
Let me explain what the handler does - it iterates over some db rows, generates a report and updates the 'ReportId' key on that record:
foreach(var row in rows)
{
var reportId = GenerateReport(row);
row.ReportId = reportId;
}
db.Save();
As I said, I'm new to nServiceBus. Do I have to use Saga for this? I don't understand saga's yet. Or maybe I can do something like this:
foreach(var row in rows)
{
_bus.Send(new GenerateReportMessage{Id = row.Id});
}
And let the handler generate the report and update the row? How will I know that all records were updated? Will the web app hang up too with 'IsTransactional(true)' in this case? (I suspect that yes)
My questions:
What should I be aware of when I'm using 'IsTransactional(false)'?
What is best way to update a lot of records? Just update them in the loop? And I don't want the web app to hang.
EDIT
Btw, this code seems to not hang the web app, and it works with IsTransactional(true).
Is this a good approach?
using (new TransactionScope(TransactionScopeOption.Suppress))
{
foreach(var row in rows.Where(x => x.ReportId != null))
{
var reportId = GenerateReport(row);
row.ReportId = reportId;
}
db.Save();
}