-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
PublisherClient/SubscriberClient snippets #1663
Conversation
Changes Unknown when pulling 5da936a on jabubake:pubsub_snippets into ** on GoogleCloudPlatform:master**. |
Changes Unknown when pulling 5da936a on jabubake:pubsub_snippets into ** on GoogleCloudPlatform:master**. |
ListTopicsRequest listTopicsRequest = | ||
ListTopicsRequest.newBuilder() | ||
.setProjectWithProjectName(ProjectName.create(projectId)) | ||
.setPageSize(100) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
ListTopicSubscriptionsPagedResponse response = | ||
publisherClient.listTopicSubscriptions(request); | ||
Iterable<String> subscriptions = response.iterateAllElements(); | ||
for (String subscription : subscriptions) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Iterable<String> subscriptions = response.iterateAllElements(); | ||
for (String subscription : subscriptions) { | ||
// do something with the subscription name | ||
} |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
try (PublisherClient publisherClient = PublisherClient.create()) { | ||
TopicName formattedTopicName = TopicName.create(projectId, topicName); | ||
// [START deleteTopic] | ||
publisherClient.deleteTopic(formattedTopicName); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
try { | ||
publisherClient.deleteTopic(TopicName.create(projectId, testTopic)); | ||
} catch (Exception e) { | ||
//do nothing catch clause |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
} | ||
|
||
/** Example of creating a topic. */ | ||
public Topic createTopic(String myTopic) throws Exception { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
} | ||
|
||
/** Example of creating a pull subscription for a topic. */ | ||
public Subscription createSubscription(String topic, String mySubscription) throws Exception { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
private static void deleteTestTopics(String projectId, String[] testTopics) throws Exception { | ||
try (PublisherClient publisherClient = PublisherClient.create()) { | ||
for (String name : testTopics) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
LGTM after merge conflicts are resolved - @lesv , do you want to take a look too? |
Changes Unknown when pulling e053154 on jabubake:pubsub_snippets into ** on GoogleCloudPlatform:master**. |
Changes Unknown when pulling c701671 on jabubake:pubsub_snippets into ** on GoogleCloudPlatform:master**. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should run the python script (utilities/add_snippets_to_file.py
) that merges your snippets into the code and see how it works. (also include the merged code with the PR).
I'm flagging many of the projectId's, I'm totally happy either way. Part of me would prefer it, but I also understand not doing it. (and the code gets messier).
Apparently all I really care about tonight is the "ARR."; but we also need to have run the script.
@@ -0,0 +1,164 @@ | |||
/* | |||
* Copyright 2017 Google Inc. All Rights Reserved. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@@ -0,0 +1,209 @@ | |||
/* | |||
* Copyright 2017 Google Inc. All Rights Reserved. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
// [START listTopics] | ||
ListTopicsRequest listTopicsRequest = | ||
ListTopicsRequest.newBuilder() | ||
.setProjectWithProjectName(ProjectName.create(projectId)) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
public Policy getTopicPolicy(String topicId) throws Exception { | ||
try (PublisherClient publisherClient = PublisherClient.create()) { | ||
// [START getTopicPolicy] | ||
TopicName topicName = TopicName.create(projectId, topicId); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
// [START testTopicPermissions] | ||
List<String> permissions = new LinkedList<>(); | ||
permissions.add("pubsub.topics.get"); | ||
TopicName topicName = TopicName.create(projectId, topicId); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@@ -0,0 +1,182 @@ | |||
/* | |||
* Copyright 2017 Google Inc. All Rights Reserved. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
retrieving default project id : moving to snippet class
Changes Unknown when pulling 3238290 on jabubake:pubsub_snippets into ** on GoogleCloudPlatform:master**. |
Well, I'm happy, but Travis is not. :( |
The logs show errors in pubsub tests, but not related to the snippets. I've restarted Travis build. |
I can't see a button to restart it. The AppVeyor UI isn't terribly intuitive... |
adding snippets for PublisherClient, SubscriberClient
chore: remove check for flatten plugin We have had the check for the flatten-maven-plugin in each Cloud Java client repository. However, the behavior of the plugin has been stable and its not each repository's responsibility to assert the plugin's behavior. A new check is going to be added at the googleapis/java-shared-config repository to assert the plugin's behavior when we upgrade its version. Source-Link: googleapis/synthtool@9266ddc Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-java:latest@sha256:ae72564aa9c368b9ccd96f4af21f87889fd83b9e60635b80844deb5a2ccd08aa Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
chore: remove check for flatten plugin We have had the check for the flatten-maven-plugin in each Cloud Java client repository. However, the behavior of the plugin has been stable and its not each repository's responsibility to assert the plugin's behavior. A new check is going to be added at the googleapis/java-shared-config repository to assert the plugin's behavior when we upgrade its version. Source-Link: https://togithub.com/googleapis/synthtool/commit/9266ddc3b17fc15f34d2fb88ce8c5f1a4bfe64b0 Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-java:latest@sha256:ae72564aa9c368b9ccd96f4af21f87889fd83b9e60635b80844deb5a2ccd08aa
chore: remove check for flatten plugin We have had the check for the flatten-maven-plugin in each Cloud Java client repository. However, the behavior of the plugin has been stable and its not each repository's responsibility to assert the plugin's behavior. A new check is going to be added at the googleapis/java-shared-config repository to assert the plugin's behavior when we upgrade its version. Source-Link: https://togithub.com/googleapis/synthtool/commit/9266ddc3b17fc15f34d2fb88ce8c5f1a4bfe64b0 Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-java:latest@sha256:ae72564aa9c368b9ccd96f4af21f87889fd83b9e60635b80844deb5a2ccd08aa
Snippets supporting How-to guides @ https://cloud.google.com/pubsub/docs/how-to
FYI, @pongad