NServiceBus - NServiceBus.Host为出版商和WPF应用程序的用户。如何? [英] NServiceBus - NServiceBus.Host as publisher and WPF app as subscriber. How To?

查看:171
本文介绍了NServiceBus - NServiceBus.Host为出版商和WPF应用程序的用户。如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用NServiceBus从一个控制台程序(非常相似,包括在启动NServiceBus.Host.exe库PubSub的例子),以我的WPF应用程序发送消息。

I'm trying to use NServiceBus to send messages from a console process (very similar to PubSub example included in the library which starts NServiceBus.Host.exe) to my WPF application.

这就是我所做的。
在WPF的App.xaml类我已经定义

This what I did. In WPF App.xaml class I have defined

public static IBus Bus;



同一类,在application_startup处理程序:

same class, in application_startup handler:

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;
});

这是app.config中的WPF应用程序的:

this is app.config of WPF application:

<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可执行文件:

Then, my NServiceBus.Host publisher, very simple c# class library which starts in debug NServiceBus.Host.exe executable:

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出版商:

App.config in publisher:

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

    <MsmqTransportConfig ErrorQueue="error" NumberOfWorkerThreads="1" MaxRetries="5"/>

这就是它。
没有什么工作。
我从发布控制台项目的事件,并没有发生在我的WPF应用程序

That's it. Nothing works. I publish events from console project, and nothing happens in my WPF App.

也许我需要一些更多的实践...。)

Maybe I need some more practice...;)

我使用NService总线3.0版本,至极是RC4版本,但我想这不是问题。

I am using NService Bus version 3.0, wich is in RC4 release, but I suppose this is not the problem.

感谢任何人都可以帮助!

Thanks to anyone can help!

推荐答案

发现问题。
我已经订阅了事件消息(实现IEvent - >它实现了即时聊天)和发布IEvent

Found the problem. I had subscribing an "EventMessage" (which implements "IEvent" -> which implements "IMessage") and publishing an "IEvent"!

这篇关于NServiceBus - NServiceBus.Host为出版商和WPF应用程序的用户。如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆