spring-attic / spring-cloud-gcp

Integration for Google Cloud Platform APIs with Spring
Apache License 2.0
704 stars 696 forks source link

Fix subscription name base on topic name #2642

Closed abelmatos closed 3 years ago

abelmatos commented 3 years ago

ATTENTION

Please file all new issues in our new repo: https://github.com/GoogleCloudPlatform/spring-cloud-gcp/issues/new/choose. Issued filed in this repo should only be bug reports for Spring Cloud GCP 1.x (corresponding to Spring Cloud Hoxton and below).


Describe the bug Please provide details of the problem, including the version of Spring Cloud that you are using. Topic in project B Subscription on project A App running on project A using Subscription on project A.

using full topic name projects//topics/ I'm not able to use the Subscription on project A .

// Use <topicName>.<group> as subscription name
            subscriptionName = topicName + "." + group;

projects/<project-id>/topics/<topic-name>.<group> is not a valid subscription name to be created

Sample If possible, please provide a test case or sample application that reproduces the problem. This makes it much easier for us to diagnose the problem and to verify that we have fixed it.

@Override
    public ConsumerDestination provisionConsumerDestination(String topicName, String group,
            ExtendedConsumerProperties<PubSubConsumerProperties> properties)
            throws ProvisioningException {
                // this will work with a topicName like projects/<project-id>/topics/<topic-name>
        Topic topic = makeSureTopicExists(topicName, properties.getExtension().isAutoCreateResources());

        String subscriptionName;
        Subscription subscription;
        if (StringUtils.hasText(group)) {
            // Use <topicName>.<group> as subscription name
                        // FIX sugestion 
                        // subscriptionName = (TopicName.isParsableFrom(topicName) ?  TopicName.parse(topicName).getTopic() : topicName) + "." + group; 
            subscriptionName = topicName  + "." + group; 
            subscription = this.pubSubAdmin.getSubscription(subscriptionName);
        }
        else {
            // Generate anonymous random group since one wasn't provided
            subscriptionName = "anonymous." + topicName + "." + UUID.randomUUID().toString();
            subscription = this.pubSubAdmin.createSubscription(subscriptionName, topicName);
            this.anonymousGroupSubscriptionNames.add(subscriptionName);
        }

https://github.com/spring-cloud/spring-cloud-gcp/blob/71ef73ada647939e7f2cfc51b53fc0f07f31fb43/spring-cloud-gcp-pubsub-stream-binder/src/main/java/org/springframework/cloud/gcp/stream/binder/pubsub/provisioning/PubSubChannelProvisioner.java#L80

meltsufin commented 3 years ago

Is this the same issue as https://github.com/GoogleCloudPlatform/spring-cloud-gcp/issues/232? @ttomsu I think we just need to backport that fix.

ttomsu commented 3 years ago

It looks pretty similar.

@abelmatos Would you be willing to upgrade to 2.0? If not, we can backport the fix, but you'd have to wait for the next Hoxton service release. (the good news is we control the release schedule/cadence in the 2.0+ world)

abelmatos commented 3 years ago

thanks for the info about the 2.0. We will try it. meanwhile we find a temporary workaround. feel free to close this issue

meltsufin commented 3 years ago

@ttomsu Any reason not to backport it anyway?

ttomsu commented 3 years ago

I don't think so - opened https://github.com/spring-cloud/spring-cloud-gcp/pull/2647