Skip to content
This repository was archived by the owner on May 12, 2026. It is now read-only.
This repository was archived by the owner on May 12, 2026. It is now read-only.

feat: add support for ScheduleTopic #2

Description

@leynier

Currently only EnqueueTopic is supported.

Proposal:

public interface ITopicPublisher
{
    ...

    void ScheduleTopic<T>(string topic, T data, TimeSpan delay);
    void ScheduleTopic<T>(string topic, T data, DateTimeOffset enqueueAt);
}

public class TopicPublisher : ITopicPublisher
{
    ...

    public void ScheduleTopic<T>(string topic, T data, TimeSpan delay)
    {
        BackgroundJob.Schedule(() => DispatchTopic(topic, data), delay);
    }

    public void ScheduleTopic<T>(string topic, T data, DateTimeOffset enqueueAt)
    {
        BackgroundJob.Schedule(() => DispatchTopic(topic, data), enqueueAt);
    }
}

Workaround:

Implement and use a new interface and implementation that inherit from "ITopicPublisher" and "TopicPublisher"

public interface ICustomTopicPublisher : ITopicPublisher
{
    void ScheduleTopic<T>(string topic, T data, TimeSpan delay);
    void ScheduleTopic<T>(string topic, T data, DateTimeOffset enqueueAt);
}

public class CustomTopicPublisher : TopicPublisher, ICustomTopicPublisher
{
    public CustomTopicPublisher(IServiceProvider serviceProvider) : base(serviceProvider)
    {
    }

    public void ScheduleTopic<T>(string topic, T data, TimeSpan delay)
    {
        BackgroundJob.Schedule(() => DispatchTopic(topic, data), delay);
    }

    public void ScheduleTopic<T>(string topic, T data, DateTimeOffset enqueueAt)
    {
        BackgroundJob.Schedule(() => DispatchTopic(topic, data), enqueueAt);
    }
}

public static class CustomTopicPublisherExtensions
{
    public static void AddCustomTopicServices(this IServiceCollection services)
    {
        services.AddTopicServices();
        services.AddScoped<ICustomTopicPublisher, CustomTopicPublisher>();
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions