1

我将 SendOnlyBus 与 NserviceBus 5.2 一起使用,我的设置代码就像

busConfiguration.UsePersistence<NHibernatePersistence,StorageType.Subscriptions>();
                busConfiguration.AssembliesToScan(AssembliesToScan);
                busConfiguration.UseTransport<MsmqTransport>();
                busConfiguration.PurgeOnStartup(false);
                busConfiguration.UseSerialization<XmlSerializer>();
                return Bus.CreateSendOnly(busConfiguration);

和 web.config

    <section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig,       NServiceBus.Core" />
<section name="MsmqTransportConfig" type="NServiceBus.Config.TransportConfig,  NServiceBus.Core" />

<MsmqTransportConfig InputQueue="XXX" ErrorQueue="XXX" NumberOfWorkerThreads="X" MaxRetries="X" />
<UnicastBusConfig>
    <MessageEndpointMappings>
      <add Messages="X" Endpoint="X" />
      </MessageEndpointMappings>
</UnicastBusConfig>

<add name="NServiceBus/Persistence" connectionString="Data Source=XXX;database=XXX;User ID=XX;Password=XXx;" />

<add key="NServiceBus/Persistence/NHibernate/dialect" value="NHibernate.Dialect.MsSql2005Dialect" />
    <add key="NServiceBus/Persistence/NHibernate/connection.provider" value="NHibernate.Connection.DriverConnectionProvider" />
    <add key="NServiceBus/Persistence/NHibernate/connection.driver_class" value="NHibernate.Driver.SqlClientDriver" />

这会导致发布消息时出错。

无法在此端点上发布 - 未配置订阅存储。”

如果我使用内存持久性,它可以正常工作,但不适用于 Hibernate DB-Subscription,无法找出丢失或错误的内容。感谢任何帮助?

谢谢

4

1 回答 1

2

解释

NServiceBus 未配置订阅持久性,因为您已请求仅发送端点。

仅发送端点没有输入队列,这意味着它们无法接收和存储订阅。如果您没有订阅者,尝试发布是没有意义的。

任何一个

  • 保留仅发送总线,但从使用切换Bus.Publish()Bus.Send()

或者

  • 通过调用return Bus.Create(busConfiguration)而不是使用完整的总线return Bus.CreateSendOnly(busConfiguration)


代码示例

在NServiceBus 5.2.0NServiceBus.NHibernate 6.1.2上使用 NHibernate 作为订阅持久性发布事件所需的唯一代码如下:

程序.cs

using System;
using NServiceBus;
using NServiceBus.Features;
using NServiceBus.Persistence;

class Program
{

    static void Main()
    {
        BusConfiguration busConfiguration = new BusConfiguration();
        busConfiguration.DisableFeature<TimeoutManager>();
        busConfiguration.UsePersistence<NHibernatePersistence, StorageType.Subscriptions>();

        using (IStartableBus bus = Bus.Create(busConfiguration))
        {
            bus.Start();
            bus.Publish(new SomeEvent());

            Console.WriteLine("Published an event");
            Console.ReadLine();
        }
    }

    class SomeEvent : IEvent {}
}

应用程序配置

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <connectionStrings>
    <add name="NServiceBus/Persistence" connectionString="Data Source=.;database=database;User ID=user;Password=password;"/>
  </connectionStrings>
  <appSettings>
    <add key="NServiceBus/Persistence/NHibernate/dialect" value="NHibernate.Dialect.MsSql2012Dialect" /> 
  </appSettings>
</configuration>
于 2015-05-21T14:03:50.760 回答