问题
This question is continuation from previous thread. store cancellation tokens in service fabric services
Opened a new thread because answering this question would not be trivial.
To summarize what has been discussed regarding cancel a job / task running in particular service in some partition of service fabric:
Cancellation Token limitation:
Cancellation token works within the service partition and that is the limitation in partition-wise storing the instances, probably the reason why cancellation token is not provided with serializable attributes (Attempt made using ISerializationSurrogate to serialize into byte array and saved into class with DataContract attribute attached and it loses all nested struct data when deserialized back.), therefore reliable dictionary can't be used.
Two distinct use of cancellation tokens in service fabric application:
- Service Fabric provided which innately injected onto methods such as RunAsync(CancellationToken) { forever loop } or used by Web API cancel request handle, which also can be forwarded to custom methods in actor / service per web API calls.
- User generated cancellation tokens need to be managed differently than ones being created by #1 (More explanation on how to manage these tokens belong to the previous thread linked at the top of this thread).
Question belong to this thread:
How do you forward from API request received via multiple partitions end points to the right partition? I guess once request has been forwarded from a Web API end point to the right partition then it seems all make sense because at that point then you should be simply able to call cancellationtokensource.cancel() with stored cancellationtoken in that specific partition, with assumption that cancellationtoken.Cancel() works partition-wise.
来源:https://stackoverflow.com/questions/53050219/forward-the-cancellation-to-the-right-partition