5

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

Community
  • 1
  • 1
Kulpemovitz
  • 531
  • 1
  • 9
  • 23

3 Answers3

4

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.

Sean McKenna
  • 3,706
  • 19
  • 19
  • My Actor are doing long jobs, they need to pull information from various sources and do some web scrapping from out clients website. Do you still think putting all this thing in a stateful service might be wiser? – Kulpemovitz Jan 14 '16 at 10:11
  • Yep. There's no reason you can't do long-running work in a thread within the stateful service. Also, there can be some gotchas with the actor model's single-threaded nature when you need your actors to do a bunch of external interactions as it sounds like you do. Generally, actors work best if you limit the amount that they need to call out. We are working on some documentation to make this guidance clearer. – Sean McKenna Jan 14 '16 at 19:14
  • @SeanMcKenna-MSFT the link is dead. Could you update it to the correct url? – Roman Ganz Feb 13 '18 at 13:50
  • @RomanGanz: Take a look here: https://azure.microsoft.com/en-us/resources/samples/service-fabric-dotnet-getting-started/ - we updated the repo with a new sample, but the WordCount sample is in the same repo, but the app is in the "classic" branch: https://github.com/Azure-Samples/service-fabric-dotnet-getting-started/tree/classic/Services/WordCount – Mikkel Mørk Hegnhøj Feb 23 '18 at 23:07
1

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.

Mikhail Shilkov
  • 34,128
  • 3
  • 68
  • 107
1

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.

charisk
  • 3,190
  • 2
  • 24
  • 18