Browse Source

Fix type header null exception

master
Savorboard 4 years ago
parent
commit
4b9f03d2a0
2 changed files with 12 additions and 4 deletions
  1. +1
    -1
      src/DotNetCore.CAP/Internal/ICapPublisher.Default.cs
  2. +11
    -3
      src/DotNetCore.CAP/Internal/IConsumerRegister.Default.cs

+ 1
- 1
src/DotNetCore.CAP/Internal/ICapPublisher.Default.cs View File

@@ -71,7 +71,7 @@ namespace DotNetCore.CAP.Internal
var messageId = SnowflakeId.Default().NextId().ToString();
headers.Add(Headers.MessageId, messageId);
headers.Add(Headers.MessageName, name);
headers.Add(Headers.Type, typeof(T).FullName);
headers.Add(Headers.Type, typeof(T).Name);
headers.Add(Headers.SentTime, DateTimeOffset.Now.ToString());
if (!headers.ContainsKey(Headers.CorrelationId))
{


+ 11
- 3
src/DotNetCore.CAP/Internal/IConsumerRegister.Default.cs View File

@@ -152,7 +152,7 @@ namespace DotNetCore.CAP.Internal
client.OnMessageReceived += async (sender, transportMessage) =>
{
_logger.MessageReceived(transportMessage.GetId(), transportMessage.GetName());
long? tracingTimestamp = null;
try
{
@@ -182,8 +182,16 @@ namespace DotNetCore.CAP.Internal
catch (Exception e)
{
transportMessage.Headers.Add(Headers.Exception, nameof(SerializationException) + "-->" + e.Message);
var dataUri = $"data:{transportMessage.Headers[Headers.Type]};base64," + Convert.ToBase64String(transportMessage.Body);
message = new Message(transportMessage.Headers, dataUri);
if (transportMessage.Headers.TryGetValue(Headers.Type, out var val))
{
var dataUri = $"data:{val};base64," + Convert.ToBase64String(transportMessage.Body);
message = new Message(transportMessage.Headers, dataUri);
}
else
{
var dataUri = "data:UnknownType;base64," + Convert.ToBase64String(transportMessage.Body);
message = new Message(transportMessage.Headers, dataUri);
}
}

if (message.HasException())


Loading…
Cancel
Save