/// <summary> /// Subscribes to the channel on the destination path. /// </summary> /// <param name="destinationPath">The channel.</param> async Task SendSubscribeStompMsgAsync(string destinationPath, Address destinationAddress = null) { StompMessage subscribe = new StompMessage(StompMessage.ClientCommands.SUBSCRIBE); subscribe.SetSubscriptionId(SubscriptionCounter++); subscribe.SetDestination(destinationPath, destinationAddress); await SendAsync(subscribe); // The LoopReadStompMsgsAsync will process the answer from the server Debug.WriteLine("Subscription requested on path " + subscribe.GetDestination()); }
/// <summary> /// Loop to read Stomp messages from the websocket and call appropriate actions. /// </summary> private async Task LoopReadStompMsgsAsync() { while (ClientWs.State == WebSocketState.Open) // Infinite loop for as long as we are running with an open socket { var msg = await ReadSocketAsync(); StompMessage stompMsg = StompMessage.Deserialize(msg); switch (stompMsg.Command) { case StompMessage.ServerResponses.ERROR: this.OnErrorEventHandler?.Invoke(stompMsg.Body); break; case StompMessage.ServerResponses.MESSAGE: ProcessReceivedMessage(stompMsg.GetDestination(), stompMsg.Body); break; default: // throw exception? Debug.WriteLine("Received STOMP Message with an unsupported Command: " + stompMsg); break; } } }