Giter Site home page Giter Site logo

yetimessaging's Introduction

YetiMessaging is very simple and lightweight framework that allows to publish and consume short broadcast messages on the certain machine.

Different transports can be used, UDP (no state connection and no guarantee) and file message (for fun) transports were implemented.

Server can be parameterized to use outer message factory.

Message has to implement custom IMessage interface and to be marked using Id attribute.

I have used YetiMessaging for VisualStudio addin to inform all addin instances about configuration changes.

Test cases can be found in the YetiMessagingTest folder

Simplest one is below

var subscriber = new YetiMessagingTest.StringSubscriber();

var transport = new UDPTransport("239.0.0.1", 2234);
using (var service = new Server(transport)) //server is ready and listening
{
	service.Add(subscriber); // subscriber has OnMessage method that is called with service if message type matches with subscriber type
	
	var transport2 = new UDPTransport("239.0.0.1", 2234); //client initialization, please note that udp transport instance can not be shared between client and service
	using (var client = new Client(transport2))
	{
		client.Send(new StringMessage("testmessage"));
	}
	
	Thread.Sleep(1500); // server should have time to get message from network and parse it
	Assert.IsTrue(subscriber.Message, "no message was received");
}

Here is sample subscriber implementation

[IdAttribute("{72F60CAB-B986-48D0-BA54-1DC4758CCD58}")]
public class StringSubscriber : Subscriber
{
	public bool Message { get; set; }

	public override void OnMessage(IMessage message, byte[] raw)
	{
		Trace.TraceInformation("string {0}", message.Value);
		Message = true;
	}
}

Subscriber type is set with Id attribute. It should have the same value that was set on appropriate message type. Please find string message base implementation below

[IdAttribute("{72F60CAB-B986-48D0-BA54-1DC4758CCD58}")]
public class StringMessage : IMessage
{
}

Message and subscriber has to be marked using the same GUID value. When message is going to be sent to listeners GUID value is saved to the stream before IMessage.Convert() serializes the message.

When received server checks by GUID value is there subscriber for this kind of message or not.

yetimessaging's People

Contributors

oleksabor avatar

Watchers

James Cloos avatar  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.