Git Product home page Git Product logo

signalrems's Introduction

Description

SignalRems is one Enterprise Messaging System (EMS) implemented by .NET Standard SignalR. It provides two communication models, RPC and PUB/SUB. This library will provide strong typed API to help client application communicate with server. It is using Newtonsoft.json or MessagePack for serialization/deserialization. In PUB/SUB mode, it subscribes with filter of Lambda expression.

Dependency

This libiary is built on SingalR, hence the server application must be using "Microsoft.NET.Sdk.Web" SDK. The client side could use any .net 6.0 SDK.

API usage

RPC Server

  1. Configure WebApplication builder;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSignalRemsService(); // Using Json serialization/deserialization
// builder.Services.AddSignalRemsService(true); // MessagePack serialization/deserialization
  1. Setup endpoint for app instance:
var app = builder.Build();
app.MapSignalRemsRpcHub("/signalr/ems/example/rpc");
  1. Register RPC handler in IRpcService instance. IRpcService instance is singleton and can be get from dependency injection, handler implements IRpcHandler<,> interface to handle the RPC logic;
IRpcService rpcService;
IRpcHandler<GetUserNameRequest, GetUserNameResponse> handler;
rpcService.RegisterHandler<GetUserNameRequest, GetUserNameResponse>(handler);

RPC Client

  1. Config RPC client into dependency injection;
services.AddSignalRemsClient(); // Using Json serialization/deserialization
// services.AddSignalRemsClient(true); // MessagePack serialization/deserialization
  1. Make connection and call:
await _rpcClient.ConnectAsync("https://localhost:7198", "/signalr/ems/example/rpc", stoppingToken);
var request = new GetUserNameRequest() { UserId = i.ToString() };
var response = await _rpcClient.SendAsync<GetUserNameRequest, GetUserNameResponse>(request);

PUB/SUB Server

  1. Configure WebApplication builder;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSignalRemsService();
  1. Setup endpoint for app instance:
var app = builder.Build();
app.MapSignalRemsPublisherHub("/signalr/ems/example/pubsub");
  1. Create publisher from IPublisherService, IPublisherService is singleton instance;
IPublisherService publisherService;
var publisher =  _publisherService.CreatePublisher<Person, int>("Message");
  1. Publish item to topic
publisher.Publish(new Person() { Id = id, Age = random.Next(95), Name = $"Person_{id:000}" });

PUB/SUB Client

  1. Config subscriber client into dependency injection;
services.AddSignalRemsClient();
  1. Make connection and call. It supports Lambda expression as filter. This Lambda expression must be able to be explained from both server and client.
ISubscriptionHandler<Person> handler;
await _subscriberClient.ConnectAsync("https://localhost:7198", "/signalr/ems/example/pubsub", stoppingToken);
var subscription = await _subscriberClient.SubscribeAsync("Message", handler, p=> p.Age > 60);

Please note, one client can only be used to do one subscription. The dispose method will stop the subscription and disconnect from server. We can get multiple client instances from DI container to subscribe with differnet topic/filter.

License

This project is open source and follows MIT license.

signalrems's People

Contributors

lipascal avatar

Stargazers

 avatar

Watchers

James Cloos avatar

Forkers

cloud-develop

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.