项目作者: alandoherty

项目描述 :
A library for cross-language service and event bus communication over RabbitMQ
高级语言: C#
项目地址: git://github.com/alandoherty/holon-net.git
创建时间: 2018-07-10T21:46:31Z
项目社区:https://github.com/alandoherty/holon-net

开源协议:Apache License 2.0

下载




GitHub license
GitHub issues
GitHub stars
GitHub forks
GitHub forks

Holon

This repository provides an in-development messaging and service layer ontop of RabbitMQ.

Goals

Holon was created to satisfy a mix-match of goals that are not completely fullfiled by competing libraries. Some are too heavy, others have dependency bloat or inconsistent API’s. This library attempts to provide the following tenants:

  • Decoupled transport architecture and few dependencies
  • No use of language specific technologies
  • Support various types of services
  • Decoupling remote-procedure call from the service layer
  • Event system built-in

Getting Started

NuGet Status

You can install the package using either the CLI:

  1. dotnet add package Holon

or from the NuGet package manager:

  1. Install-Package Holon

Example

The repository comes with an example project, but a practical example of how this library can be used is documented below.

Factory Service

The factory service provides a way to look at the total production and command a factory to start and stop. The implementation here is a console application but it can be embedded anywhere that is async friendly.

  1. [RpcContract]
  2. interface IFactoryController
  3. {
  4. [RpcOperation]
  5. Task<double> GetProductionToday();
  6. [RpcOperation]
  7. Task StartProduction();
  8. [RpcOperation]
  9. Task StopProduction();
  10. }
  11. class FruitFactory : IFactoryController
  12. {
  13. public async Task GetProductionToday() {
  14. return 10000.0;
  15. }
  16. public async Task StartProduction() {
  17. // start our factory up!
  18. }
  19. public async Task StopProduction() {
  20. // shut it down before any fruit gets bruised
  21. }
  22. }
  23. class ServiceHost {
  24. static void Main() => MainAsync().Wait();
  25. static async Task MainAsync() {
  26. // attach node
  27. Node node = await Node.CreateAsync("amqp://localhost");
  28. // attach our service
  29. await node.AttachAsync("factory:fruit", ServiceType.Singleton, RpcBehaviour.Bind<IFactoryController>(new FruitFactory()));
  30. // wait forever
  31. await Task.Delay(Timeout.InfiniteSpan);
  32. }
  33. }

Client

The client can also be embedded anywhere that is async friendly, and provides a simple way to obtain a proxy and begin communicating with the fruit factory. The interface class is carried over from the previous example.

  1. class Client {
  2. static void Main() => MainAsync().Wait();
  3. static async Task MainAsync() {
  4. // attach node
  5. Node node = await Node.CreateAsync("amqp://localhost");
  6. // get a proxy to the factory
  7. IFactoryController controller = node.Proxy<IFactoryController>("factory:fruit");
  8. // start production!
  9. await controller.StartProduction();
  10. }
  11. }

Licenses

Package License
Newtonsoft.Json MIT
PeNet.Asn1 MIT
protobuf-net Apache 2.0
RabbitMQ.Client Apache 2.0 & MPL 1.1
.NET Core MIT

Contributing

Any pull requests or bug reports are welcome, please try and keep to the existing style conventions and comment any additions.