Last post Jun 20, 2018 02:33 AM by Edward Z
Jun 19, 2018 06:23 AM|zeimodaniel|LINK
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);
//Logic of saving message using service (must be in queue to)
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
Jun 19, 2018 11:03 AM|mgebhard|LINK
Can you explain what overlap means? I'm guessing data and users are getting mixed.
If so, I doubt the issue is concurrency in Web API as Web API can handle 1000s of concurrent connections. Each user connection has a thread of execution. Most likely there is a bug in the hardware code or you've defined a static variable somewhere in the
Jun 20, 2018 02:33 AM|Edward Z|LINK
For queuing the request, I am afraid you could not.
For a workaround, I suggest you could create a Task table which will contains the information like “PhoneNr”, “MessageBody”, “Start Time”, and you could save the information to this table when users request this method, then you could try Asp.Net Core job
to process this based on your request.
#Background tasks with hosted services in ASP.NET Core