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