Redis Learning Notes ~ Enabling Message Queuing to be more convenient than MSMQ

Source: Internet
Author: User
Tags msmq

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.