Browse Source

fix dead lock.

master
Savorboard 7 years ago
parent
commit
ea64bbcbd7
1 changed files with 6 additions and 6 deletions
  1. +6
    -6
      src/DotNetCore.CAP.Kafka/PublishQueueExecutor.cs

+ 6
- 6
src/DotNetCore.CAP.Kafka/PublishQueueExecutor.cs View File

@@ -21,7 +21,7 @@ namespace DotNetCore.CAP.Kafka
_kafkaOptions = options; _kafkaOptions = options;
} }


public override async Task<OperateResult> PublishAsync(string keyName, string content)
public override Task<OperateResult> PublishAsync(string keyName, string content)
{ {
try try
{ {
@@ -29,21 +29,21 @@ namespace DotNetCore.CAP.Kafka
var contentBytes = Encoding.UTF8.GetBytes(content); var contentBytes = Encoding.UTF8.GetBytes(content);
using (var producer = new Producer(config)) using (var producer = new Producer(config))
{ {
var message = await producer.ProduceAsync(keyName, null, contentBytes);
var message = producer.ProduceAsync(keyName, null, contentBytes).Result;


if (!message.Error.HasError) if (!message.Error.HasError)
{ {
_logger.LogDebug($"kafka topic message [{keyName}] has been published."); _logger.LogDebug($"kafka topic message [{keyName}] has been published.");


return OperateResult.Success;
return Task.FromResult(OperateResult.Success);
} }
else else
{ {
return OperateResult.Failed(new OperateError
return Task.FromResult(OperateResult.Failed(new OperateError
{ {
Code = message.Error.Code.ToString(), Code = message.Error.Code.ToString(),
Description = message.Error.Reason Description = message.Error.Reason
});
}));
} }
} }
} }
@@ -51,7 +51,7 @@ namespace DotNetCore.CAP.Kafka
{ {
_logger.LogError($"kafka topic message [{keyName}] has benn raised an exception of sending. the exception is: {ex.Message}"); _logger.LogError($"kafka topic message [{keyName}] has benn raised an exception of sending. the exception is: {ex.Message}");


return OperateResult.Failed(ex);
return Task.FromResult(OperateResult.Failed(ex));
} }
} }
} }

Loading…
Cancel
Save