My clients (python, java) are using simple WebSocket connection to send messages. I want to receive these messages inside my backend .NET 8 web api and process them further to send fine-tuned data to some distributed cache services.
Clients will only want to use pure websocket library available in their languages and NOT azure pub sub library.
From documentation, I only understood that I can use backend to only send the Access URL with token to clients, and Hubs are for dealing with events only (not messages).
I don't see how to receive messages in the backend service itself, but I guess I will need to use 'WebPubSubClient' in backend service itself to receive & process messages. which doesn't seem right as name indicates client.
Doubt:
Sharing relevant code for reference:
Sender:
WebPubSubClient pubSubClient = new(serverUri);
await pubSubClient.StartAsync();
//await pubSubClient.JoinGroupAsync(PubSubUtils.GroupName);
WebPubSubResult result = await pubSubClient.SendToGroupAsync(PubSubUtils.GroupName,
BinaryData.FromString("hello_from_dheeraj"),
WebPubSubDataType.Text);
Receiver:
await pubSubClient.StartAsync();
pubSubClient.GroupMessageReceived += eventArgs =>
{
Console.WriteLine($"Receive message: {eventArgs.Message.Data}");
return Task.CompletedTask;
};
Turns out there is specific json format that you need to adhere to while communicating using generic websockets. You cannot just use your json as it is. Below is the format that pubsub expects:
Even for protobuf to work with PubSub, There is also a specific format, but I am yet to figure it out.