简体   繁体   中英

Azure service fabric : IReliableQueue

I'm using azure service fabric for our new service.

For the client-facing gateway I have a stateless service getting request using a Web API endpoint, the actual work is done using reliable stateless actors.

As suggested by Sean McKenna - MSFT in this question , I put the incoming request in a ReliableQueue and storing the result in a ReliableDictionary.

I don't understand how to implement this, where do I define the ReliableQueue?? it is obvious(?) that enqueue a job will occur at the Web API controller, but where do i dequeue an object and when? there are no event firing telling me an object was added??

As you see I'll love some help on this

Thanks

In the question you refer to, I am describing the pattern shown in the WordCount sample .

In that case, the application is made up of a stateless gateway service and a stateful processing service. The client input is sent to the stateless gateway, then relayed on to the stateful service, where it is initially persisted in a ReliableQueue . In parallel, there's an infinite while loop running inside the RunAsync method pulling items off of the queue and processing them, with the results being stored in a ReliableDictionary . This pattern is useful when you want to quickly ACK back to the client that you received (and safely persisted!) its input and can afford to perform the real processing asynchronously.

Note that if you intend to store your state in a ReliableQueue / ReliableDictionary , there probably isn't much value in doing the processing using a stateless actor. You'd be better off to just move that logic into a type within the stateful service and do the processing there as you will likely save yourself a network hop back and forth.

If I understand your question correctly, you are just searching for a way to communicate from a Stateless Service to an Actor. If so, you don't need a reliable queue - just make a call with an ActorProxy instance:

ActorId actorId = new ActorId("YourActorId");
string applicationName = "fabric:/YourAppName";
IYourActor actor = ActorProxy.Create<IYourActor>(actorId, applicationName);
await dtoActor.DoWork(new WorkItem());

Service Fabric will route this call for you.

You can have a Stateful Service that will dequeue items from the queue in the RunAsync method (see here for a RunAsync() example).

When you dequeue an item you can communicate with an actor using ActorProxy and ask it to do the work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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