[英]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: 作为一般指导,在以下情况下,请考虑使用参与者模式来为您的问题或场景建模:
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:
我认为您可以执行以下操作:
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.