public async Task <SendResult <TResult> > Send <TResult>(string message) where TResult : class { try { var request = new RestRequest("/", Method.POST) { Body = new RequestBody("application/json", null !, message) }; var response = await _restClient.ExecuteAsync <TResult>(request); if (response.ResponseStatus == ResponseStatus.Completed) { return(SendResult.Ok(response.Data)); } return(SendResult.Failure <TResult>( $"Response status indicates failure (status '{response.ResponseStatus}', HTTP {response.StatusCode}, {response.StatusDescription}), message: {response.ErrorMessage}", response.ErrorException)); } catch (Exception ex) { return(SendResult.Failure <TResult>($"HTTP transport failed: {ex.Message}", ex)); } }
public async Task <SendResult <TResult> > Send <TResult>(string message) where TResult : class { try { var messageBytes = Encoding.UTF8.GetBytes(message); await _topicClient.SendAsync(new Message(messageBytes)); return(SendResult.Ok <TResult>(null)); } catch (Exception ex) { return(SendResult.Failure <TResult>($"MessageBus transport failed: {ex.Message}", ex)); } }