Enterprise Library Logging Block and MSMQ Part 2 MSMQ Distributor Configuration
The Enterprise Library comes with a service called MSMQ Distributor which can be used to poll messages from a queue and write them to a database in a transactional and safe way.
This means that if the database is down, if the service polls a message and tries to write it to the DB, it will fail. the message will stay in the queue and wont be lost. When the database is back, the messages will be written in the database in the order they arrived in the queue without loosing any bit. Another advantage is when a lot of messages are sent at the same time, the queue will work as a buffer preventing the database engine to receive too many requests at the same time.
Install MSMQ service.
From Manage Server, install the Msmq Feature.
Install Enterprise Library on the DB server (or copy the dll and exe needed)
By default the binaries will be in the following Folder : C:\Program Files (x86)\Microsoft Enterprise Library 5.0\Bin
Create a new transactional private Queue.
Ensure the group Everyone has the following accesses:
- Peek Message
- Get Properties
- Get Permissions
- Send Message
Configure the MSMQ Service and Start it
Configure the Msmq Distributor Service
Edit the MsmqDistributor.exe.config file and get to the msmqDistributorSettings tag :
|
|
msmqpath : Name of the queue defined above.
queueTimerInterval : Interval in milliseconds between each poll on the queue.
serviceName : Name shown in the service manager page.
Add a Connection String Section
|
|
Add a Database Listener in the LoggingConfiguration section:
|
|
Then, install the Msmq Distributor Service as a service.
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe “C:\Program Files (x86)\Microsoft Enterprise Library 5.0\Bin\MsmqDistributor.exe”