项目作者: jacqueskang

项目描述 :
.NET Core Inter-process communication framework
高级语言: C#
项目地址: git://github.com/jacqueskang/IpcServiceFramework.git
创建时间: 2018-01-04T10:12:33Z
项目社区:https://github.com/jacqueskang/IpcServiceFramework

开源协议:MIT License

下载


CI build Stable build
Build Status Build Status

IpcServiceFramework

A .NET Core 3.1 based lightweight framework for efficient inter-process communication.
Named pipeline and TCP support out-of-the-box, extensible with other protocols.

NuGet packages

Name Purpose Status
JKang.IpcServiceFramework.Client.NamedPipe Client SDK to consume IPC service over Named pipe NuGet version
JKang.IpcServiceFramework.Client.Tcp Client SDK to consume IPC service over TCP NuGet version
JKang.IpcServiceFramework.Hosting.NamedPipe Server SDK to run Named pipe IPC service endpoint NuGet version
JKang.IpcServiceFramework.Hosting.Tcp Server SDK to run TCP IPC service endpoint NuGet version

Usage

  1. Create an interface as service contract and package it in an assembly to be referenced by server and client applications, for example:

    1. public interface IInterProcessService
    2. {
    3. string ReverseString(string input);
    4. }
  2. Implement the service in server application, for example:

    1. class InterProcessService : IInterProcessService
    2. {
    3. public string ReverseString(string input)
    4. {
    5. char[] charArray = input.ToCharArray();
    6. Array.Reverse(charArray);
    7. return new string(charArray);
    8. }
    9. }
  3. Install the following NuGet packages in server application:

    1. > Install-Package Microsoft.Extensions.Hosting
    2. > Install-Package JKang.IpcServiceFramework.Hosting.NamedPipe
  4. Register the service implementation and configure IPC endpoint(s):

    1. class Program
    2. {
    3. public static void Main(string[] args)
    4. {
    5. CreateHostBuilder(args).Build().Run();
    6. }
    7. public static IHostBuilder CreateHostBuilder(string[] args) =>
    8. Host.CreateDefaultBuilder(args)
    9. .ConfigureServices(services =>
    10. {
    11. services.AddScoped<IInterProcessService, InterProcessService>();
    12. })
    13. .ConfigureIpcHost(builder =>
    14. {
    15. // configure IPC endpoints
    16. builder.AddNamedPipeEndpoint<IInterProcessService>(pipeName: "pipeinternal");
    17. })
    18. .ConfigureLogging(builder =>
    19. {
    20. // optionally configure logging
    21. builder.SetMinimumLevel(LogLevel.Information);
    22. });
    23. }
  5. Install the following NuGet package in client application:

    1. > Install-Package JKang.IpcServiceFramework.Client.NamedPipe
  6. Invoke the server

    1. // register IPC clients
    2. ServiceProvider serviceProvider = new ServiceCollection()
    3. .AddNamedPipeIpcClient<IInterProcessService>("client1", pipeName: "pipeinternal")
    4. .BuildServiceProvider();
    5. // resolve IPC client factory
    6. IIpcClientFactory<IInterProcessService> clientFactory = serviceProvider
    7. .GetRequiredService<IIpcClientFactory<IInterProcessService>>();
    8. // create client
    9. IIpcClient<IInterProcessService> client = clientFactory.CreateClient("client1");
    10. string output = await client.InvokeAsync(x => x.ReverseString(input));

FAQs