Skip to content

AdamMYoung/ObjectBus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ObjectBus

ObjectBus is a library to make it quick and simple to serialize/serialize objects across applications via an Azure Service Bus.

NuGet package

Usage

First create your ObjectBus in the ConfigureServices() method, by specifying the connection information and bus type.

services.CreateObjectBus<YourMessageObject>(p =>
	p.Configure("ConnectionString", "QueueName", BusTypes.Sender));	

//OR

services.CreateObjectBus<YourMessageObject>(p =>
	p.Configure("ConnectionString", "QueueName", BusTypes.Reciever));

Then, access the ObjectBus via dependency injection in the constructor:

private IObjectBus<YourMessageObject> NewObjectBus { get; }

public MyClass(IObjectBus<YourMessageObject> objectBus)
{
	NewObjectBus = objectBus;
}

Send

To send your objects, simply call the SendAsync() method with the object you wish to send, like so:

public void SendObject() 
{
	var newObject = new YourMessageObject();
	NewObjectBus.SendAsync(newObject);
}

Recieve

To receive objects, subscribe to the MessageRecieved event of the ObjectBus.

public MyClass(IObjectBus<YourMessageObject> objectBus)
{
	NewObjectBus = objectBus;
	NewObjectBus.MessageRecieved += onMessageRecieved;
}

The received object is within the MessageEventArgs argument.

private void onMessageRecieved(object sender, MessageEventArgs<RecordingChunk> e)
{
	var myObject = e.Object;
	//Do something with object.
}

Overrides

If the current implementation doesn't fit your use case, you can create a subclass of ObjectBus, and override the SendAsync() or HandleMessageAsync() methods like so:

public class SubclassObjectBus : ObjectBus<YourMessageObject> 
{
	public SubclassObjectBus(IOptions<YourMessageObject> options) : base(options) {}
	
	//Handle incoming messages.
	override Task HandleMessageAsync(YourMessageObject message) {}
	
	//Handle outgoing messages.
	override Task SendAsync(YourMessageObject message){}
}

This can then be injected in the startup method similar to before, with the subclass specified.

services.CreateObjectBus<YourMessageObject, SubclassObjectBus>(p =>
	p.Configure("ConnectionString", "QueueName", BusTypes.Sender));	

About

Object serialization/deserialization library for the Azure Service Bus

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages