Giter Site home page Giter Site logo

tinyipc's Introduction

TinyIpc

NuGet Build

.NET inter process broadcast message bus.

Intended for quick broadcast messaging in Windows desktop applications, it just works.

Quick introduction

  • Designed to be serverless
  • Clients may drop in and out at any time
  • Messages expire after a specified timeout, default 500 milliseconds
  • The log is kept small for performance, default max log size is 1 MB
  • Reads are queued and should be received in the same order as they were published

Benefits and drawbacks

It's easy to use and there is no complicated setup. It is suited for small messages, so big messages probably need some other transport mechanism. With high enough throughput messages may be lost if receivers are not able to get a read lock before the message timeout is reached.

Performance

Every publish operation reads and writes the entire contents of a shared memory mapped file and every read operation which is triggered by writes also reads the entire file so if performance is important then batch publish several messages at once to reduce the amount of reads and writes.

OS Support

Unfortunately TinyIpc only works on Windows because the named primitives that are core to this entire solution only works on Windows and throws PlatformNotSupportedException on other operating systems by design.

See dotnet/runtime#4370 for more information.

Compared to other solutions

TinyIPC IpcChannel Named Pipes
Broadcasting to all listeners (except self)
No master process
Insensitive to process privilege level
Entirely in memory

Simple example

One message bus listening to the other. Check ConsoleApp for a sample application.

using var messagebus1 = new TinyMessageBus("ExampleChannel");
using var messagebus2 = new TinyMessageBus("ExampleChannel");

messagebus2.MessageReceived +=
	(sender, e) => Console.WriteLine(Encoding.UTF8.GetString(e.Message));

while (true)
{
	var message = Console.ReadLine();
	await messagebus1.PublishAsync(Encoding.UTF8.GetBytes(message));
}

Example using generic hosting

Equivalent example to the above using generic hosting. Check GenericHost for a sample application.

// Add service to IServiceCollection
services.AddTinyIpc(options =>
{
	options.Name = "ExampleChannel";
});

// Later use ITinyIpcFactory to create instances
using var tinyIpcInstance1 = tinyIpcFactory.CreateInstance();
using var tinyIpcInstance2 = tinyIpcFactory.CreateInstance();

tinyIpcInstance2.MessageBus.MessageReceived +=
	(sender, e) => Console.WriteLine(Encoding.UTF8.GetString(e.Message));

while (true)
{
	var message = Console.ReadLine();
	await tinyIpcInstance1.MessageBus.PublishAsync(Encoding.UTF8.GetBytes(message));
}

tinyipc's People

Contributors

davidzidar avatar githubpang avatar weazl avatar

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.