{"id":16485136,"url":"https://github.com/jrouaix/mutopic","last_synced_at":"2025-09-18T15:32:43.811Z","repository":{"id":100601401,"uuid":"132193134","full_name":"jrouaix/Mutopic","owner":"jrouaix","description":"Micro topic pubsub","archived":false,"fork":false,"pushed_at":"2019-02-08T14:56:51.000Z","size":77,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-08-29T01:18:07.305Z","etag":null,"topics":["message-broker","pubsub","reactive","rx","topic"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jrouaix.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2018-05-04T22:02:22.000Z","updated_at":"2023-11-07T12:48:37.000Z","dependencies_parsed_at":"2023-05-16T06:45:31.974Z","dependency_job_id":null,"html_url":"https://github.com/jrouaix/Mutopic","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jrouaix/Mutopic","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jrouaix%2FMutopic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jrouaix%2FMutopic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jrouaix%2FMutopic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jrouaix%2FMutopic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jrouaix","download_url":"https://codeload.github.com/jrouaix/Mutopic/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jrouaix%2FMutopic/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275789305,"owners_count":25528712,"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-09-18T02:00:09.552Z","response_time":77,"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":["message-broker","pubsub","reactive","rx","topic"],"created_at":"2024-10-11T13:24:18.380Z","updated_at":"2025-09-18T15:32:43.481Z","avatar_url":"https://github.com/jrouaix.png","language":"C#","readme":"\n# \u003cimg alt=\"icon\" src=\"icon.png\" height=\"30\"\u003e Mutopic\nMicro, yet turbocharged, C# pubsub library.\n\n[![Build status](https://ci.appveyor.com/api/projects/status/1mpqa3gly0xkg8wy/branch/master?svg=true)](https://ci.appveyor.com/project/JromeRx/mutopic/branch/master)\n![License](https://img.shields.io/badge/License-Apache_2.0-44cc11.svg)\n![Nuget](https://img.shields.io/nuget/v/Mutopic.svg)\n![Nuget](https://img.shields.io/nuget/v/Mutopic.Reactive.svg)\n\n## Installing\n\nUsing NuGet Package Manager Console:\n`PM\u003e Install-Package Mutopic`\n\n## Design principles\n- **Topic based** - You publish in a topic name, you subscibe on the topic name too. Any \"typed\" implementation is just using the GetType().Name as topic name.\n- **Fire \u0026 Forget** - Publish should never throw any exception\n- **Synchronous** - Publish is synchronous and will call the subscribed handler as quick as possible. Then you can achieve asynchronous handling by pluging any task queuing system you need. (example : Reactive Extensions)\n\n## Getting started\nThe best place to start will be examples (when added). For a moment, best examples will be in the unit tests.\n\n\n### Subscribe multiple handlers\n\n```csharp\nusing Mutopic;\n```\n\nBuild a PubSub\n```csharp\nconst string TOPIC = \"topicName\";\nvar sut = new PubSubBuilder().Build();\n\nvar receivedA = new List\u003cstring\u003e();\nvar receivedB = new List\u003cint\u003e();\nvar receivedC = new List\u003cobject\u003e();\n```\n\nSubscribe \u0026 Publish\n```csharp \nusing (var subscriptionA = sut.Subscribe\u003cstring\u003e(TOPIC, receivedA.Add))\nusing (var subscriptionB = sut.Subscribe\u003cint\u003e(TOPIC, receivedB.Add))\nusing (var subscriptionC = sut.Subscribe\u003cobject\u003e(TOPIC, receivedC.Add))\n{\n    sut.Publish(1, TOPIC);\n    sut.Publish(\"topic to rule them all\", TOPIC);\n    sut.Publish(\"dead letter\", \"no_one_listen_this_topic\"); // no handler subscribed on this topic\n}\n```\n\nAssertions\n```csharp\nreceivedA.ShouldBe(new string[] { \"topic to rule them all\" });\nreceivedB.ShouldBe(new int[] { 1 });\nreceivedC.ShouldBe(new object[] { 1, \"topic to rule them all\" });\n```\n\n### Achieve asynchronous handling with Reactive Extensions\n\n```csharp\nusing Mutopic;\nusing Mutopic.Reactive;\n```\n\n```csharp\nconst string TOPIC = \"topicName\";\nvar randy = new Random();\nvar sut = new PubSubBuilder().Build();\n\nvar received = new ConcurrentBag\u003cobject\u003e();\nvar count = 0;\nusing (var observable = sut.SubscribeObservable\u003cint\u003e(TOPIC))\n{\n    using (observable\n        // without this next \"ObserveOn\" line, the publishing would be blocked by the long running one\n        .ObserveOn(TaskPoolScheduler.Default)                                       // after this, all message processing will be asynchronous\n        .Do(i =\u003e Thread.Sleep(randy.Next(20, 50)))                                  // some long running in the pipeline\n        .Do(i =\u003e Interlocked.Increment(ref count))\n        .Where(i =\u003e i == 42)                                                        // some filtering provided by reactive extension\n        .Select(i =\u003e $\"the answer to life the universe and everything is {i}.\")     // some transformation ..\n        .Subscribe(s =\u003e received.Add(s))                                            // this is reactive extensions subscription\n        )\n    {\n        var sw = new Stopwatch();\n        sw.Start();\n        for (int i = 0; i \u003c 100; i++)\n        {\n            sut.Publish(i, TOPIC);\n        }\n        sw.Stop();\n        sw.Elapsed.ShouldBeLessThan(TimeSpan.FromSeconds(0.05)); // This was quick !\n\n        Thread.Sleep(50 * 100); // Give it time to process all\n        count.ShouldBe(100);\n        received.ShouldBe(new[] { \"the answer to life the universe and everything is 42.\" });\n    }\n}\n```\n\n### Use middleware to build a publishing pipeline\n\nGiven this class hierarchy\n```csharp\ninterface IA { }\ninterface IB { }\ninterface IC { }\n\nclass A : IA { }\nclass B : A, IB { }\nclass C : IA, IC { }\n```\n\nBuild a pubsub with middleware\n```csharp\nconst string TOPIC = \"topic\";\n\nvar sut = new PubSubBuilder()\n    // this is a middleware\n    // it will propage messages in all their inheritance topic names\n    .WithMessageInheritancePublishing()\n    .Build();\n```\n\nPublish a message\n```csharp\nvar b = new B();\n\nvar topicReceived = new List\u003cobject\u003e();\nvar AReceived = new List\u003cobject\u003e();\nvar IBReceived = new List\u003cobject\u003e();\nusing (sut.Subscribe\u003cobject\u003e(TOPIC, topicReceived.Add))\nusing (sut.Subscribe\u003cA\u003e(typeof(A).Name, AReceived.Add))\nusing (sut.Subscribe\u003cIB\u003e(typeof(IB).Name, IBReceived.Add))\n{\n    sut.Publish(b, TOPIC);\n}\n```\n\nAssertions\n```csharp\n// Message have been propagaged in multiple topic names\ntopicReceived.ShouldBe(new object[] { b });\nAReceived.ShouldBe(new object[] { b });\nIBReceived.ShouldBe(new object[] { b });\n\n```    \n\n### Exception handling\n\nSince no exception will bubble from a handler, a OnSubscriptionException event is exposed to collect eventual exception.\nUse it to log errors !\n\n```csharp\nvar sut = new PubSubBuilder().Build();\nvar received = new List\u003cobject\u003e();\nvar exceptions = new List\u003cException\u003e();\nsut.OnSubscriptionException += (sub, mess, ex) =\u003e { received.Add(mess); exceptions.Add(ex); };\n\nusing (var subscription = sut.Subscribe(TOPIC, (object message) =\u003e throw new IndexOutOfRangeException()))\n{\n    sut.Publish(42, TOPIC);\n    sut.Publish(\"message\", TOPIC);\n    sut.Publish(\"dead letter\", \"no_one_listen_topic\"); // no handler subscribed on this topic\n}\n\nreceived.ShouldBe(new object[] { 42, \"message\" });\nexceptions.Count.ShouldBe(2);\nexceptions[0].ShouldBeAssignableTo\u003cIndexOutOfRangeException\u003e();\nexceptions[1].ShouldBeAssignableTo\u003cIndexOutOfRangeException\u003e();\n```\n\n# \u003cimg alt=\"Mutopic\" src=\"title.png\" height=\"100\"\u003e","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjrouaix%2Fmutopic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjrouaix%2Fmutopic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjrouaix%2Fmutopic/lists"}