Giter Site home page Giter Site logo

arstomp's Introduction

Simple STOMP over WS client

Implemented in C# (.NET Core and Framework)

Works with RabbitMQ.

Uses (and probably requires) binary frames.

Supports 'custom' Root CA certficates.

Has simple RPC helper.

Usage

class Program
{
	static async Task Main(string[] args)
	{
		var utf8 = Encoding.UTF8;

		byte[] bytes = File.ReadAllBytes("path/to/ca.crt");
		X509Certificate2 myca = new X509Certificate2(bytes);
		X509Certificate2Collection mycerts = new X509Certificate2Collection { myca };

		StompClient client = new StompClient(mycerts);
		// can get messages in handler
		//client.OnMessage += OnMessage;
		// or use something to make request/response simpler
		using var rpc = new RPC(client);

		// connect
		var uri = new Uri("wss://stomp.server:15673/ws");
		await client.Connect(uri, "login", "pass");

		// subscriptions
		var sub1 = await client.Subscribe("/exchange/ex1/test.#");
		sub1.OnMessage += OnBroadcast;
		var sub2 = await client.Subscribe("/exchange/ex2/test.#");
		sub2.OnMessage += OnBroadcast;

		// simple publish (no response)
		await client.Send("/exchange/something/test", "1", utf8.GetBytes("Test 1"));

		// simple call (sending request and expecting response)
		var result = await rpc.Call("/exchange/rpc/test", utf8.GetBytes("Test 2"),
			TimeSpan.FromSeconds(3));
		Console.WriteLine("RCP: {0}", result);

		await client.Close();
	}
	static void OnBroadcast(object sender, SubscriptionEventArgs ea)
	{
		Console.WriteLine("Broadcast {0}", ea.Frame);
		var body = Encoding.UTF8.GetString(ea.Frame.Body);
		Console.WriteLine("Body: {0}", body);
	}
}

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.