Browse Source

Rename IRawEventPublisher to ISupportsEventBoxes and refactor methods.

pull/10008/head
Halil İbrahim Kalkan 5 years ago
parent
commit
4af63febff
  1. 6
      framework/src/Volo.Abp.EventBus.Boxes/Volo/Abp/EventBus/Boxes/AbpDistributedEventBusExtensions.cs
  2. 4
      framework/src/Volo.Abp.EventBus.Boxes/Volo/Abp/EventBus/Boxes/InboxProcessor.cs
  3. 8
      framework/src/Volo.Abp.EventBus.Boxes/Volo/Abp/EventBus/Boxes/OutboxSender.cs
  4. 21
      framework/src/Volo.Abp.EventBus.Kafka/Volo/Abp/EventBus/Kafka/KafkaDistributedEventBus.cs
  5. 14
      framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/RabbitMqDistributedEventBus.cs
  6. 8
      framework/src/Volo.Abp.EventBus.Rebus/Volo/Abp/EventBus/Rebus/RebusDistributedEventBus.cs
  7. 12
      framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/DistributedEventBusBase.cs
  8. 18
      framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/IRawEventPublisher.cs
  9. 17
      framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/ISupportsEventBoxes.cs

6
framework/src/Volo.Abp.EventBus.Boxes/Volo/Abp/EventBus/Boxes/AbpDistributedEventBusExtensions.cs

@ -4,12 +4,12 @@ namespace Volo.Abp.EventBus.Boxes
{ {
public static class AbpDistributedEventBusExtensions public static class AbpDistributedEventBusExtensions
{ {
public static IRawEventPublisher AsRawEventPublisher(this IDistributedEventBus eventBus) public static ISupportsEventBoxes AsSupportsEventBoxes(this IDistributedEventBus eventBus)
{ {
var rawPublisher = eventBus as IRawEventPublisher; var rawPublisher = eventBus as ISupportsEventBoxes;
if (rawPublisher == null) if (rawPublisher == null)
{ {
throw new AbpException($"Given type ({eventBus.GetType().AssemblyQualifiedName}) should implement {nameof(IRawEventPublisher)}!"); throw new AbpException($"Given type ({eventBus.GetType().AssemblyQualifiedName}) should implement {nameof(ISupportsEventBoxes)}!");
} }
return rawPublisher; return rawPublisher;

4
framework/src/Volo.Abp.EventBus.Boxes/Volo/Abp/EventBus/Boxes/InboxProcessor.cs

@ -103,8 +103,8 @@ namespace Volo.Abp.EventBus.Boxes
using (var uow = UnitOfWorkManager.Begin(isTransactional: true, requiresNew: true)) using (var uow = UnitOfWorkManager.Begin(isTransactional: true, requiresNew: true))
{ {
await DistributedEventBus await DistributedEventBus
.AsRawEventPublisher() .AsSupportsEventBoxes()
.ProcessRawAsync(InboxConfig, waitingEvent.EventName, waitingEvent.EventData); .ProcessFromInboxAsync(waitingEvent, InboxConfig);
await Inbox.MarkAsProcessedAsync(waitingEvent.Id); await Inbox.MarkAsProcessedAsync(waitingEvent.Id);

8
framework/src/Volo.Abp.EventBus.Boxes/Volo/Abp/EventBus/Boxes/OutboxSender.cs

@ -82,11 +82,13 @@ namespace Volo.Abp.EventBus.Boxes
foreach (var waitingEvent in waitingEvents) foreach (var waitingEvent in waitingEvents)
{ {
await DistributedEventBus await DistributedEventBus
.AsRawEventPublisher() .AsSupportsEventBoxes()
.PublishRawAsync(waitingEvent.Id, waitingEvent.EventName, waitingEvent.EventData); .PublishFromOutboxAsync(
waitingEvent,
OutboxConfig
);
await Outbox.DeleteAsync(waitingEvent.Id); await Outbox.DeleteAsync(waitingEvent.Id);
Logger.LogInformation($"Sent the event to the message broker with id = {waitingEvent.Id:N}"); Logger.LogInformation($"Sent the event to the message broker with id = {waitingEvent.Id:N}");
} }
} }

21
framework/src/Volo.Abp.EventBus.Kafka/Volo/Abp/EventBus/Kafka/KafkaDistributedEventBus.cs

@ -201,32 +201,33 @@ namespace Volo.Abp.EventBus.Kafka
unitOfWork.AddOrReplaceDistributedEvent(eventRecord); unitOfWork.AddOrReplaceDistributedEvent(eventRecord);
} }
public override Task PublishRawAsync( public override Task PublishFromOutboxAsync(
Guid eventId, OutgoingEventInfo outgoingEvent,
string eventName, OutboxConfig outboxConfig)
byte[] eventData)
{ {
return PublishAsync( return PublishAsync(
AbpKafkaEventBusOptions.TopicName, AbpKafkaEventBusOptions.TopicName,
eventName, outgoingEvent.EventName,
eventData, outgoingEvent.EventData,
new Headers new Headers
{ {
{ "messageId", System.Text.Encoding.UTF8.GetBytes(eventId.ToString("N")) } { "messageId", System.Text.Encoding.UTF8.GetBytes(outgoingEvent.Id.ToString("N")) }
}, },
null null
); );
} }
public override async Task ProcessRawAsync(InboxConfig inboxConfig, string eventName, byte[] eventDataBytes) public override async Task ProcessFromInboxAsync(
IncomingEventInfo incomingEvent,
InboxConfig inboxConfig)
{ {
var eventType = EventTypes.GetOrDefault(eventName); var eventType = EventTypes.GetOrDefault(incomingEvent.EventName);
if (eventType == null) if (eventType == null)
{ {
return; return;
} }
var eventData = Serializer.Deserialize(eventDataBytes, eventType); var eventData = Serializer.Deserialize(incomingEvent.EventData, eventType);
var exceptions = new List<Exception>(); var exceptions = new List<Exception>();
await TriggerHandlersAsync(eventType, eventData, exceptions, inboxConfig); await TriggerHandlersAsync(eventType, eventData, exceptions, inboxConfig);
if (exceptions.Any()) if (exceptions.Any())

14
framework/src/Volo.Abp.EventBus.RabbitMQ/Volo/Abp/EventBus/RabbitMq/RabbitMqDistributedEventBus.cs

@ -212,22 +212,26 @@ namespace Volo.Abp.EventBus.RabbitMq
unitOfWork.AddOrReplaceDistributedEvent(eventRecord); unitOfWork.AddOrReplaceDistributedEvent(eventRecord);
} }
public override Task PublishRawAsync(Guid eventId, string eventName, byte[] eventData) public override Task PublishFromOutboxAsync(
OutgoingEventInfo outgoingEvent,
OutboxConfig outboxConfig)
{ {
return PublishAsync(eventName, eventData, null, eventId: eventId); return PublishAsync(outgoingEvent.EventName, outgoingEvent.EventData, null, eventId: outgoingEvent.Id);
} }
public override async Task ProcessRawAsync(InboxConfig inboxConfig, string eventName, byte[] eventDataBytes) public override async Task ProcessFromInboxAsync(
IncomingEventInfo incomingEvent,
InboxConfig inboxConfig)
{ {
//TODO: We have a duplication in logic and also with the kafka side! //TODO: We have a duplication in logic and also with the kafka side!
var eventType = EventTypes.GetOrDefault(eventName); var eventType = EventTypes.GetOrDefault(incomingEvent.EventName);
if (eventType == null) if (eventType == null)
{ {
return; return;
} }
var eventData = Serializer.Deserialize(eventDataBytes, eventType); var eventData = Serializer.Deserialize(incomingEvent.EventData, eventType);
var exceptions = new List<Exception>(); var exceptions = new List<Exception>();
await TriggerHandlersAsync(eventType, eventData, exceptions, inboxConfig); await TriggerHandlersAsync(eventType, eventData, exceptions, inboxConfig);
if (exceptions.Any()) if (exceptions.Any())

8
framework/src/Volo.Abp.EventBus.Rebus/Volo/Abp/EventBus/Rebus/RebusDistributedEventBus.cs

@ -188,13 +188,17 @@ namespace Volo.Abp.EventBus.Rebus
return false; return false;
} }
public override Task PublishRawAsync(Guid eventId, string eventName, byte[] eventData) public override Task PublishFromOutboxAsync(
OutgoingEventInfo outgoingEvent,
OutboxConfig outboxConfig)
{ {
/* TODO: IMPLEMENT! */ /* TODO: IMPLEMENT! */
throw new NotImplementedException(); throw new NotImplementedException();
} }
public override Task ProcessRawAsync(InboxConfig inboxConfig, string eventName, byte[] eventDataBytes) public override Task ProcessFromInboxAsync(
IncomingEventInfo incomingEvent,
InboxConfig inboxConfig)
{ {
/* TODO: IMPLEMENT! */ /* TODO: IMPLEMENT! */
throw new NotImplementedException(); throw new NotImplementedException();

12
framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/DistributedEventBusBase.cs

@ -10,7 +10,7 @@ using Volo.Abp.Uow;
namespace Volo.Abp.EventBus.Distributed namespace Volo.Abp.EventBus.Distributed
{ {
public abstract class DistributedEventBusBase : EventBusBase, IDistributedEventBus, IRawEventPublisher public abstract class DistributedEventBusBase : EventBusBase, IDistributedEventBus, ISupportsEventBoxes
{ {
protected IGuidGenerator GuidGenerator { get; } protected IGuidGenerator GuidGenerator { get; }
protected IClock Clock { get; } protected IClock Clock { get; }
@ -80,8 +80,14 @@ namespace Volo.Abp.EventBus.Distributed
await PublishToEventBusAsync(eventType, eventData); await PublishToEventBusAsync(eventType, eventData);
} }
public abstract Task PublishRawAsync(Guid eventId, string eventName, byte[] eventData); public abstract Task PublishFromOutboxAsync(
public abstract Task ProcessRawAsync(InboxConfig inboxConfig, string eventName, byte[] eventDataBytes); OutgoingEventInfo outgoingEvent,
OutboxConfig outboxConfig
);
public abstract Task ProcessFromInboxAsync(
IncomingEventInfo incomingEvent,
InboxConfig inboxConfig);
private async Task<bool> AddToOutboxAsync(Type eventType, object eventData) private async Task<bool> AddToOutboxAsync(Type eventType, object eventData)
{ {

18
framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/IRawEventPublisher.cs

@ -1,18 +0,0 @@
using System;
using System.Threading.Tasks;
namespace Volo.Abp.EventBus.Distributed
{
public interface IRawEventPublisher //TODO: Rename: ISupportsEventBoxes
{
Task PublishRawAsync(
Guid eventId,
string eventName,
byte[] eventData);
Task ProcessRawAsync(
InboxConfig inboxConfig,
string eventName,
byte[] eventDataBytes);
}
}

17
framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/ISupportsEventBoxes.cs

@ -0,0 +1,17 @@
using System.Threading.Tasks;
namespace Volo.Abp.EventBus.Distributed
{
public interface ISupportsEventBoxes
{
Task PublishFromOutboxAsync(
OutgoingEventInfo outgoingEvent,
OutboxConfig outboxConfig
);
Task ProcessFromInboxAsync(
IncomingEventInfo incomingEvent,
InboxConfig inboxConfig
);
}
}
Loading…
Cancel
Save