Skip to content

Add cancellation token support to Subscribers#912

Merged
yang-xiaodong merged 4 commits intodotnetcore:masterfrom
matt-psaltis:feature/cancellationTokens
Jun 28, 2021
Merged

Add cancellation token support to Subscribers#912
yang-xiaodong merged 4 commits intodotnetcore:masterfrom
matt-psaltis:feature/cancellationTokens

Conversation

@matt-psaltis
Copy link
Contributor

Relates to: #907

Wanted to get your thoughts on this currently. I've added an example integration test as well as some additional unit tests for the subscriber resolution when cancellation tokens are in play. There's a couple of signature changes that would be potentially breaking so I'd like to get your thoughts on those please?

@matt-psaltis matt-psaltis force-pushed the feature/cancellationTokens branch from 3573ddc to 81120de Compare June 21, 2021 03:32
@matt-psaltis matt-psaltis force-pushed the feature/cancellationTokens branch from 81120de to e7ad0d4 Compare June 21, 2021 04:02
Copy link
Member

@yang-xiaodong yang-xiaodong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @matt-psaltis,

Thank you very much for your PR, I reviewed and found two issues, please confirm it


public AsyncLocal<ICapTransaction> Transaction { get; }

public void Start(CancellationToken stoppingToken)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be removed? I think the prevent Start method in CapPublisher looks a bit strange? and the method is not called

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does look strange on the publisher side agreed. I need to come back to this and reassess. It didn't quite fit the current structure.


var methodInfo = context.ConsumerDescriptor.MethodInfo;
var reflectedType = methodInfo.ReflectedType.Name;
var reflectedType = methodInfo.ReflectedType.TypeHandle.Value;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we use ReflectedType.TypeHandle.Value, as described in #908, do we still need "{methodInfo.Module.Name}_{reflectedType}_{methodInfo.MetadataToken}" to ensure that the key is unique?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey got slammed with work this week. I was trying to keep the PRs separate so I was planning to do this once I had some test coverage in place in a subsequent PR. happy to amalgamate tho if that's easier.

@yang-xiaodong
Copy link
Member

Hello @matt-psaltis , Any further response on this PR?

@matt-psaltis
Copy link
Contributor Author

Hello @matt-psaltis , Any further response on this PR?

@yang-xiaodong I've pushed some updates and additional tests for the cache key problem from #908 Would love your thoughts when you can please.

@yang-xiaodong
Copy link
Member

yang-xiaodong commented Jun 27, 2021

Hello @matt-psaltis ,

Since the object that implements IProcessingServer will be started in Bootstrapper class so what do you think about making the IDispatcher inherit the IProcessingServer ?

https://github.com/dotnetcore/CAP/blob/master/src/DotNetCore.CAP/CAP.ServiceCollectionExtensions.cs#L47
https://github.com/dotnetcore/CAP/blob/master/src/DotNetCore.CAP/Internal/IBootstrapper.Default.cs#L33

@matt-psaltis
Copy link
Contributor Author

Hello @matt-psaltis ,

Since the object that implements IProcessingServer will be started in Bootstrapper class so what do you think about making the IDispatcher inherit the IProcessingServer ?

https://github.com/dotnetcore/CAP/blob/master/src/DotNetCore.CAP/CAP.ServiceCollectionExtensions.cs#L47
https://github.com/dotnetcore/CAP/blob/master/src/DotNetCore.CAP/Internal/IBootstrapper.Default.cs#L33

Awesome! I actually did go down that path today. I removed it because I wasn't sure on the intention of a "processing server" as a concept vs the dispatcher. I'll consolidate, it was cleaner that way, thanks.

@matt-psaltis
Copy link
Contributor Author

Hello @matt-psaltis ,

Since the object that implements IProcessingServer will be started in Bootstrapper class so what do you think about making the IDispatcher inherit the IProcessingServer ?

https://github.com/dotnetcore/CAP/blob/master/src/DotNetCore.CAP/CAP.ServiceCollectionExtensions.cs#L47
https://github.com/dotnetcore/CAP/blob/master/src/DotNetCore.CAP/Internal/IBootstrapper.Default.cs#L33

I remember why I unwound this now, it was because of the number of places that directly reference the IDispatcher.

I could register it as an IProcessingServer using something like this:

            services.TryAddEnumerable(ServiceDescriptor.Singleton<IProcessingServer, IDispatcher>(sp =>
                sp.GetRequiredService<IDispatcher>()));

Need to make sure we only get a single instance created so by registering it as an IProcessing Server as well as IDispatcher, we need to use a factory pattern like above to reference the same IDispatcher instance. Does that make sense?
Happy to do it this way - I'm just being overly cautious of making drastic changes like I would with my own repositories :D

@yang-xiaodong
Copy link
Member

It’s a good idea to use a factory to resolve, just do it

@matt-psaltis
Copy link
Contributor Author

It’s a good idea to use a factory to resolve, just do it

Done.

@yang-xiaodong
Copy link
Member

Looks good, thanks very much

@yang-xiaodong yang-xiaodong merged commit 2069014 into dotnetcore:master Jun 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants