{"id":21514177,"url":"https://github.com/greentube/messaging","last_synced_at":"2025-08-23T13:10:57.844Z","repository":{"id":75456510,"uuid":"111240079","full_name":"Greentube/messaging","owner":"Greentube","description":"Library for simple pub/sub with different serialization and brokers","archived":false,"fork":false,"pushed_at":"2018-02-23T17:30:11.000Z","size":162,"stargazers_count":9,"open_issues_count":1,"forks_count":2,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-07-22T01:59:08.600Z","etag":null,"topics":["dotnet-core","json","kafka","messagepack","messaging-library","protobuf","redis","xml"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Greentube.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-11-18T21:17:24.000Z","updated_at":"2022-11-09T10:23:04.000Z","dependencies_parsed_at":"2023-06-03T01:15:15.279Z","dependency_job_id":null,"html_url":"https://github.com/Greentube/messaging","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/Greentube/messaging","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Greentube%2Fmessaging","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Greentube%2Fmessaging/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Greentube%2Fmessaging/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Greentube%2Fmessaging/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Greentube","download_url":"https://codeload.github.com/Greentube/messaging/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Greentube%2Fmessaging/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268035807,"owners_count":24185101,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-31T02:00:08.723Z","response_time":66,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dotnet-core","json","kafka","messagepack","messaging-library","protobuf","redis","xml"],"created_at":"2024-11-23T23:43:07.567Z","updated_at":"2025-07-31T12:06:05.558Z","avatar_url":"https://github.com/Greentube.png","language":"C#","readme":"# messaging [![Build Status](https://travis-ci.org/Greentube/messaging.svg?branch=master)](https://travis-ci.org/Greentube/messaging) [![Build status](https://ci.appveyor.com/api/projects/status/a3pstjg357fn8it9/branch/master?svg=true)](https://ci.appveyor.com/project/Greentube/messaging) [![codecov](https://codecov.io/gh/Greentube/messaging/branch/master/graph/badge.svg)](https://codecov.io/gh/Greentube/messaging)\n\nAn opinionated messaging library for simple pub/sub with different serialization and message broker/middleware.\n\nTo use this library, you need to decide on which [serialization](#serialization) and [messaging middleware](#messaging-middleware) to use.\n\n## Samples\n\nThis repository includes two samples:\n\n* [Redis with Json serialization](https://github.com/Greentube/messaging/tree/master/samples/Greentube.Messaging.Sample.Redis)\n* [Kafka with ProtoBuf serialization](https://github.com/Greentube/messaging/tree/master/samples/Greentube.Messaging.Sample.Kafka)\n\n## Example publishing and handling a message on an ASP.NET Core application\n\n```csharp\n// Class without annotations\npublic class SomeMessage\n{\n    public string Body { get; set; }\n}\n\n// Handling messages: Class implementing IMessageHandler\u003cT\u003e to be invoked when T arrives\npublic class SomeMessageHandler : IMessageHandler\u003cSomeMessage\u003e\n{\n    public Task Handle(SomeMessage message, CancellationToken _)\n    {\n        Console.WriteLine($\"Handled: {message}.\");\n        return Task.CompletedTask;\n    }\n}\n\n// Startup.cs\npublic void ConfigureServices(IServiceCollection services)\n{\n    services.AddMessaging(builder =\u003e builder\n        .AddRedis()\n        .AddSerialization(b =\u003e b.AddProtoBuf())\n        .AddTopic\u003cSomeMessage\u003e(\"some.topic\"))\n}\npublic void Configure(IApplicationBuilder app)\n{\n    app.UseMessagingSubscriptions(); // Subscribes to the topics defined via Services\n}\n\n// Publishing via ASP.NET Core MVC:\n[Route(\"some-message\")]\npublic class SomeMessageController\n{\n    private readonly IMessagePublisher _publisher;\n    public SomeMessageController(IMessagePublisher publisher) =\u003e _publisher;\n\n    [HttpPut]\n    public async Task\u003cIActionResult\u003e PublishSomeMessage([FromBody] SomeMessage message, CancellationToken token)\n    {\n        await _publisher.Publish(message, token);\n        return Accepted();\n    }\n}\n```\n\n## Highlights\n\n* Supports multiple serialization formats and messaging middlewares.\n* Message handlers automatically discovered, registered\n* Handlers are resolved through DI with configurable lifetimes\n* Handler invocation done with [Expression trees](https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/expression-trees/)\n* Doesn't require implementing any interfaces or declaring attributes\n\n## Messaging middleware\n\nThe current supported messaging systems are:\n\n* [Redis](https://redis.io/topics/pubsub)\n* [Apache Kafka](https://kafka.apache.org/)\n\n## Serialization\n\nThe supported serialization formats are:\n\n* MessagePack - with [MessagePack-CSharp](https://github.com/neuecc/MessagePack-CSharp)\n* ProtoBuf - with [protobuf-net](https://github.com/mgravell/protobuf-net)\n* JSON - with [Newtonsoft.Json](https://github.com/JamesNK/Newtonsoft.Json)\n* XML - with [System.Xml.XmlSerializer](https://github.com/dotnet/corefx/tree/master/src/System.Xml.XmlSerializer)\n\nAll of the above can be 'plugged-in' with a single line when using the Messaging.DependencyInjection.* packages.\nExample serialization setup:\n\n```csharp\nservices.AddMessaging(builder =\u003e\n    builder.AddSerialization(s =\u003e\n    {\n        s.AddMessagePack();\n        // or\n        s.AddProtoBuf();\n        // or\n        s.AddJson();\n        // or\n        s.AddXml();\n    })\n```\n\nEach implementation has some additional settings.\n\n**For more information on serialization, please refer the [Greentube.Serialization](https://github.com/Greentube/serialization) repository.**\n\n## Discovering and Invoking handlers\n\nBy default. Implementations of `IMessageHandler\u003cT\u003e` are discovered and registered dynamically. \nWhen classes are in assemblies other than the entry assembly or the assemblies where `TMessage` is defined, \nthe library might need some help to find them. Similar to the [MVC Application parts](https://docs.microsoft.com/en-us/aspnet/core/mvc/advanced/app-parts) concept.\n\nOnly `public` implementations of `IMessageHandler\u003cT\u003e` will be automatically registered by default.\n\nYour handlers will be created via DI. That means you can take dependencies via the constructor but mind the lifetime:\nThe lifetime of the automatically registered Handlers is `Transient`. Each time a message arrives, the library will ask the container\nfor a message handler. Something like: `provider.GetService\u003cIMessageHandler\u003cT\u003e\u003e();` for each call.\nIt's advisable you switch to Singleton lifetime in case your handlers are thread-safe.\n\nThe characteristics mentioned above can be customized with:\n\n```csharp\nbuilder.AddHandlerDiscovery(d =\u003e\n    {\n        d.IncludeNonPublic = true;\n        d.DiscoveredHandlersLifetime = ServiceLifetime.Singleton;\n        d.MessageHandlerAssemblies.Add(typeof(SomeMessage).Assembly);\n    });\n```\n\n## Features planned\n\n* Add Message to Topic name map via Attributes\n\n## Limitations\n\nCurrently it only supports a single Handler per Message type. You can easily work around it by implementing some\ncomposite pattern on your Handler by dispatching a call to multiple, pontentially in multiple threads, etc.\nWe can consider adding such support if there's demand.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgreentube%2Fmessaging","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgreentube%2Fmessaging","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgreentube%2Fmessaging/lists"}