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

PushConfig: Unable to set attributes for PushConfig while creating a new subscription. #1846

Open
NimitSharma opened this issue Dec 8, 2023 · 1 comment
Assignees
Labels
api: pubsub Issues related to the googleapis/java-pubsub API. priority: p2 Moderately-important priority. Fix may not be included in next release.

Comments

@NimitSharma
Copy link

NimitSharma commented Dec 8, 2023

Thanks for stopping by to let us know something could be better!

PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response.

Please run down the following list and make sure you've tried the usual "quick fixes":

If you are still having issues, please include as much information as possible:

Environment details

  1. Specify the API at the beginning of the title. For example, "BigQuery: ...").
    General, Core, and Other are also allowed as types
  2. OS type and version: All
  3. Java version: JDK 8/11/17
  4. version(s): 1.125.13 or earlier

Steps to reproduce

  1. Create a topic
  2. Create a subscription with Push as delivery type and configure custom attributes while creating the subscription
  3. Get the subscription object
  4. Call this API subscription.getPushConfig().getAttributesMap() on subscription object.

Code example

/*
 * Copyright 2016 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package pubsub;

// [START pubsub_create_push_subscription]

import com.google.cloud.pubsub.v1.SubscriptionAdminClient;
import com.google.pubsub.v1.PushConfig;
import com.google.pubsub.v1.Subscription;
import com.google.pubsub.v1.SubscriptionName;
import com.google.pubsub.v1.TopicName;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class CreatePushSubscriptionExample {
  public static void main(String... args) throws Exception {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "project-id";
    String subscriptionId = "sub-test";
    String topicId = "topic-test";
    String pushEndpoint = "https://my-test-project.appspot.com/push";

    createPushSubscriptionExample(projectId, subscriptionId, topicId, pushEndpoint);
  }

  public static void createPushSubscriptionExample(
      String projectId, String subscriptionId, String topicId, String pushEndpoint)
      throws IOException {
    try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
      TopicName topicName = TopicName.of(projectId, topicId);
      SubscriptionName subscriptionName = SubscriptionName.of(projectId, subscriptionId);

      Map<String, String> attributes = new HashMap<>();
      attributes.put("test1", "v1");
      attributes.put("test2", "v2");
      attributes.put("test3", "v3");

      PushConfig pushConfig = PushConfig.newBuilder().setPushEndpoint(pushEndpoint).putAllAttributes(attributes).build();


      // Create a push subscription with default acknowledgement deadline of 10 seconds.
      // Messages not successfully acknowledged within 10 seconds will get resent by the server.
      Subscription subscription =
          subscriptionAdminClient.createSubscription(subscriptionName, topicName, pushConfig, 10);
      System.out.println("Custom attributes: " + subscription.getPushConfig().getAttributesMap());
    }
  }
}
// [END pubsub_create_push_subscription]

Result:
Custom attributes: {x-goog-version=v1}
It must include other attributes as well.

Stack trace

NA since I am getting the proper subscription object but it does not contains custom attributes configured while creating the subscription. It only has a default attribute named "x-goog-version". However, when I try to update the subscription then the custom attributes are coming properly.

External references such as API reference guides

  • ?

Any additional information below

I am getting the proper subscription object but it does not contains custom attributes configured while creating the subscription. It only has a default attribute named "x-goog-version". However, when I try to update the subscription then the custom attributes are coming properly.

Following these steps guarantees the quickest resolution possible.

Thanks!

@product-auto-label product-auto-label bot added the api: pubsub Issues related to the googleapis/java-pubsub API. label Dec 8, 2023
kamalaboulhosn pushed a commit to kamalaboulhosn/java-pubsub that referenced this issue Dec 14, 2023
…p/templates/java_library/.kokoro (googleapis#1846) (googleapis#1842)

build(deps): bump cryptography

Bumps [cryptography](https://github.com/pyca/cryptography) from 41.0.2 to 41.0.3.
- [Changelog](https://github.com/pyca/cryptography/blob/main/CHANGELOG.rst)
- [Commits](pyca/cryptography@41.0.2...41.0.3)

---
updated-dependencies:
- dependency-name: cryptography
  dependency-type: indirect
...






Source-Link: googleapis/synthtool@bfb4e63
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-java:latest@sha256:11d59eabd49dc088f8339fb96e9da79ba4b3a73b3d49a8a4e0263e91edd053ba

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Burke Davison <40617934+burkedavison@users.noreply.github.com>
Co-authored-by: Jeffrey Rennie <rennie@google.com>
Co-authored-by: Alice <65933803+alicejli@users.noreply.github.com>
@maitrimangal maitrimangal added the priority: p2 Moderately-important priority. Fix may not be included in next release. label Dec 18, 2023
@maitrimangal
Copy link
Member

Hi thank you for your question. I believe that currently the only supported push-endpoint attribute is x-goog-version, which you can use to change the format of the push message.

Are you trying to set push-endpoint attribute or something else?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: pubsub Issues related to the googleapis/java-pubsub API. priority: p2 Moderately-important priority. Fix may not be included in next release.
Projects
None yet
Development

No branches or pull requests

3 participants