Create a Message Queue (MSMQ).
I. Overview
In Enterprise Library step by step We have said in the series, Logs and detection applicationsProgramBlock Mainly2Components:ClientAndDistributor.ClientCreates a message.DistributorWrite destination location. Client According to the distribution policy (Distribution strategies) Send messagesDistributor, InApplication BlockProvided2Distribution Policies:In ProcessAndMSMQ, The default value isIn ProcessPolicy. Log synchronization is performed onClientWhile asynchronous logs useMSMQTo achieve,ClientYou need to create a log message and send itMSMQMessage queue. The other process waits for the message to arrive and writes it to the appropriate log receiving pool.
The application block containsWindows Service: MSMQ distributor Service. After the service is installed, the Service detects message queues at specified intervals.
Let's take a look at the log and Monitoring Application Block Processing flowchart:
Ii. install and configureMSMQ distributor Service
1. OpenVisual StudioCommand line tool, switch to the directory (the default installation path of the Enterprise Library)C: \ Program Files \ Microsoft Enterprise Library \ binRun the following command:
Installutil / I msmqdistributor.exe
Note: You must install the service in this way. Otherwise, the installation will fail.
2During the installation process, a set service Login Dialog Box is displayed, requiring you to enter the user name and password. In this case, the user name and password must be entered in the form of a domain user.<. \ USERNAME>The format is also possible, as shown in:
3. Start the service. In the Service Manager, findEnterprise Library logging distributor ServiceStart this service manually.
4. Open in a text editorMsmqdistributor.exe. configFile, delete the following section:
< Configurationsections >
< Configurationsection Name = "Loggingconfiguration" Encrypt = "False" >
< Storageprovider Xsi: Type = "Xmlfilestorageproviderdata" Name = "XML file storage provider" Path = "Loggingconfiguration. config" />
< Datatransformer Xsi: Type = "Xmlserializertransformerdata" Name = "XML serializer transformer" >
< Includetypes />
</ Datatransformer >
</ Configurationsection >
5. UseConfiguration console,OpenMsmqdistributor.exe. configFile
SetMSMQ distributor ServiceAddDistributor settings, As shown in:
6. SetMsmqpathProperty MatchingClientQueue name, which can be modifiedMsmqpathBut the value must be consistent withClientThe configurations are consistent.
Iii. UseMSMQCreate asynchronous log
1. As we mentioned earlier,Client settingsDetermine the distribution policy,OneClientUse the same policy for all messages. Therefore, we cannot create two policies at the same time. We must delete them first.In ProcessBefore creatingMSMQ:
2. CreateMSMQAfter the distribution policy, note that the queue name must be consistent with what we mentioned in Section 2:
3.Enterprise Library step by stepThe same is written in the series.
For more information, see:
Enterprise Library step by stepSeries (7): logging and monitoring application blocks--Entry
Enterprise Library step by stepSeries (8): logging and monitoring application blocks--Advanced