How to queue method execution in asp.net core RRS feed

  • Question

  • I created messenger which uses AT commands and GSM modem to communicate but if many users send and receive messages at one time then AT commands will overlap and that will cause a lot of problems so I thought that my web app need sort of FIFO Queue for storing send/receive method execution. 
    Let's say I have HttpPost method which is executed by pressing SendMessage button on the web page this method saves the message to the database and executes SendSms and ReceiveSms method which doing stuff with AT commands as in the code below.

    [HttpPost(Name = "add-message")]
        public async Task<IActionResult> PostMessage([FromBody] MessengerViewModel messengerViewModel)
            AtSmsSender smsSender = new AtSmsSender();
            InnerAtSmsReceiver innerAtSmsReceiver = new InnerAtSmsReceiver(_receivedMessagesService);
            await smsSender.SendSms(messengerViewModel.PhoneNr, messengerViewModel.MessageBody);
            await innerAtSmsReceiver.ReceiveSms();
            //Logic of saving message using service

    How could I queue this Http method or methods inside it that they would be stacked and executed after some delay? 

    e.g. of functionality There is 20 users and they clicked send button almost in one time, so methods stacking in queue and first user message is sent and response received, after second third and so on. Users wont chat with other people but with device which response is pretty fast

    • Moved by CoolDadTx Monday, June 18, 2018 9:02 PM ASP.NET related
    Monday, June 18, 2018 6:14 PM

All replies

  • Change the architecture.

    Make the communication with the modem a Windows service. Use a queuing system like MSMQ or use a database for your own queuing. Either by tables or using SQL Server Broker queues. A further possibilty would be using SignalR

    But it depends a lot on the kind of service and what kind of response is needed for the client.

    Monday, June 18, 2018 6:23 PM
  • Please post questions related to web development in the ASP.NET forums.

    Michael Taylor http://www.michaeltaylorp3.net

    Monday, June 18, 2018 9:01 PM