Distributed message queue in the Nginx cluster, and the WCF in the nginx Cluster
Directory
1 General idea... 1
2. WCF distributed message queue in Nginx cluster... 1
3 MSMQ Message Queue... 2
4. Compile the WCF Service and client program... 2
5. Install MSMQ on the server .. 5
6. Deploy the WCF Service Program to one PC in the LAN... 6
7. Nginx cluster configuration and setup... 7
8 running results... 8
9 Conclusion... 11
1. General idea
L WCF distributed message queue in an Nginx Cluster
L MSMQ Message Queue
L compile the WCF Service and client programs
L install MSMQ on the server
L deploy the WCF Service Program to one PC in the LAN
L Nginx cluster configuration and Setup
L running result
L Summary
2. Distributed message queue in a Nginx Cluster
The processing capability of the distributed Message Queue MSMQ is greatly improved for WCF. Both the sender and receiver do not have to wait for the other party to return a successful message, but it is not suitable for real-time interaction between the Client and the Server. In terms of log processing, the results of the WCF distributed message queue are remarkable.
Of course, there are many Message Queue processing technologies, such as ActiveMQ, RabbitMQ, ZeroMQ, Kafka, MetaMQ, and RocketMQ. This article uses the Message Queue MSMQ that comes with Microsoft, and creates a log-type or mail-type WCF Service in combination with WCF in the Ningx cluster environment.
The architecture of the distributed message queue is as follows:
3. MSMQ Message Queue
Message Queue MSMQ provides non-connection communication support for higher programs because it supports offline communication. Message senders are carried out in offline mode. The offline communication mode changes the participants in message exchange into two completely independent applications. The only link between them is the message queue.
With the help of MSMQ communication methods, no matter how high the load occurs, as long as the arrival message accumulation does not exceed the set limit, MSMQ can be processed at its own pace. The high-load requests are postponed to low-load requests for processing, which solves the load problems well.
MSMQ has two main concepts.
One is Message: Message is the Message to be transmitted by both parties. It can be text, images, videos, etc. A message contains the sender and receiver IDs. Only the specified user can obtain the message.
Queue |
Description |
Public queue |
Replication across the MQ network may be accessed by all sites connected to the network |
Dedicated queue |
They are not released across the network. They are only available on the local computer where they reside. Dedicated queues can only be accessed by applications that know the full path name or tag of the queue. |
Log queue |
Contains the message receipt message that is confirmed in the given message queue" |
Response queue |
Contains the response message returned to the sending application when the target application receives the message, including the machine log queue, machine dead message queue, and machine transaction dead message queue. |
4. Compile the WCF Service and client programs
L WCF Service Program
Program. cs
Using Service; using System. serviceModel; namespace MessageDealingHosting {class Program {static void Main (string [] args) {using (ServiceHost host = new ServiceHost (typeof (PublicMessageQueue) {host. opened + = delegate {Console. writeLine (host. description. endpoints [0]. address. uri + "started. Press any key to terminate the service! ") ;}; Host. Open (); Console. Read ();}}}}
PublicMessageQueue. cs
Using System; using Service. interface; namespace Service {public partial class PublicMessageQueue: IPublicMessageQueue {public void SendMessage (string msg) {Console. writeLine (string. format ("message queue starts processing, input {0} succeeded", msg ));}}}
IPublicMessageQueue. cs
Using System; using Service. interface; namespace Service {public partial class PublicMessageQueue: IPublicMessageQueue {public void SendMessage (string msg) {Console. writeLine (string. format ("message queue starts processing, input {0} succeeded", msg ));}}}
Server configuration file:
<?xml version="1.0" encoding="utf-8" ?><configuration> <system.serviceModel> <behaviors> <serviceBehaviors> <behavior name="MessageQueueBehavior"> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="true" /> </behavior> </serviceBehaviors> </behaviors> <bindings> <netMsmqBinding> <binding name="MessageQueueBinding" exactlyOnce="false"> <security mode="None"></security> </binding> </netMsmqBinding> </bindings> <services> <service behaviorConfiguration="MessageQueueBehavior" name="Service.PublicMessageQueue"> <endpoint address="net.msmq://10.92.202.56/private/wcf_message" binding="netMsmqBinding" bindingConfiguration="MessageQueueBinding" contract="Service.Interface.IPublicMessageQueue" />
L client program
Program. cs
Using System; using System. collections. generic; using System. linq; using System. text; using MessageDealingClient. messageDealingService; using System. serviceModel; namespace MessageDealingClient {class Program {static void Main (string [] args) {using (ChannelFactory <IPublicMessageQueue> channelFactory = new ChannelFactory <IPublicMessageQueue> ("queue ")) {IPublicMessageQueue proxyServer = channelFactory. createChannel (); proxyServer. sendMessage ("hello world"); Console. writeLine ("the client is started first, and the message is sent to the Message Queue. If the WCF Service is started, hello world" is output);} Console. read ();}}}
Client configuration file:
<?xml version="1.0" encoding="utf-8" ?><configuration> <system.serviceModel> <bindings> <netMsmqBinding> <binding name="NetMsmqBinding_IPublicMessageQueue" exactlyOnce="false"> <security mode="None" /> </binding> </netMsmqBinding> </bindings> <client> <endpoint address="net.msmq://10.92.202.56/private/wcf_message" binding="netMsmqBinding" bindingConfiguration="NetMsmqBinding_IPublicMessageQueue" contract="MessageDealingService.IPublicMessageQueue" name="NetMsmqBinding_IPublicMessageQueue" /> </client> </system.serviceModel></configuration>
5. Install MSMQ on the server
L open control panel"
L click programs, and then click Enable or Disable Windows functions under programs and functions.
L expand "Microsoft Message Queue (MSMQ) server", expand "Microsoft Message Queue (MSMQ) server core", and select the check boxes corresponding to the "Message Queue" function to be installed below
N MSMQ Active Directory domain service integration (for computers that are added to the domain ).
N msmq http support.
6. Deploy the WCF Service Program to one PC in the LAN
Remote Deployment of a WCF server program to a PC
7. Configure and build an Nginx Cluster
Access the Server Load balancer cluster through the self-built domain name zhyongfeng.com: 80, access C: \ Windows \ System32 \ drivers \ etc \ hosts, and add the following "Custom Domain Name of the local IP Address ":
10.93.85.66 zhyongfeng.com
The Nginx matching principle is used to configure one PC deployed on WCF as follows:
worker_processes 1;events { worker_connections 1024;}http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; upstream zhyongfeng.com { server 10.92.202.56:5600; server 10.92.202.57:5700; server 10.92.202.58:5800; } server { listen 80; server_name zhyongfeng.com; location / { proxy_pass http://zhyongfeng.com; proxy_connect_timeout 10s; } location /wcf_message{ proxy_pass http://10.92.202.56:5600/wcf_message; proxy_connect_timeout 10s; } }}
Run CMD:
D:\DTLDownLoads\nginx-1.10.2>start nginxD:\DTLDownLoads\nginx-1.10.2>nginx -s reload
Access the WCF server: http://zhyongfeng.com/wcf_messageand run the result:
8 running results
Start the remote WCF server and the WCF client at the same time. The result is as follows:
Close the remote WCF server and start the WCF client. The result is as follows:
Restart the WCF server. The result is as follows:
9 Summary
Based on the WCF distributed message queue, it can be applied in scenarios where clients do not need server-side responses. Message Queue has a huge advantage in asynchronous processing. It is a type of selective inter-process communication that can maintain the stability of inter-process communication.
Source code download:
Http://download.csdn.net/download/ruby_matlab/10134565
PDF download:
Nginxcluster's WCF distribution type queue