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

PublisherClient/SubscriberClient snippets #1663

Merged
merged 11 commits into from
Mar 6, 2017

Conversation

jabubake
Copy link
Contributor

Snippets supporting How-to guides @ https://cloud.google.com/pubsub/docs/how-to

FYI, @pongad

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Feb 25, 2017
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 5da936a on jabubake:pubsub_snippets into ** on GoogleCloudPlatform:master**.

@coveralls
Copy link

Coverage Status

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.

This comment was marked as spam.

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.

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.

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.

This comment was marked as spam.

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.

}

/** Example of creating a topic. */
public Topic createTopic(String myTopic) throws Exception {

This comment was marked as spam.

This comment was marked as spam.

}

/** 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.


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.

@garrettjonesgoogle
Copy link
Member

LGTM after merge conflicts are resolved - @lesv , do you want to take a look too?

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling e053154 on jabubake:pubsub_snippets into ** on GoogleCloudPlatform:master**.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling c701671 on jabubake:pubsub_snippets into ** on GoogleCloudPlatform:master**.

Copy link
Contributor

@lesv lesv left a 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.

@@ -0,0 +1,209 @@
/*
* Copyright 2017 Google Inc. All Rights Reserved.

This comment was marked as spam.

// [START listTopics]
ListTopicsRequest listTopicsRequest =
ListTopicsRequest.newBuilder()
.setProjectWithProjectName(ProjectName.create(projectId))

This comment was marked as spam.

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.

// [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.

@@ -0,0 +1,182 @@
/*
* Copyright 2017 Google Inc. All Rights Reserved.

This comment was marked as spam.

This comment was marked as spam.

retrieving default project id : moving to snippet class
@coveralls
Copy link

coveralls commented Mar 2, 2017

Coverage Status

Changes Unknown when pulling 3238290 on jabubake:pubsub_snippets into ** on GoogleCloudPlatform:master**.

@lesv
Copy link
Contributor

lesv commented Mar 2, 2017

Well, I'm happy, but Travis is not. :(

@jabubake
Copy link
Contributor Author

jabubake commented Mar 3, 2017

The logs show errors in pubsub tests, but not related to the snippets. I've restarted Travis build.
@garrettjonesgoogle, @pongad : is there an easy way to restart the appveyor build ? Appveyor logs show the pubsub package test failures, fyi.

@garrettjonesgoogle
Copy link
Member

I can't see a button to restart it. The AppVeyor UI isn't terribly intuitive...

@jabubake jabubake merged commit d21491b into googleapis:master Mar 6, 2017
@jabubake jabubake deleted the pubsub_snippets branch March 6, 2017 17:36
rybosome pushed a commit to rybosome/google-cloud-java that referenced this pull request Mar 9, 2017
adding snippets for PublisherClient, SubscriberClient
github-actions bot pushed a commit that referenced this pull request Oct 24, 2022
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>
suztomo pushed a commit that referenced this pull request Feb 1, 2023
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://github.com/googleapis/synthtool/commit/9266ddc3b17fc15f34d2fb88ce8c5f1a4bfe64b0
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-java:latest@sha256:ae72564aa9c368b9ccd96f4af21f87889fd83b9e60635b80844deb5a2ccd08aa
suztomo pushed a commit that referenced this pull request Feb 1, 2023
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://github.com/googleapis/synthtool/commit/9266ddc3b17fc15f34d2fb88ce8c5f1a4bfe64b0
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-java:latest@sha256:ae72564aa9c368b9ccd96f4af21f87889fd83b9e60635b80844deb5a2ccd08aa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants