Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for group and topic prefixes #780

Merged
merged 1 commit into from
Mar 5, 2021
Merged

Add support for group and topic prefixes #780

merged 1 commit into from
Mar 5, 2021

Conversation

AndriiLab
Copy link
Collaborator

Problem
We have multiple instances of the app, which deployed to AWS in different VPCs but in the same region. In this scenario, isolation works perfectly except for SNS and SQS, which are shared within the region.

Proposed solution
Add to CapOptions prefixes for topic (TopicNamePrefix ) and group (GroupNamePrefix ) names to make these parameters unique for each application instance. These parameters are optional, and if not defined the behavior will remain unchanged.

@yang-xiaodong
Copy link
Member

Hello,

Thanks for your PR,

Since GroupName is customizable, so I think it is redundant to provide GroupNamePrefix

I think it is reasonable to provide TopicNamePrefix

@roman-bezmen
Copy link
Contributor

@yang-xiaodong At the moment it is a bit fussy overriding the way how the group name constructs. For simple cases like providing prefixes to host multiple instances within the same infrastructure, it would be more pleasant to have a consistent way to set up prefixes for both queues and topics, even if there is an alternative way. What are your concerns?

@yang-xiaodong
Copy link
Member

What I think is that providing more configuration items will complicate the beginner and keep it simple.

Do as you say at present we have the configuration items DefaultGroup and GroupNamePrefix, In fact, the name of DefaultGroup should be rename to GroupName so that users can know what happened.

@@ -34,6 +34,16 @@ public CapOptions()
/// </summary>
public string DefaultGroup { get; set; }
Copy link
Member

Choose a reason for hiding this comment

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

As described in the comments, rename DefaultGroup to GroupName seemed more appropriate

@AndriiLab
Copy link
Collaborator Author

Currently, we configure GroupNamePrefix via overriding method in ConsumerServiceSelector.SetSubscribeAttribute:

    public class PrefixedConsumerServiceSelector : ConsumerServiceSelector
    {
        private readonly string _prefix;

        public PrefixedConsumerServiceSelector(IServiceProvider serviceProvider, string prefix)
            : base(serviceProvider)
        {
            _prefix = prefix;
        }

        protected override void SetSubscribeAttribute(TopicAttribute attribute)
        {
            base.SetSubscribeAttribute(attribute);
            if (!string.IsNullOrEmpty(_prefix))
            {
                attribute.Group = $"{_prefix}.{attribute.Group}";
            }
        }
     }

And then in Startup.cs:

    services.AddCap(c => ...);
    services.TryRemove<IConsumerServiceSelector>();
    services.TryAddSingleton<IConsumerServiceSelector>(s => new PrefixedConsumerServiceSelector(s, "MyPerfix"));

Possibly, I understand this overring incorrectly, but I think there could be a more simple approach just to add prefix like

    services.AddCap(c => {
        c.GroupNamePrefix = "MyGroupPrefix",
        c.TopicNamePrefix = "MyTopicPrefix"
    });

Since GroupNamePrefix and TopicNamePrefix are not required, the application will behave as usual without these parameters. Similar behavior was implemented for suggested DefaultGroup (GroupName)

@AndriiLab
Copy link
Collaborator Author

Dear @yang-xiaodong,
This feature is very important for us since we use CAP in production. If you have any concerns about releasing this feature for global configuration, I can try to implement it only for the AWS provider.

@yang-xiaodong
Copy link
Member

well, I want let you know I will rename options DefaultGroup to GroupName , thanks for your PR

@yang-xiaodong yang-xiaodong merged commit 1d2594d into dotnetcore:master Mar 5, 2021
@yang-xiaodong
Copy link
Member

Preview version 5.0.0-preview-131679580 released to nuget

@AndriiLab
Copy link
Collaborator Author

Thank you very much, @yang-xiaodong!

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.

None yet

3 participants