初步理解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中的应用
Publish / Subscribe (发布者/订阅者)
²这种方式解决了发布消息对象知道消息发送给谁.(谁订阅了就给谁发)
Subscriptions (订阅者)
Publish(发布者)
NserviceBus in Distributor(在分布式系统的应用)
One publish(一个发布者):
Two publish(两个发布者的时候):
Point to Point(点对点通信)
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(请求\回复)
Publish & Subscribe(发布者\订阅者)
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)
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(分布式系统)
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> |
欢迎各位参与讨论,如果觉得对你有帮助,请点击 推荐下,万分谢谢.
作者:spring yang
出处:http://www.cnblogs.com/springyangwc/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!