The right way to call fire-and-forget method on a service-fabric service

590 views Asked by At

I have a method on ServiceA that I need to call from ServiceB. The method takes upwards of 5 minutes to execute and I don't care about its return value. (Output from the method is handled another way)

I have setup my method in IServiceA like this:

[OneWay]
Task LongRunningMethod(int param1);

However that doesn't appear to run, because I am getting System.TimeoutException: This can happen if message is dropped when service is busy or its long running operation and taking more time than configured Operation Timeout.

One choice is to increase the timeout, but it seems that there should be a better way. Is there?

1

There are 1 answers

0
Diego Mendes On BEST ANSWER

For fire and forget or long running operations the best solution is using a message bus as a middle-ware that will handle this dependency between both process.

To do what you want without a middle-ware, your caller would have to worry about many things, like: Timeouts (like in your case), delivery guarantee(confirmation), Service availability, Exceptions and so on.

With the middle-ware the only worry your application logic need is the delivery guarantee, the rest should be handled by the middle-ware and the receiver.

There are many options, like:

  • Azure Service Bus
  • Azure Storage Queue
  • MSMQ
  • Event Hub
  • and so on.

I would not recommend using the SF Communication, Task.Run(), Threads workarounds as many places suggests, because they will just bring you extra work and wont run as smooth as the middle-ware approach.