Refactor `AddToInboxAsync` method.

pull/16333/head
maliming 2 years ago
parent f3589878fa
commit 13d1289452
No known key found for this signature in database
GPG Key ID: A646B9CB645ECEA4

@ -21,6 +21,7 @@ public class AbpAspNetCoreMvcDaprEventsController : AbpController
var daprSerializer = HttpContext.RequestServices.GetRequiredService<IDaprSerializer>();
var body = (await JsonDocument.ParseAsync(HttpContext.Request.Body));
var id = body.RootElement.GetProperty("id").GetString();
var pubSubName = body.RootElement.GetProperty("pubsubname").GetString();
var topic = body.RootElement.GetProperty("topic").GetString();
var data = body.RootElement.GetProperty("data").GetRawText();
@ -32,7 +33,7 @@ public class AbpAspNetCoreMvcDaprEventsController : AbpController
var distributedEventBus = HttpContext.RequestServices.GetRequiredService<DaprDistributedEventBus>();
var eventData = daprSerializer.Deserialize(data, distributedEventBus.GetEventType(topic));
await distributedEventBus.DaprTriggerHandlersDirectAsync(distributedEventBus.GetEventType(topic), eventData);
await distributedEventBus.TriggerHandlersAsync(distributedEventBus.GetEventType(topic), eventData);
return Ok();
}
}

@ -84,10 +84,9 @@ public class AzureDistributedEventBus : DistributedEventBusBase, ISingletonDepen
return;
}
var eventBytes = message.Body.ToArray();
var eventData = _serializer.Deserialize(eventBytes, eventType);
var eventData = _serializer.Deserialize(message.Body.ToArray(), eventType);
if (await AddToInboxAsync(message.MessageId, eventName, eventType, eventBytes, eventData))
if (await AddToInboxAsync(message.MessageId, eventName, eventType, eventData))
{
return;
}

@ -169,13 +169,12 @@ public class DaprDistributedEventBus : DistributedEventBusBase, ISingletonDepend
}
}
public virtual async Task DaprTriggerHandlersDirectAsync(Type eventType, object eventData)
public virtual async Task TriggerHandlersAsync(string messageId, Type eventType, object eventData)
{
// TODO: Implement inbox
// if (await AddToInboxAsync(message.MessageId, EventNameAttribute.GetNameOrDefault(eventType), eventType, message.Body.ToArray()))
// {
// return;
// }
if (await AddToInboxAsync(messageId, EventNameAttribute.GetNameOrDefault(eventType), eventType, eventData))
{
return;
}
await TriggerHandlersDirectAsync(eventType, eventData);
}

@ -83,10 +83,9 @@ public class KafkaDistributedEventBus : DistributedEventBusBase, ISingletonDepen
}
var messageId = message.GetMessageId();
var eventBytes = message.Value;
var eventData = Serializer.Deserialize(message.Value, eventType);
if (await AddToInboxAsync(messageId, eventName, eventType, eventBytes, eventData))
if (await AddToInboxAsync(messageId, eventName, eventType, eventData))
{
return;
}

@ -101,10 +101,9 @@ public class RabbitMqDistributedEventBus : DistributedEventBusBase, ISingletonDe
return;
}
var eventBytes = ea.Body.ToArray();
var eventData = Serializer.Deserialize(eventBytes, eventType);
var eventData = Serializer.Deserialize(ea.Body.ToArray(), eventType);
if (await AddToInboxAsync(ea.BasicProperties.MessageId, eventName, eventType, eventBytes, eventData))
if (await AddToInboxAsync(ea.BasicProperties.MessageId, eventName, eventType, eventData))
{
return;
}

@ -145,7 +145,7 @@ public class RebusDistributedEventBus : DistributedEventBusBase, ISingletonDepen
var messageId = MessageContext.Current.TransportMessage.GetMessageId();
var eventName = EventNameAttribute.GetNameOrDefault(eventType);
if (await AddToInboxAsync(messageId, eventName, eventType, MessageContext.Current.TransportMessage.Body, eventData))
if (await AddToInboxAsync(messageId, eventName, eventType, eventData))
{
return;
}

@ -147,7 +147,6 @@ public abstract class DistributedEventBusBase : EventBusBase, IDistributedEventB
string messageId,
string eventName,
Type eventType,
byte[] eventBytes,
object eventData)
{
if (AbpDistributedEventBusOptions.Inboxes.Count <= 0)
@ -184,7 +183,7 @@ public abstract class DistributedEventBusBase : EventBusBase, IDistributedEventB
GuidGenerator.Create(),
messageId,
eventName,
eventBytes,
Serialize(eventData),
Clock.Now
)
);

Loading…
Cancel
Save