我正在尝试使用NServiceBus从控制台进程(非常类似于启动NServiceBus.Host.exe的库中包含的PubSub示例)向我的WPF应用程序发送消息。
这就是我所做的。 在WPF App.xaml类中,我定义了
public static IBus Bus;
相同的类,在application_startup处理程序中:
Bus = Configure.With().DefaultBuilder().BinarySerializer()
.MsmqTransport().IsTransactional(true).PurgeOnStartup(false)
.UnicastBus().ImpersonateSender(false).LoadMessageHandlers()
.CreateBus()
.Start();
Bus.Subscribe<EventMessage>((message) =>
{
switch (message.EventType)
{
case EventType.CreateSingleStay:
break;
case EventType.MoveToStartUpState:
case EventType.MoveToOperativeState:
case EventType.MoveToOutOfOrderState:
break;
case EventType.InputSignalDetected:
break;
}
return true;
});
这是WPF应用程序的app.config:
<configSections>
<section name="MsmqTransportConfig" type="NServiceBus.Config.MsmqTransportConfig, NServiceBus.Core" />
<section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core" />
</configSections>
<MsmqTransportConfig InputQueue="PresentationInputQueue" ErrorQueue="PresentationErrorQueue" NumberOfWorkerThreads="5" MaxRetries="5" />
<UnicastBusConfig>
<MessageEndpointMappings>
<add Messages="PlusMatic.EventsTest" Endpoint="PlusMaticPublisherInputQueue" />
</MessageEndpointMappings>
</UnicastBusConfig>
然后,我的NServiceBus.Host发布者,非常简单的c#类库,它在调试NServiceBus.Host.exe可执行文件中启动:
namespace PlusMatic.EventsTest
{
class EndpointConfig : IConfigureThisEndpoint, AsA_Publisher { }
}
...
namespace PlusMatic.EventsTest
{
public class TestPlusMaticServerEndpoint : IWantToRunAtStartup
{
public IBus Bus { get; set; }
private Thread _loopConsole;
#region Implementation of IWantToRunAtStartup
public void Run()
{
string readLine = string.Empty;
bool publishIEvent = true;
while (readLine != "j")
{
readLine = Console.ReadLine();
var eventMessage = publishIEvent
? Bus.CreateInstance<IEvent>()
: new EventMessage();
...
Bus.Publish(eventMessage);
Console.WriteLine("Published event with Id {0}.", eventMessage.EventId);
publishIEvent = !publishIEvent;
}
}
public void Stop()
{
}
}
}
这是我的活动课
namespace PlusMatic.EventsTest
{
[Serializable]
public class EventMessage : IEvent
{
public Guid EventId { get; set; }
public DateTime? Time { get; set; }
public EventType EventType { get; set; }
public MoveToStateEvent NextApplicationState { get; set; }
public InputEvent InputSignal { get; set; }
public IProductCard<Card> Card { get; set; }
}
public interface IEvent : IMessage
{
Guid EventId { get; set; }
DateTime? Time { get; set; }
IProductCard<Card> Card { get; set; }
EventType EventType { get; set; }
MoveToStateEvent NextApplicationState { get; set; }
InputEvent InputSignal { get; set; }
}
}
发布商的App.config:
<configSections>
<section name="MsmqTransportConfig" type="NServiceBus.Config.MsmqTransportConfig, NServiceBus.Core" />
</configSections>
<MsmqTransportConfig ErrorQueue="error" NumberOfWorkerThreads="1" MaxRetries="5"/>
就是这样。 什么都行不通。 我从控制台项目发布事件,我的WPF应用程序没有任何反应。
也许我需要更多练习......;)
我正在使用NService Bus 3.0版,这是在RC4版本中,但我认为这不是问题。
感谢任何人都可以提供帮助!
→
答案 0 :(得分:0)
发现问题。 我订阅了一个“EventMessage”(实现了“IEvent” - &gt;实现了“IMessage”)并发布了“IEvent”!