{"id":16678956,"url":"https://github.com/joncloud/azure-servicebus-hosting","last_synced_at":"2026-05-19T06:06:04.441Z","repository":{"id":78825169,"uuid":"152356583","full_name":"joncloud/azure-servicebus-hosting","owner":"joncloud","description":"Azure Service Bus hosting infrastructure and startup logic for background applications","archived":false,"fork":false,"pushed_at":"2020-06-12T04:11:31.000Z","size":29,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"publish","last_synced_at":"2025-03-06T04:36:32.126Z","etag":null,"topics":["ampq","azure","hosting","netcore","queue","service-bus","subscription"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/joncloud.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","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-10-10T03:17:21.000Z","updated_at":"2019-01-05T20:10:26.000Z","dependencies_parsed_at":null,"dependency_job_id":"40b39818-fffb-4c9e-81fa-9c7757753da2","html_url":"https://github.com/joncloud/azure-servicebus-hosting","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joncloud%2Fazure-servicebus-hosting","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joncloud%2Fazure-servicebus-hosting/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joncloud%2Fazure-servicebus-hosting/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joncloud%2Fazure-servicebus-hosting/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joncloud","download_url":"https://codeload.github.com/joncloud/azure-servicebus-hosting/tar.gz/refs/heads/publish","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243360756,"owners_count":20278429,"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":["ampq","azure","hosting","netcore","queue","service-bus","subscription"],"created_at":"2024-10-12T13:32:24.887Z","updated_at":"2026-05-19T06:05:59.421Z","avatar_url":"https://github.com/joncloud.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ex.Microsoft.Azure.ServiceBus.Hosting\n[![NuGet](https://img.shields.io/nuget/v/Ex.Microsoft.Azure.ServiceBus.Hosting.svg)](https://www.nuget.org/packages/Ex.Microsoft.Azure.ServiceBus.Hosting/)\n\n## Description\nEx.Microsoft.Azure.ServiceBus.Hosting implements the ability to host an application process messages from an Azure Service Bus Queue or Subscription.\n\n## Licensing\nReleased under the MIT License. See the [LICENSE][] File for further details.\n\n[license]: LICENSE.md\n\n## Usage\nUse the `IMessageHandler` and `IExceptionHandler` interfaces in order to implement functionality for processing. The `IMessageHandler` interface is used for business logic that would normally get processed through the `RegisterMessageHandler` method. Likewise the `IExceptionHandler` interface is used for handling any uncaught exceptions.\n\n### Processing messages\nThis sample shows a simple implementation of what `IMessageHandler` requires.\n\n```csharp\nusing Microsoft.Azure.ServiceBus.Hosting;\nusing System.Threading;\nusing System.Threading.Tasks;\n\npublic class MyMessageHandler : IMessageHandler {\n  public Task HandleAsync(Message message, CancellationToken cancellationToken) =\u003e\n    throw new NotImplementedException();\n}\n```\n\n### Processing exceptions\nThis sample shows a simple implementation of what `IExceptionHandler` requires.\n\n```csharp\nusing Microsoft.Azure.ServiceBus.Hosting;\nusing System.Threading;\nusing System.Threading.Tasks;\n\npublic class MyExceptionHandler : IExceptionHandler {\n  public Task HandleExceptionAsync(ExceptionReceivedEventArgs eventArgs) =\u003e\n    throw new NotImplementedException();\n}\n```\n\n### Connecting to a Service Bus Queue\nUse the `ConfigureServiceBusQueue` extension method to connect to a Service Bus Queue.\n\n```csharp\nusing Microsoft.Azure.ServiceBus.Hosting;\nusing Microsoft.Extensions.Configuration;\nusing Microsoft.Extensions.Hosting;\nusing System.Threading.Tasks;\n\npublic static class Program {\n  static string GetConnectionString(IConfiguration configuration) =\u003e\n    configuration.GetSection(\"ConnectionStrings\")[\"ServiceBusConnection\"];\n\n  public static Task Main(string[] args) =\u003e\n    new HostBuilder().ConfigureServiceBusQueue(\n      (hostBuilder, options) =\u003e \n        options.ConnectionString = GetConnectionString(hostBuilder.Configuration),\n      context =\u003e context.ExceptionHandler\u003cMyExceptionHandler\u003e()\n        .StaticMessageHandler()\n        .Scoped\u003cMyMessageHandler\u003e()\n    )\n    .RunConsoleAsync();\n}\n```\n\n### Connecting to a Service Bus Subscription\nUse the `ConfigureServiceBusSubscription` extension method to connect to a Service Bus Subscription.\n\n```csharp\nusing Microsoft.Azure.ServiceBus.Hosting;\nusing Microsoft.Extensions.Configuration;\nusing Microsoft.Extensions.Hosting;\nusing System.Threading.Tasks;\n\npublic static class Program {\n  static string GetConnectionString(IConfiguration configuration) =\u003e\n    configuration.GetSection(\"ConnectionStrings\")[\"ServiceBusConnection\"];\n\n  public static Task Main(string[] args) =\u003e\n    new HostBuilder().ConfigureServiceBusSubscription(\n      (hostBuilder, options) =\u003e\n      {\n        options.ConnectionString = GetConnectionString(hostBuilder.Configuration);\n        options.SubscriptionName = hostBuilder.Configuration[\"SubscriptionName\"];\n      },\n      context =\u003e context.ExceptionHandler\u003cMyExceptionHandler\u003e()\n        .StaticMessageHandler()\n        .Scoped\u003cMyMessageHandler\u003e()\n    )\n    .RunConsoleAsync();\n}\n```\n\n### Handling messages generically\nYou can also handle messages using `IMessageHandler\u003cT\u003e`, which creates a contract with a generic type.\n\n```csharp\npublic class MyInt32Handler : IMessageHandler\u003cint\u003e {\n  public Task HandleAsync(int message, CancellationToken cancellationToken) =\u003e\n    throw new NotImplementedException();\n}\n\npublic class MyStringHandler : IMessageHandler\u003cstring\u003e {\n  public Task HandleAsync(string message, CancellationToken cancellationToken) =\u003e\n    throw new NotImplementedException();\n}\n\npublic static class Program {\n  static string GetConnectionString(IConfiguration configuration) =\u003e\n    configuration.GetSection(\"ConnectionStrings\")[\"ServiceBusConnection\"];\n\n  public static Task Main(string[] args) =\u003e\n    new HostBuilder().ConfigureServiceBusQueue(\n      (hostBuilder, options) =\u003e\n        options.ConnectionString = GetConnectionString(hostBuilder.Configuration),\n      context =\u003e context.ExceptionHandler\u003cMyExceptionHandler\u003e()\n        .GenericMessageHandler(msg =\u003e\n        {\n          switch (msg.ContentType)\n          {\n            case \"int\":\n              return BitConverter.ToInt32(msg.Body, 0);\n            case \"string\":\n              return Encoding.UTF8.GetString(msg.Body);\n            default:\n              throw new Exception(\"Invalid message content type\");\n          }\n        })\n        .Scoped\u003cint, MyInt32Handler\u003e()\n        .Scoped\u003cstring, MyStringHandler\u003e()\n    )\n    .RunConsoleAsync();\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoncloud%2Fazure-servicebus-hosting","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoncloud%2Fazure-servicebus-hosting","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoncloud%2Fazure-servicebus-hosting/lists"}