Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added general global bookmark provider for all KafkaMessageReceivedOv… #3807

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using Elsa.Activities.Kafka.Activities.KafkaMessageReceived;
using Elsa.Activities.Kafka.Configuration;
using Elsa.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Elsa.Activities.Kafka.Bookmarks
{
/// <summary>
/// General Bookmark provider for all KafkaMessageReceived override activities.
/// </summary>
internal class OverrideKafkaBookmarkProvider : BookmarkProvider<Elsa.Activities.Kafka.Bookmarks.MessageReceivedBookmark, KafkaMessageReceived>
{

private readonly IKafkaCustomActivityProvider _customActivityProvider;
public OverrideKafkaBookmarkProvider(IKafkaCustomActivityProvider customActivityProvider)
{
_customActivityProvider = customActivityProvider;
}

public override bool SupportsActivity(BookmarkProviderContext<KafkaMessageReceived> context)
{
if (_customActivityProvider != null &&
_customActivityProvider.KafkaOverrideTriggers != null
&& _customActivityProvider.KafkaOverrideTriggers.Contains(context.ActivityExecutionContext.ActivityBlueprint.Type))
{
return true;
}
else
{
return base.SupportsActivity(context);
}
}

public override async ValueTask<IEnumerable<BookmarkResult>> GetBookmarksAsync(BookmarkProviderContext<KafkaMessageReceived> context, CancellationToken cancellationToken) =>
new[]
{
Result(
new Elsa.Activities.Kafka.Bookmarks.MessageReceivedBookmark(
topic: (await context.ReadActivityPropertyAsync(x => x.Topic, cancellationToken))!,
group: (await context.ReadActivityPropertyAsync(x => x.Group, cancellationToken))!,
connectionString: (await context.ReadActivityPropertyAsync(x => x.ConnectionString, cancellationToken))!,
headers: (await context.ReadActivityPropertyAsync(x => x.Headers, cancellationToken) ?? new Dictionary<string, string>())!,
autoOffsetReset: Enum.Parse<Confluent.Kafka.AutoOffsetReset>(await context.ReadActivityPropertyAsync(x => x.AutoOffsetReset, cancellationToken) ?? ((int)Confluent.Kafka.AutoOffsetReset.Earliest).ToString())!
))
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public static ElsaOptionsBuilder AddKafkaActivities(this ElsaOptionsBuilder opti
.AddHostedService<StartKafkaQueues>()
.AddSingleton<IKafkaTenantIdResolver, DefaultKafkaTenantIdResolver>()
.AddSingleton<IKafkaCustomActivityProvider, KafkaCustomActivityProvider>()
.AddBookmarkProvider<OverrideKafkaBookmarkProvider>()
.AddBookmarkProvider<QueueMessageReceivedBookmarkProvider>();

options.AddPubSubConsumer<UpdateWorkers, TriggerIndexingFinished>("WorkflowManagementEvents");
Expand Down