How to do that efficiently in Golang?
A third party web service B. is working in batch with up to 100 Records.
Each Record is uniquely identified with RecordID.
- A websocket Golang App A. is listening at https://MyApp.com/ws's MyApp handler.
- Multiple parallel User requests with one Record are sent to MyApp.com. Each request should generate separate Go process MyAppRequest.
- Each record from 2. is uniquely identified with RecordID which is actually the UserID associated with each request.
- All Requests to MyApp collected within one second in 1. must be combined together and sent in a batch to B. in Go routine MyAppCallWebService.
- The batch response from B. in MyAppCallWebService must be split by RecordID and sent back to each requestor's MyAppRequest in 2.
=================================================================
A. Websocket Golang App:
=================================
Request from User:0000010:
Go process MyAppRequest associated with 0000010
=================================
{
"RequestRecords": [
{
"RecordID": "0000010",
"RequestData": "M4V2T2"
}
],
"TotalRecords": 1"
}
=================================
Response to User:0000010:
Go process MyAppRequest associated with 0000010
=================================
{
"ResponseRecords": [
{
"RecordID": "0000010",
"ResponseData": "processed M4V2T2"
}
],
"TotalRecords": 1"
}
=================================
Request from User:0000020:
Go process MyAppRequest associated with 0000020
=================================
{
"ResponseRecords": [
{
"RecordID": "0000020",
"RequestData": "M4V2T3"
}
],
"TotalRecords": 1"
}
=================================
Response to User:0000020:
Go process MyAppRequest associated with 0000020
=================================
{
"RequestRecords": [
{
"RecordID": "0000020",
"ResponseData": "processed M4V2T3"
}
],
"TotalRecords": 1"
}
B. Third party web service:
=================================
Request:
Go process MyAppCallWebService
=================================
{
"RequestRecords": [
{
"RecordID": "0000010",
"RequestData": "M4V2T2"
}, {
"RecordID": "0000020",
"RequestData": "M4V2T3"
}
],
"TotalRecords": "2"
}
The web service performs processing of up to 100 RequestRecords in batch
and returns results in batch of ResponseRecords.
=================================
Response:
=================================
{
"ResponseRecords": [
{
"RecordID": "0000010",
"ResponseData": "processed M4V2T2"
}, {
"RecordID": "0000020",
"ResponseData": "processed M4V2T3"
}
],
"TotalRecords": "2"
}
=================================