我正在使用带有NserviceBus 5.2的SendOnlyBus 我的设置代码就像
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" />
这会在发布消息时导致错误。
无法在此端点上发布 - 没有订阅存储 配置“。
如果我使用Memory Persistence,它可以正常工作但不能使用Hibernate DB-Subscription,无法找出遗漏或错误的内容。 感谢任何帮助?。
由于
答案 0 :(得分:2)
NServiceBus未配置订阅持久性,因为您已请求仅发送端点。
仅发送端点没有输入队列,这意味着它们无法接收和存储订阅。如果没有订阅者,尝试发布是没有意义的。
无论
Bus.Publish()
切换到Bus.Send()
或
return Bus.Create(busConfiguration)
而不是return Bus.CreateSendOnly(busConfiguration)
在 NServiceBus 5.2.0 和 NServiceBus.NHibernate 6.1.2 上发布NHibernate事件作为订阅持久性所需的唯一代码如下:
<强> Program.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 {}
}
<强>的app.config 强>
<?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>