Fork me on GitHub
NServiceBus 开源通讯框架

概述

NServiceBus 是一个用于构建企业级 .NET系统的开源通讯框架。它在消息发布/订阅支持、工作流集成和高度可扩展性等方面表现优异,因此是很多分布式系统基础平台的理想选择。,它能够帮助开发人员在搭建企业.NET系统时避免很多典型的常见问题。同时,该框架也提供了一些可伸缩的关键特征,比如对发布/订阅的支持、集成的长时间工作流及深入的扩展能力等。据作者说,其本意是为构建分布式应用软件创建一个理想的基础设施。

NServiceBus的核心并不依赖于MSMQ。NServiceBus可扩展性允许我们插入自行编写的通信传送器,、订阅存储器和工作流的实现。我已经基于MSMQ实现了一个传送器,还有一个则借助了WCF的NetTCP。开发人员既可以使用这些现有组件,也可以根据需要进行自定义。我们知道当前的许多SOA产品都与HTTP紧密耦合,因此NServiceBus的这种实现方式也将是个另辟蹊径的设计。 
之所以选择使用MSMQ,是因为它是微软公司的两大主流的通讯技术之一(另一个是SQL Server Service Broker)。MSMQ允许双方在离线的状态下进行通信,且它提供了一整套易于使用的API,并已经集成到了.NET框架中,这一点要比Service Broker好得多。我个人认为支持离线通信是任何SOA基础框架都必须考虑的关键部分——因为Tenet of Service Autonomy 并不能保证当前通信的另一端处于可用状态。

NServiceBus是dotnet世界里面最流行的开源企业服务总线.  它具有以下特点: 1.强大,轻量级.     2.可插拨,简单易用.     3.支持企业级开发.

 

在internet中的应用

image

 

 

Publish / Subscribe (发布者/订阅者)

²这种方式解决了发布消息对象知道消息发送给谁.(谁订阅了就给谁发)

Subscriptions (订阅者)

image

 

Publish(发布者)

image

 

NserviceBus in Distributor(在分布式系统的应用)

One publish(一个发布者):

image

 

Two publish(两个发布者的时候):

image

 

 

 

Point to Point(点对点通信)

image

 

Point to Point Configuration(需要配置)

1
2
3
4
5
6
Client
 
class EndPointConfig : IConfigureThisEndpoint, AsA_Client { }
 
<UnicastBusConfig>      <MessageEndpointMappings>       <add Messages="MyMessages“ Endpoint="MyServerInputQueue" />   </MessageEndpointMappings>
</UnicastBusConfig>

 

 

1
2
3
4
5
Server
 
class EndPointConfig : IConfigureThisEndpoint, AsA_Server { }
 
<MsmqTransportConfig InputQueue="MyServerInputQueue" />

 

 

Request & Response(请求\回复)

image

 

Publish & Subscribe(发布者\订阅者)

image

 

 

1
2
3
4
5
Subscriber
 
class EndPointConfig : IConfigureThisEndpoint, AsA_Server { }
 
<MsmqTransportConfig InputQueue=Subscriber1InputQueue" />   <UnicastBusConfig>      <MessageEndpointMappings>       <add Messages="MyMessages" Endpoint=" MyPublisherInputQueue" />     </MessageEndpointMappings>   </UnicastBusConfig>

 

1
2
3
4
5
Publisher
 
class EndPointConfig : IConfigureThisEndpoint, AsA_Publisher { }
 
<MsmqTransportConfig InputQueue="MyPublisherInputQueue />

 

 

Saga(Workflow)

image

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Server
 
class EndPointConfig : IConfigureThisEndpoint, AsA_Server { }
 
<MsmqTransportConfig InputQueue=MySagaInputQueue" />
  <UnicastBusConfig>   <MessageEndpointMappings>     <add Messages="MyMessages" Endpoint="MyDestinationInputQueue" />
      <add Messages=“NServiceBus.Saga.TimeoutMessage” Endpoint=“timeoutmanager” >   </MessageEndpointMappings>
  </UnicastBusConfig>
 
<NHibernateSagaPersisterConfig>
  <NHibernateProperties>
      <add Key="connection.provider“ Value="NHibernate.Connection.DriverConnectionProvider"/>
      <add Key="connection.driver_class" Value="NHibernate.Driver.SqlClientDriver"/>
      <add Key="connection.connection_string" Value="Server=localhost;initial    catalog=NServiceBus;Integrated Security=SSPI"/>
      <add Key="dialect" Value="NHibernate.Dialect.MsSql2000Dialect"/>
    </NHibernateProperties>
  </NHibernateSagaPersisterConfig>

 

 

 

Distributor(分布式系统)

image

 

1
2
3
<appSettings>   <add key="NumberOfWorkerThreads" value="1"/>   <!-- queue that the distributor process reads and feeds to workers -->   <add key="DataInputQueue" value="nservicebus_distributor_data_bus"/>
  <!--queue that manages work distribution -->  <add key="ControlInputQueue“  value="nservicebus_distributor_control_bus"/>   <!-- errors -->   <add key="ErrorQueue" value="nservicebus_error"/>   <!-- queue that maintains the state(availability) of the workers -->   <add key="StorageQueue" value="nservicebus_distributor_storage"/>      <!-- relevant for a Serialization of "interfaces" or "xml" -->   <add key="NameSpace" value="http://www.MySite.com"/>         <add key="Serialization" value="xml"/>   <!-- can be either "xml", or "binary" -->
</appSettings>

 

posted on   HackerVirus  阅读(1421)  评论(2编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
历史上的今天:
2009-12-26 聊聊我对开发项目选技术的看法2
2009-12-26 中介者模式(Mediator)
2009-12-26 职责链模式(Chain of Responsibility)
2009-12-26 命令模式(Command)
2009-12-26 桥接模式(Bridge)与合成/聚合复用原则(CARP)
2009-12-26 大型网站性能优化的通用方法
2009-12-26 单例模式(Singleton)
点击右上角即可分享
微信分享提示