ASP.NET 核心中的服务总线
Service Bus in ASP.NET Core
我希望我的 ASP.NET 核心应用程序将消息发送到 Azure 服务总线。
在 Microsoft 的文章 Best Practices for performance improvements using Service Bus Messaging 中,他们认为您应该重用客户端实例。
It is recommended that you do not close messaging factories or queue, topic, and subscription clients after you send a message, and then re-create them when you send the next message.
所以我认为我不应该使用 new
关键字在我的控制器中实例化客户端 (TopicClient
or QueueClient
) 的新实例。
我想我应该使用 dependency injection in ASP.NET Core。
我应该直接注入 TopicClient
/QueueClient
还是应该创建一个自己的 class 来包装客户端实例并公开 SendAsync
方法?
使用依赖注入器注册服务时,我应该将其注册为单例吗?
我们用包装器 class 完成了它,然后返回 TopicClient/QueueClient 并将其注册为单例,发现这种方法没有大问题。
我们的方法基于 Microsoft eshopOnContainers.
提供的这个示例
此功能的示例代码可在 file 中找到。他们然后在需要 ServiceBus 的服务中将此 class 注册为 Startup.cs 中的单例。
我希望我的 ASP.NET 核心应用程序将消息发送到 Azure 服务总线。
在 Microsoft 的文章 Best Practices for performance improvements using Service Bus Messaging 中,他们认为您应该重用客户端实例。
It is recommended that you do not close messaging factories or queue, topic, and subscription clients after you send a message, and then re-create them when you send the next message.
所以我认为我不应该使用 new
关键字在我的控制器中实例化客户端 (TopicClient
or QueueClient
) 的新实例。
我想我应该使用 dependency injection in ASP.NET Core。
我应该直接注入 TopicClient
/QueueClient
还是应该创建一个自己的 class 来包装客户端实例并公开 SendAsync
方法?
使用依赖注入器注册服务时,我应该将其注册为单例吗?
我们用包装器 class 完成了它,然后返回 TopicClient/QueueClient 并将其注册为单例,发现这种方法没有大问题。
我们的方法基于 Microsoft eshopOnContainers.
提供的这个示例此功能的示例代码可在 file 中找到。他们然后在需要 ServiceBus 的服务中将此 class 注册为 Startup.cs 中的单例。