{"id":13431554,"url":"https://github.com/rogeralsing/Microphone","last_synced_at":"2025-03-16T11:31:58.300Z","repository":{"id":65413790,"uuid":"44410440","full_name":"rogeralsing/Microphone","owner":"rogeralsing","description":null,"archived":true,"fork":false,"pushed_at":"2017-11-18T16:24:33.000Z","size":1939,"stargazers_count":460,"open_issues_count":19,"forks_count":70,"subscribers_count":44,"default_branch":"dotnetcore","last_synced_at":"2025-03-15T22:57:33.858Z","etag":null,"topics":[],"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/rogeralsing.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-10-16T21:02:33.000Z","updated_at":"2024-10-31T18:22:16.000Z","dependencies_parsed_at":"2023-01-23T10:55:06.028Z","dependency_job_id":null,"html_url":"https://github.com/rogeralsing/Microphone","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rogeralsing%2FMicrophone","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rogeralsing%2FMicrophone/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rogeralsing%2FMicrophone/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rogeralsing%2FMicrophone/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rogeralsing","download_url":"https://codeload.github.com/rogeralsing/Microphone/tar.gz/refs/heads/dotnetcore","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243863295,"owners_count":20360294,"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","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":[],"created_at":"2024-07-31T02:01:04.030Z","updated_at":"2025-03-16T11:31:56.352Z","avatar_url":"https://github.com/rogeralsing.png","language":"C#","funding_links":[],"categories":["Frameworks, Libraries and Tools","SDKs","框架, 库和工具","Capabilities"],"sub_categories":["SDKs","Misc","开发工具包SDKs","Configuration \u0026 Discovery"],"readme":"\u003cimg src=\"/Resources/microphone.png\" height=\"80\"\u003e\n\n# Microphone - Self announcing services\n\n**Microphone** is a lightweight framework to run self hosting REST services using **Web Api** or **NancyFx** ontop of a **Consul** or **ETCD** cluster.\nEach service will start out by allocating a free port to run on, once the service is started, it will register itself in the local cluster provider.\n\n## Install from Nuget\n\n**WebApi bootstrapper**\n\n```bat\nPM\u003e Install-Package Microphone.AspNet\n```\n\n**NancyFx bootstrapper**\n\n```bat\nPM\u003e Install-Package Microphone.Nancy\n```\n\n## Create a service\n\n### Web Api\n```csharp\n    class Program\n    {\n        static void Main(string[] args)\n        {\n            var options = new ConsulOptions();\n            var loggerFactory = new LoggerFactory();\n            var logger = loggerFactory.CreateLogger(\"logger\");\n            var provider = new ConsulProvider(loggerFactory, Options.Create(options));\n            Cluster.RegisterService(new Uri($\"http://localhost\"), provider, \"orders\", \"v1\", logger);\n            Console.ReadLine();\n        }\n    }\n\n    public class OrdersController : ApiController\n    {\n        public string Get()\n        {\n            return \"WebApi Service\";\n        }\n    }\n```\n\n### NancyFx\n\n```csharp\n    class Program\n    {\n        private static void Main(string[] args)\n        {\n            Cluster.Bootstrap(new NancyProvider(), new ConsulProvider(), \"customers\", \"v1\");\n            Console.ReadLine();\n        }\n    }\n\n    public class CustomersService : NancyModule\n    {\n        public MyService()\n        {\n            Get[\"/\"] = _ =\u003e \"Nancy Service\";\n        }\n    }\n```\n\n## Cluster providers\n\n**Consul**\n```\nCluster.Bootstrap(new WebApiProvider(), new ConsulProvider(), \"my-service\", \"v1\");\n```\n\nThe Consul provider also works together with Ebays \"Fabio\" load balancer https://github.com/eBay/fabio\n```\nCluster.Bootstrap(new WebApiProvider(), new ConsulProvider(useEbayFabio:true), \"my-service\", \"v1\");\n```\n\n**ETCD**\n```\nCluster.Bootstrap(new WebApiProvider(), new EtcdProvider(), \"my-service\", \"v1\");\n```\n\n## Service Discovery\n\nIf one of your services needs to communicate with another service in the same Consul cluster you can query it for active instances.\n\n```csharp\n//inside some WebApi/Nancy endpoint:\n\n//automatically load balanced over service instances\nvar instance = await Cluster.FindServiceInstanceAsync(\"orders\"); \n\n//Use Rest# or similar to call into the remote service\nMakeSomeCall(\"/api/orders\",instance.ServiceAddress, instance.ServicePort);\n```\n\n## Running your services\n\nBefore you start your services, make sure you have an active cluster running on the host machine.\n\n#### Consul Cluster\n\nIf you are new to Consul, you can bootstrap your test environment using this command:\n```\nconsul agent -server -bootstrap -data-dir /tmp/consul -bind=127.0.0.1\n```\n\nThis will give you a single server Consul cluster, this is not recommended for production usage, but it will allow you to use service discovery on your dev machine.\n\n\n#### Diagnostics using Consul REST API\n\nCheck service health on Consul agent:\n\n**GET**\n```\nhttp://localhost:8500/v1/agent/checks\n```\n\nCheck all services registered on Consul agent:\n\n**GET**\n```\nhttp://localhost:8500/v1/agent/services\n```\n\n#### ETCD Cluster\n\nIf you are using the ETCD cluster provider, make sure you have a local ETCD cluster running on your dev machine.\n\n```\netcd.exe\n```\n\n#### Key/Value storage\n\n```csharp\n    class Person\n    {\n        public string Name { get; set; }\n        public int Age { get; set; }\n    }\n\n    class Program\n    {\n        private static void Main(string[] args)\n        {\n            Cluster.Bootstrap(new WebApiProvider(), new ConsulProvider(), \"orders\", \"v1\");\n            Cluster.KVPutAsync(\"val1\", new Person { Name = \"Name\", Age = 25 }).Wait();\n            var res = Cluster.KVGetAsync\u003cPerson\u003e(\"val1\").Result;\n            Console.ReadLine();\n        }\n    }\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frogeralsing%2FMicrophone","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frogeralsing%2FMicrophone","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frogeralsing%2FMicrophone/lists"}