开发者

pub/sub nservicebus beginner

I am trying to get a simple NServiceBus pub/sub working. Here is what I am trying to do. I am trying to read a message from msmq, and pub publishes the messages to sub, and the sub will insert the messages to sub's queue. (right now, there are all on same computer).

I have a pub and a sub (there are Written as console apps). I also have a Message class, and here it is.

    [Serializable]
public class Message : IEvent
{
    public string name { get; set; }

}

public interface IEvent : IMessage
{
    string name { get; set; }

}

And, this is my pub

            IBus bus = NServiceBus.Configure.With()
            .DefaultBuilder()
            .XmlSerializer()
            .MsmqTransport()
                .IsTransact开发者_StackOverflow社区ional(true)
               .PurgeOnStartup(false)
            .UnicastBus()
            .ImpersonateSender(false)
            .MsmqSubscriptionStorage()
            .CreateBus().
            Start(); 

sub looks same execpt that it has .LoadMessageHandlers().

I understand that you have to handle the message, where do you put the Handle() on sub side? I want to read them and put them into sub's queue.

Thanks.


The Publisher will handle putting messages in the Subscriber's queue. To handle those messages, you must implement the IHandleMessages<T> interface on a class in your subscriber. NSB will execute the Handle method on that class when a message of that type shows up. For example:

public class MyMessageHandler : IHandleMessages<Message>;
{
    // do stuff here 
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜