public async Task <PubMessage> Publish(string message) { var pubMessage = new PubMessage() { Message = message }; using (var sqlConnection = new SqlConnection(_cfg["ConnectionString"])) { sqlConnection.Open(); using (var tran = sqlConnection.BeginTransaction()) { // your business code await _publisher.PublishAsync("CapDemo.Publish", pubMessage, sqlConnection, "CapDemo.Response", tran); tran.Commit(); } } var tcs = new TaskCompletionSource <PubMessage>(); _tcsDic.TryAdd(pubMessage.Id, tcs); return(await tcs.Task); }
public async Task Respoonse(PubMessage pubMsg) { await Console.Out.WriteLineAsync(pubMsg.Message); if (_tcsDic.Remove(pubMsg.Id, out var tcs)) { tcs.SetResult(pubMsg); } }