product-microgateway
product-microgateway copied to clipboard
[Websockets] APIs with topics not working properly
Description
If we deploy a websocket API with a couple of topics and try to invoke them using the topics, gateway doesn't response properly (either hangs or gives a 400 response)
Steps to Reproduce
- Create a websocket API with context: postman, version: 1.0.0, endpoint:
wss://ws.postman-echo.com/raw
as the endpoint URL and deploy in CC. - Try to invoke after subscribe/keygen:
wscat -c wss://localhost:9095/postman/1.0.0 -H "Authorization: Bearer $TOKEN" -n
- This can be invoked properly
- Now create another websocket API with context: postmantopics, version: 1.0.0, endpoint:
wss://ws.postman-echo.com
- Try to invoke after subscribe/keygen:
wscat -c wss://localhost:9095/postmantopics/1.0.0/raw -H "Authorization: Bearer $TOKEN" -n
- This ends up with a 400 response.
If we use a ballerina service as the endpoint and try the same scenario above, the CC hangs without giving a response in the 2nd case.
ws-server.bal
import ballerina/io;
import ballerina/websocket;
service /echo on new websocket:Listener(7070) {
resource function get .()
returns websocket:Service|websocket:Error {
return new WsService();
}
}
service class WsService {
*websocket:Service;
remote function onTextMessage(websocket:Caller caller,
string text) returns websocket:Error? {
io:println("\ntext message: " + text);
return caller->writeTextMessage("You said: " + text);
}
}
Running:
bal run ws-server.bal
Endpoint: ws://
Version
1.1.0
Environment Details (with versions)
No response
Relevant Log Output
No response
Related Issues
No response
Suggested Labels
No response
I checked the given scenario, after doing steps 4 and 5, got the path logs as below:
[2022-09-08T06:07:36.335Z] 'GET /postmantopics/1.0.0/raw / HTTP/1.1' 502 - 0 150 2170 - '-' '-' '88164b83-4090-4a66-bbe4-cf7ffde65002' 'ws.postman-echo.com' '3.225.70.24:443'
/
means we are not passing /raw
path to the actual backend.
Then I add mapping to the topic from /raw
to /raw
as described here:
[2022-09-08T06:32:59.689Z] 'GET /postmantopics/1.0.0/raw /raw HTTP/1.1' 101 DC 51 29 4621 - '-' '-' '1383ec06-30ea-4783-be78-acd4b07aaaab' 'ws.postman-echo.com' '3.225.70.24:443'
and it worked.
when checked this in a apim pack, it had the same behaviour
Closing the issue as the functionality works properly.