/// <summary> /// Initiates the connection to the STOMP server. /// </summary> /// <param name="host"></param> /// <param name="login"></param> /// <param name="passcode"></param> /// <param name="headers"></param> /// <param name="cancellationToken"></param> /// <returns></returns> internal async Task ConnectAsync(string host, string login, string passcode, IEnumerable <KeyValuePair <string, string> > headers, CancellationToken cancellationToken) { headers ??= Enumerable.Empty <KeyValuePair <string, string> >(); if (GetStompVersionHeader() is string acceptVersion) { headers = headers.Prepend(new KeyValuePair <string, string>("accept-version", acceptVersion)); } if (host != null) { headers = headers.Prepend(new KeyValuePair <string, string>("host", host)); } logger.LogInformation("Initating STOMP connection: Host={Host}", host); var result = await SendFrameAndWaitAsync(StompCommand.Connect, headers, null, frame => frame.Command == StompCommand.Connected || frame.Command == StompCommand.Error, cancellationToken); if (result.Command == StompCommand.Error) { throw new StompException($"ERROR waiting for CONNECTED response: {Encoding.UTF8.GetString(result.Body.Span)}"); } if (result.Command != StompCommand.Connected) { throw new StompException("Did not receive CONNECTED response."); } version = result.GetHeaderValue("version") is string _version?ParseStompVersionHeader(_version) : StompVersion.Stomp_1_0; session = result.GetHeaderValue("session"); logger.LogInformation("STOMP connection established: Version={Version} Session={Session}", StompVersionHeaderToString(version), session); }
/// <summary> /// Converts a <see cref="StompVersion"/> into a string. /// </summary> /// <param name="version"></param> /// <returns></returns> string StompVersionHeaderToString(StompVersion version) => version switch {