NServiceBus:没有通用主机的自定义 ISubscriptionStorage 实现

发布于 2024-10-03 05:12:41 字数 1593 浏览 0 评论 0原文

当我使用通用主机以外的其他内容时,我无法使用自定义 ISubscriptionStorage 实现。我不太确定为什么。我收到“无法在此端点上发布 - 尚未配置订阅存储。在‘NServiceBus.Configure.With()’之后添加‘MsmqSubscriptionStorage()’或‘DbSubscriptionStorage()’的异常。”

只是我不想使用这些选项,因为我想使用我的自定义选项。

这是我失败的地方:

public class Program
{
    static void Main()
    {
        var bus = Configure.With()
            .CustomConfigurationSource(new UserConfigurationSource()
                .Register(() => new MsmqTransportConfig())
                .Register(() => new UnicastBusConfig()))
            .DefaultBuilder()
            .XmlSerializer()
            .MsmqTransport()
            .IsTransactional(true)
            .UnicastBus()
            .CreateBus()
            .Start();

        Configure.Instance.Configurer.ConfigureComponent<StreamSubscriptionStorage>(ComponentCallModelEnum.Singleton);

        Console.WriteLine("This will publish IEvent and EventMessage alternately.");
        Console.WriteLine("Press 'Enter' to publish a message.To exit, Ctrl + C");

        bool publishIEvent = true;

        while (Console.ReadLine() != null)
        {
            var eventMessage = publishIEvent ? bus.CreateInstance<IEvent>() : new EventMessage();

            eventMessage.EventId = Guid.NewGuid();
            eventMessage.Time = DateTime.Now.Second > 30 ? (DateTime?)DateTime.Now : null;
            eventMessage.Duration = TimeSpan.FromSeconds(99999D);

            bus.Publish(eventMessage);

            Console.WriteLine("Published event.");

            publishIEvent = !publishIEvent;
        }
    }
}

I am unable to use my custom ISubscriptionStorage implementation when I use something other than the generic host. I'm not really sure why. I am getting an exception of "Cannot publish on this endpoint - no subscription storage has been configured. Add either 'MsmqSubscriptionStorage()' or 'DbSubscriptionStorage()' after 'NServiceBus.Configure.With()'."

Only I don't want to use these options because I want to use my custom option.

Here's what I have that's failing:

public class Program
{
    static void Main()
    {
        var bus = Configure.With()
            .CustomConfigurationSource(new UserConfigurationSource()
                .Register(() => new MsmqTransportConfig())
                .Register(() => new UnicastBusConfig()))
            .DefaultBuilder()
            .XmlSerializer()
            .MsmqTransport()
            .IsTransactional(true)
            .UnicastBus()
            .CreateBus()
            .Start();

        Configure.Instance.Configurer.ConfigureComponent<StreamSubscriptionStorage>(ComponentCallModelEnum.Singleton);

        Console.WriteLine("This will publish IEvent and EventMessage alternately.");
        Console.WriteLine("Press 'Enter' to publish a message.To exit, Ctrl + C");

        bool publishIEvent = true;

        while (Console.ReadLine() != null)
        {
            var eventMessage = publishIEvent ? bus.CreateInstance<IEvent>() : new EventMessage();

            eventMessage.EventId = Guid.NewGuid();
            eventMessage.Time = DateTime.Now.Second > 30 ? (DateTime?)DateTime.Now : null;
            eventMessage.Duration = TimeSpan.FromSeconds(99999D);

            bus.Publish(eventMessage);

            Console.WriteLine("Published event.");

            publishIEvent = !publishIEvent;
        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

很糊涂小朋友 2024-10-10 05:12:41

您需要在启动总线之前配置自定义订阅存储。您可以通过在流畅的初始化中包含 .RunCustomAction(此处为您的代码)来做到这一点。

You need to configure your custom subscription storage before starting the bus. You can do that by including .RunCustomAction( your code here ) in the fluent initialization.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文