Headless CMS and Content Managment Hub
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

49 lines
1.6 KiB

// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using Squidex.Domain.Apps.Events;
using Squidex.Infrastructure.EventSourcing;
using Squidex.Messaging.Subscriptions;
namespace Squidex.Domain.Apps.Core.Subscriptions;
public sealed class SubscriptionPublisher : IEventConsumer
{
private readonly ISubscriptionService subscriptionService;
private readonly IEnumerable<ISubscriptionEventCreator> subscriptionEventCreators;
public string Name => "Subscriptions";
public StreamFilter EventsFilter { get; } = StreamFilter.Prefix("content-", "asset-");
public bool StartLatest => true;
public bool CanClear => false;
public SubscriptionPublisher(ISubscriptionService subscriptionService, IEnumerable<ISubscriptionEventCreator> subscriptionEventCreators)
{
this.subscriptionService = subscriptionService;
this.subscriptionEventCreators = subscriptionEventCreators;
}
public bool Handles(StoredEvent @event)
{
return subscriptionService.HasSubscriptions;
}
public Task On(Envelope<IEvent> @event)
{
if (@event.Payload is not AppEvent)
{
return Task.CompletedTask;
}
var wrapper = new EventMessageWrapper(@event.To<AppEvent>(), subscriptionEventCreators);
return subscriptionService.PublishAsync(wrapper);
}
}