What is a queue: the simple is that the data is stored in a space (can be memory, or can be a physical file), the first stored data objects, first taken out, which is the opposite of the stack, Message Queuing is also the case of high-concurrency data can be queued storage, and in the order of the queue processing, There are many tools to implement Message Queuing, such as Microsoft MSMQ, and some open source kv storage tools, which today mainly introduce the implementation of Message Queuing with Redis.
This is my REDIS project structure.
The Redis service has a console program that can support running under Windows and Linux.
I use the MVC application to do this example, write the information in one-way memory, and then take the message out of memory every 5 seconds to see the code
<summary>/// Message Object type/// </summary> public class Messagequene { static System.Timers.Timer Timer = new System.Timers.Timer; public static Chatmodels currentchatmodels = new Chatmodels (); Static Redis.Utils.RedisClient redisclient; Static Messagequene () { redisclient = new Redis.Utils.RedisClient (); Timer. AutoReset = true; Timer. Enabled = true; Timer. Elapsed + = new System.Timers.ElapsedEventHandler (timer_elapsed);//subscribe a event timer. Start (); } private static void Timer_elapsed (object sender, Elapsedeventargs e) { currentchatmodels = (chatmodels) Redisclient.leftpop ("Messagequene"); } }
Action displayed by the foreground
Public ActionResult Index () { viewdata["pop"] = Messagequene.currentchatmodels = = null? "Did you have a D-record?": MessageQuene.CurrentChatModels.Chat; viewdata["MSMQ"] = Redisclient.listrange ("messagequene") = = null ? New list<chatmodels> () : Redisclient.listrange ("Messagequene"). Cast<chatmodels> (). ToList ();
}
Action for form submission
event, if we use the message queue in the project, we can use the object of viewdata["Pop" directly, it is the queue element that is currently taken out, we can manipulate it data and so on.
Redis Learning Notes ~ Enabling Message Queuing to be more convenient than MSMQ