NServiceBus:没有通用主机的自定义 ISubscriptionStorage 实现
当我使用通用主机以外的其他内容时,我无法使用自定义 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在启动总线之前配置自定义订阅存储。您可以通过在流畅的初始化中包含 .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.