In my project I receive a transaction from the client then process it and return a status back to the client via WCF. As you know I have to somehow save the transaction for recovery purposes and persistence.
I am thinking of using MSMQ for that purpose. When the transaction starts I will "save" it on MSMQ (database save will occur in a batch for performance reasons).
Is MSMQ good for that? Do you know of better way to create persistence? What is the best way to "backup" the transaction and keep high performance?
When picking a technology I think it's helpful to consider not only can the technology meet your needs, but also whether it was designed to meet your needs. By this I mean that you should choose the best option rather than just the first option that seems good enough. You could probably solve this problem with logging or text files or various other means, but that doesn't mean you should.
My order of preference in this situation would be
If it isn't possible to save transactions to database for whatever reason then MSMQ can probably help you here. It should perform better than a opening a database connection & committing yet provides a 'good' persistence layer. The downside is that it's more code and another point of failure for your application (not that it will fail if written properly, but more code means more places for bugs).
You can throw your transactions into a queue very easily using something like this
private string queuePath = @".\Private$\myQueue";
MessageQueue queue = new MessageQueue(queuePath);
Message message = new Messge();
message.Id = "messageId";
message.Body = "my content";
queue.Send(message, transaction);
transaction.Complete();
queue.Close();
and then retrieve them later through querying properties: MSMQ querying for a specific message. There's a lot of other functionality out of the box but keep it simple.
Some relevent questions:
I think you are looking for SQL Server Service Broker. Everything that 10 years ago we did with MSMQ we now are doing with the Service broker. It works well.
A popular approach used by database and file systems is called Write-Ahead Logging. This is not however trivial to implement. You can find details here...
Wikipedia: Write-Ahead Logging
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With