简体   繁体   English

服务结构,什么微服务最适合从服务总线进行连续轮询

[英]Service Fabric, What Microservices is best intended for continuous polling from Service Bus

I am new to Service Fabric. 我是Service Fabric的新手。

We have a queue on Azure Service Bus. 我们在Azure Service Bus上有一个队列。 I want to continuously pull from the queue in my Service Fabric, process the message (execute some business logic) and save some data in the DB, then remove the message from the queue. 我想连续从Service Fabric中的队列中提取消息,处理消息(执行一些业务逻辑)并将某些数据保存在DB中,然后从队列中删除消息。

The Microservice should check the queue every couple of seconds to monitor for a new message. 微服务应每隔几秒钟检查一次队列,以监视是否有新消息。

My question is, What is the intended Microservice(s) that would pull data, process some business logic, then save to the DB. 我的问题是, 将提取数据,处理一些业务逻辑然后保存到数据库的预期微服务什么? Is it A Stateless Service or a Reliable Actor 是无国籍服务还是可靠演员

(Edit: interpreted question wrong earlier) (编辑:解释错误的问题较早)

I'd say it's a matter of personal preference which model you choose. 我会说,选择哪种型号是个人喜好问题。

You can have a stateless service running on all nodes, receiving messages and processing them on worker threads. 您可以在所有节点上运行无状态服务,以接收消息并在工作线程上对其进行处理。

Actors are less able to singlehandedly process lots of messages because of the Single Entry model (limiting multi-threading options). 由于单入口模型(限制多线程选项),Actor不能单手处理大量消息。 But Actors can come in numbers. 但是演员可以有很多。 You can have many Actors listening for messages. 您可以让许多Actor收听消息。 You'd need to ensure those Actors become & stay alive though. 您需要确保那些演员成为并保持活着。


original answer: 原始答案:

This nuget package does this: https://www.nuget.org/packages/ServiceFabric.ServiceBus.Services It supports queues, topics, batching and sessions. 这个nuget包可以这样做: https ://www.nuget.org/packages/ServiceFabric.ServiceBus.Services它支持队列,主题,批处理和会话。

Your problem space seems to fit the stateful or stateless model. 您的问题空间似乎适合有状态或无状态模型。 Either one is fine depending on whether you need to maintain state or not. 根据您是否需要维护状态,哪种都可以。

As general guidance, consider the actor pattern to model your problem or scenario if: 作为一般指导,在以下情况下,请考虑使用参与者模式来为您的问题或场景建模:

  • Your problem space involves a large number (thousands or more) of small, independent, and isolated units of state and logic. 您的问题空间涉及大量(成千上万个)小型,独立且隔离的状态和逻辑单元。
  • You want to work with single-threaded objects that do not require significant interaction from external components, including querying state across a set of actors. 您希望使用不需要与外部组件进行大量交互(包括查询一组参与者的状态)的单线程对象。
  • Your actor instances won't block callers with unpredictable delays by issuing I/O operations. 您的actor实例不会通过发出I / O操作而以不可预测的延迟阻止调用者。

Reference: https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-reliable-actors-introduction 参考: https : //docs.microsoft.com/en-us/azure/service-fabric/service-fabric-reliable-actors-introduction

You may use any. 您可以使用任何一个。 Stateless or Statefull. 无状态或全状态。 Is should not really matter. 是应该没关系的。 In my view, you can do below: 我认为您可以执行以下操作:

  1. Create a custom listener say "ServiceBusCommunicationListener" derived from ICommunicationListener. 创建一个自定义侦听器,说它是从ICommunicationListener派生的“ ServiceBusCommunicationListener”。 In the "public Task OpenAsync(CancellationToken cancellationToken)" method of ICommunicationListener, you can write code to access service bus queue. 在ICommunicationListener的“公共任务OpenAsync(CancellationToken cancelleToken)”方法中,可以编写代码以访问服务总线队列。
  2. For Service Bus Queue read, you can use "Microsoft.ServiceBus.Messaging.SubscriptionClient" and use its "OnMessageAsync" method to continuously receive message. 对于读取服务总线队列,可以使用“ Microsoft.ServiceBus.Messaging.SubscriptionClient”并使用其“ OnMessageAsync”方法连续接收消息。
  3. Once you have this, inside your service code, you may use StatefulService's "CreateServiceReplicaListeners" override or StatelessService's "CreateServiceInstanceListeners". 一旦有了这些,就可以在服务代码中使用StatefulService的“ CreateServiceReplicaListeners”替代或StatelessService的“ CreateServiceInstanceListeners”。

      protected override IEnumerable<ServiceReplicaListener> CreateServiceReplicaListeners() { return new[] { new ServiceReplicaListener(context => new ServiceBusCommunicationListener(context)) }; } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM