Skip to content

Commit

Permalink
docs: Update samples for v0.3.0 (#235)
Browse files Browse the repository at this point in the history
* docs: Update samples for v0.3.0

* fix: Fix build error.

* Bump readme version
  • Loading branch information
dpcollins-google committed Sep 8, 2020
1 parent e8be2b9 commit 61b1981
Show file tree
Hide file tree
Showing 20 changed files with 137 additions and 152 deletions.
48 changes: 24 additions & 24 deletions .readme-partials.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ custom_content: |
Integer partitions = 1;
TopicPath topicPath =
TopicPaths.newBuilder()
.setProjectNumber(ProjectNumber.of(projectNumber))
.setZone(CloudZone.of(CloudRegion.of(cloudRegion), zoneId))
.setTopicName(TopicName.of(topicId))
TopicPath.newBuilder()
.setProject(ProjectNumber.of(projectNumber))
.setLocation(CloudZone.of(CloudRegion.of(cloudRegion), zoneId))
.setName(TopicName.of(topicId))
.build();
Topic topic =
Expand All @@ -45,7 +45,7 @@ custom_content: |
// beyond this value, older messages will be dropped to make room for
// newer ones, regardless of the value of `period`.
.setPerPartitionBytes(30 * 1024 * 1024 * 1024L))
.setName(topicPath.value())
.setName(topicPath.toString())
.build();
AdminClientSettings adminClientSettings =
Expand Down Expand Up @@ -81,10 +81,10 @@ custom_content: |
int messageCount = 100;
TopicPath topicPath =
TopicPaths.newBuilder()
.setProjectNumber(ProjectNumber.of(projectNumber))
.setZone(CloudZone.of(CloudRegion.of(cloudRegion), zoneId))
.setTopicName(TopicName.of(topicId))
TopicPath.newBuilder()
.setProject(ProjectNumber.of(projectNumber))
.setLocation(CloudZone.of(CloudRegion.of(cloudRegion), zoneId))
.setName(TopicName.of(topicId))
.build();
Publisher publisher = null;
List<ApiFuture<String>> futures = new ArrayList<>();
Expand Down Expand Up @@ -149,17 +149,17 @@ custom_content: |
String subscriptionId = "your-subscription-id";
TopicPath topicPath =
TopicPaths.newBuilder()
.setProjectNumber(ProjectNumber.of(projectNumber))
.setZone(CloudZone.of(CloudRegion.of(cloudRegion), zoneId))
.setTopicName(TopicName.of(topicId))
TopicPath.newBuilder()
.setProject(ProjectNumber.of(projectNumber))
.setLocation(CloudZone.of(CloudRegion.of(cloudRegion), zoneId))
.setName(TopicName.of(topicId))
.build();
SubscriptionPath subscriptionPath =
SubscriptionPaths.newBuilder()
.setZone(CloudZone.of(CloudRegion.of(cloudRegion), zoneId))
.setProjectNumber(ProjectNumber.of(projectNumber))
.setSubscriptionName(SubscriptionName.of(subscriptionId))
SubscriptionPath.newBuilder()
.setLocation(CloudZone.of(CloudRegion.of(cloudRegion), zoneId))
.setProject(ProjectNumber.of(projectNumber))
.setName(SubscriptionName.of(subscriptionId))
.build();
Subscription subscription =
Expand All @@ -172,8 +172,8 @@ custom_content: |
// may be a gap at that offset.
DeliveryConfig.newBuilder()
.setDeliveryRequirement(DeliveryRequirement.DELIVER_IMMEDIATELY))
.setName(subscriptionPath.value())
.setTopic(topicPath.value())
.setName(subscriptionPath.toString())
.setTopic(topicPath.toString())
.build();
AdminClientSettings adminClientSettings =
Expand Down Expand Up @@ -212,10 +212,10 @@ custom_content: |
String subscriptionId = "your-subscription-id";
SubscriptionPath subscriptionPath =
SubscriptionPaths.newBuilder()
.setZone(CloudZone.of(CloudRegion.of(cloudRegion), zoneId))
.setProjectNumber(ProjectNumber.of(projectNumber))
.setSubscriptionName(SubscriptionName.of(subscriptionId))
SubscriptionPath.newBuilder()
.setLocation(CloudZone.of(CloudRegion.of(cloudRegion), zoneId))
.setProject(ProjectNumber.of(projectNumber))
.setName(SubscriptionName.of(subscriptionId))
.build();
// The message stream is paused based on the maximum size or number of messages that the
Expand Down Expand Up @@ -248,7 +248,7 @@ custom_content: |
// Start the subscriber. Upon successful starting, its state will become RUNNING.
subscriber.startAsync().awaitRunning();
System.out.println("Listening to messages on " + subscriptionPath.value() + "...");
System.out.println("Listening to messages on " + subscriptionPath.toString() + "...");
try {
System.out.println(subscriber.state());
Expand Down
50 changes: 25 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ If you are using Maven, add this to your pom.xml file:
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-pubsublite</artifactId>
<version>0.2.0</version>
<version>0.3.0</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
Expand Down Expand Up @@ -108,10 +108,10 @@ String topicId = "your-topic-id";
Integer partitions = 1;

TopicPath topicPath =
TopicPaths.newBuilder()
.setProjectNumber(ProjectNumber.of(projectNumber))
.setZone(CloudZone.of(CloudRegion.of(cloudRegion), zoneId))
.setTopicName(TopicName.of(topicId))
TopicPath.newBuilder()
.setProject(ProjectNumber.of(projectNumber))
.setLocation(CloudZone.of(CloudRegion.of(cloudRegion), zoneId))
.setName(TopicName.of(topicId))
.build();

Topic topic =
Expand All @@ -132,7 +132,7 @@ Topic topic =
// beyond this value, older messages will be dropped to make room for
// newer ones, regardless of the value of `period`.
.setPerPartitionBytes(30 * 1024 * 1024 * 1024L))
.setName(topicPath.value())
.setName(topicPath.toString())
.build();

AdminClientSettings adminClientSettings =
Expand Down Expand Up @@ -168,10 +168,10 @@ String topicId = "your-topic-id";
int messageCount = 100;

TopicPath topicPath =
TopicPaths.newBuilder()
.setProjectNumber(ProjectNumber.of(projectNumber))
.setZone(CloudZone.of(CloudRegion.of(cloudRegion), zoneId))
.setTopicName(TopicName.of(topicId))
TopicPath.newBuilder()
.setProject(ProjectNumber.of(projectNumber))
.setLocation(CloudZone.of(CloudRegion.of(cloudRegion), zoneId))
.setName(TopicName.of(topicId))
.build();
Publisher publisher = null;
List<ApiFuture<String>> futures = new ArrayList<>();
Expand Down Expand Up @@ -236,17 +236,17 @@ String topicId = "your-topic-id";
String subscriptionId = "your-subscription-id";

TopicPath topicPath =
TopicPaths.newBuilder()
.setProjectNumber(ProjectNumber.of(projectNumber))
.setZone(CloudZone.of(CloudRegion.of(cloudRegion), zoneId))
.setTopicName(TopicName.of(topicId))
TopicPath.newBuilder()
.setProject(ProjectNumber.of(projectNumber))
.setLocation(CloudZone.of(CloudRegion.of(cloudRegion), zoneId))
.setName(TopicName.of(topicId))
.build();

SubscriptionPath subscriptionPath =
SubscriptionPaths.newBuilder()
.setZone(CloudZone.of(CloudRegion.of(cloudRegion), zoneId))
.setProjectNumber(ProjectNumber.of(projectNumber))
.setSubscriptionName(SubscriptionName.of(subscriptionId))
SubscriptionPath.newBuilder()
.setLocation(CloudZone.of(CloudRegion.of(cloudRegion), zoneId))
.setProject(ProjectNumber.of(projectNumber))
.setName(SubscriptionName.of(subscriptionId))
.build();

Subscription subscription =
Expand All @@ -259,8 +259,8 @@ Subscription subscription =
// may be a gap at that offset.
DeliveryConfig.newBuilder()
.setDeliveryRequirement(DeliveryRequirement.DELIVER_IMMEDIATELY))
.setName(subscriptionPath.value())
.setTopic(topicPath.value())
.setName(subscriptionPath.toString())
.setTopic(topicPath.toString())
.build();

AdminClientSettings adminClientSettings =
Expand Down Expand Up @@ -299,10 +299,10 @@ String topicId = "your-topic-id";
String subscriptionId = "your-subscription-id";

SubscriptionPath subscriptionPath =
SubscriptionPaths.newBuilder()
.setZone(CloudZone.of(CloudRegion.of(cloudRegion), zoneId))
.setProjectNumber(ProjectNumber.of(projectNumber))
.setSubscriptionName(SubscriptionName.of(subscriptionId))
SubscriptionPath.newBuilder()
.setLocation(CloudZone.of(CloudRegion.of(cloudRegion), zoneId))
.setProject(ProjectNumber.of(projectNumber))
.setName(SubscriptionName.of(subscriptionId))
.build();

// The message stream is paused based on the maximum size or number of messages that the
Expand Down Expand Up @@ -335,7 +335,7 @@ Subscriber subscriber = Subscriber.create(subscriberSettings);
// Start the subscriber. Upon successful starting, its state will become RUNNING.
subscriber.startAsync().awaitRunning();

System.out.println("Listening to messages on " + subscriptionPath.value() + "...");
System.out.println("Listening to messages on " + subscriptionPath.toString() + "...");

try {
System.out.println(subscriber.state());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,12 @@ public ApiFuture<Long> getTopicPartitionCount(TopicPath path) {
@Override
public ApiFuture<List<Topic>> listTopics(LocationPath path) {
return RetryingExecutorUtil.runWithRetries(
() -> stub.listTopics(
ListTopicsRequest.newBuilder()
.setParent(ProjectLookupUtils.toCannonical(path).toString())
.build())
.getTopicsList(),
() ->
stub.listTopics(
ListTopicsRequest.newBuilder()
.setParent(ProjectLookupUtils.toCannonical(path).toString())
.build())
.getTopicsList(),
listTopicsRetryingExecutor);
}

Expand Down Expand Up @@ -226,11 +227,12 @@ public ApiFuture<Subscription> getSubscription(SubscriptionPath path) {
@Override
public ApiFuture<List<Subscription>> listSubscriptions(LocationPath path) {
return RetryingExecutorUtil.runWithRetries(
() -> stub.listSubscriptions(
ListSubscriptionsRequest.newBuilder()
.setParent(ProjectLookupUtils.toCannonical(path).toString())
.build())
.getSubscriptionsList(),
() ->
stub.listSubscriptions(
ListSubscriptionsRequest.newBuilder()
.setParent(ProjectLookupUtils.toCannonical(path).toString())
.build())
.getSubscriptionsList(),
listSubscriptionsRetryingExecutor);
}

Expand Down
2 changes: 1 addition & 1 deletion samples/snippets/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-pubsublite</artifactId>
<version>0.2.0</version>
<version>0.3.0</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@
import com.google.cloud.pubsublite.ProjectNumber;
import com.google.cloud.pubsublite.SubscriptionName;
import com.google.cloud.pubsublite.SubscriptionPath;
import com.google.cloud.pubsublite.SubscriptionPaths;
import com.google.cloud.pubsublite.TopicName;
import com.google.cloud.pubsublite.TopicPath;
import com.google.cloud.pubsublite.TopicPaths;
import com.google.cloud.pubsublite.proto.Subscription;
import com.google.cloud.pubsublite.proto.Subscription.DeliveryConfig;
import com.google.cloud.pubsublite.proto.Subscription.DeliveryConfig.DeliveryRequirement;
Expand All @@ -50,17 +48,17 @@ public static void createSubscriptionExample(
throws Exception {

TopicPath topicPath =
TopicPaths.newBuilder()
.setProjectNumber(ProjectNumber.of(projectNumber))
.setZone(CloudZone.of(CloudRegion.of(cloudRegion), zoneId))
.setTopicName(TopicName.of(topicId))
TopicPath.newBuilder()
.setProject(ProjectNumber.of(projectNumber))
.setLocation(CloudZone.of(CloudRegion.of(cloudRegion), zoneId))
.setName(TopicName.of(topicId))
.build();

SubscriptionPath subscriptionPath =
SubscriptionPaths.newBuilder()
.setZone(CloudZone.of(CloudRegion.of(cloudRegion), zoneId))
.setProjectNumber(ProjectNumber.of(projectNumber))
.setSubscriptionName(SubscriptionName.of(subscriptionId))
SubscriptionPath.newBuilder()
.setLocation(CloudZone.of(CloudRegion.of(cloudRegion), zoneId))
.setProject(ProjectNumber.of(projectNumber))
.setName(SubscriptionName.of(subscriptionId))
.build();

Subscription subscription =
Expand All @@ -73,8 +71,8 @@ public static void createSubscriptionExample(
// may be a gap at that offset.
DeliveryConfig.newBuilder()
.setDeliveryRequirement(DeliveryRequirement.DELIVER_IMMEDIATELY))
.setName(subscriptionPath.value())
.setTopic(topicPath.value())
.setName(subscriptionPath.toString())
.setTopic(topicPath.toString())
.build();

AdminClientSettings adminClientSettings =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.google.cloud.pubsublite.ProjectNumber;
import com.google.cloud.pubsublite.TopicName;
import com.google.cloud.pubsublite.TopicPath;
import com.google.cloud.pubsublite.TopicPaths;
import com.google.cloud.pubsublite.proto.Topic;
import com.google.cloud.pubsublite.proto.Topic.PartitionConfig;
import com.google.cloud.pubsublite.proto.Topic.RetentionConfig;
Expand All @@ -48,10 +47,10 @@ public static void createTopicExample(
throws Exception {

TopicPath topicPath =
TopicPaths.newBuilder()
.setProjectNumber(ProjectNumber.of(projectNumber))
.setZone(CloudZone.of(CloudRegion.of(cloudRegion), zoneId))
.setTopicName(TopicName.of(topicId))
TopicPath.newBuilder()
.setProject(ProjectNumber.of(projectNumber))
.setLocation(CloudZone.of(CloudRegion.of(cloudRegion), zoneId))
.setName(TopicName.of(topicId))
.build();

Topic topic =
Expand All @@ -72,7 +71,7 @@ public static void createTopicExample(
// beyond this value, older messages will be dropped to make room for
// newer ones, regardless of the value of `period`.
.setPerPartitionBytes(30 * 1024 * 1024 * 1024L))
.setName(topicPath.value())
.setName(topicPath.toString())
.build();

AdminClientSettings adminClientSettings =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.google.cloud.pubsublite.ProjectNumber;
import com.google.cloud.pubsublite.SubscriptionName;
import com.google.cloud.pubsublite.SubscriptionPath;
import com.google.cloud.pubsublite.SubscriptionPaths;

public class DeleteSubscriptionExample {

Expand All @@ -43,18 +42,18 @@ public static void deleteSubscriptionExample(
String cloudRegion, char zoneId, long projectNumber, String subscriptionId) throws Exception {

SubscriptionPath subscriptionPath =
SubscriptionPaths.newBuilder()
.setZone(CloudZone.of(CloudRegion.of(cloudRegion), zoneId))
.setProjectNumber(ProjectNumber.of(projectNumber))
.setSubscriptionName(SubscriptionName.of(subscriptionId))
SubscriptionPath.newBuilder()
.setLocation(CloudZone.of(CloudRegion.of(cloudRegion), zoneId))
.setProject(ProjectNumber.of(projectNumber))
.setName(SubscriptionName.of(subscriptionId))
.build();

AdminClientSettings adminClientSettings =
AdminClientSettings.newBuilder().setRegion(CloudRegion.of(cloudRegion)).build();

try (AdminClient adminClient = AdminClient.create(adminClientSettings)) {
adminClient.deleteSubscription(subscriptionPath).get();
System.out.println(subscriptionPath.value() + " deleted successfully.");
System.out.println(subscriptionPath.toString() + " deleted successfully.");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.google.cloud.pubsublite.ProjectNumber;
import com.google.cloud.pubsublite.TopicName;
import com.google.cloud.pubsublite.TopicPath;
import com.google.cloud.pubsublite.TopicPaths;

public class DeleteTopicExample {

Expand All @@ -42,18 +41,18 @@ public static void main(String... args) throws Exception {
public static void deleteTopicExample(
String cloudRegion, char zoneId, long projectNumber, String topicId) throws Exception {
TopicPath topicPath =
TopicPaths.newBuilder()
.setProjectNumber(ProjectNumber.of(projectNumber))
.setZone(CloudZone.of(CloudRegion.of(cloudRegion), zoneId))
.setTopicName(TopicName.of(topicId))
TopicPath.newBuilder()
.setProject(ProjectNumber.of(projectNumber))
.setLocation(CloudZone.of(CloudRegion.of(cloudRegion), zoneId))
.setName(TopicName.of(topicId))
.build();

AdminClientSettings adminClientSettings =
AdminClientSettings.newBuilder().setRegion(CloudRegion.of(cloudRegion)).build();

try (AdminClient adminClient = AdminClient.create(adminClientSettings)) {
adminClient.deleteTopic(topicPath).get();
System.out.println(topicPath.value() + " deleted successfully.");
System.out.println(topicPath.toString() + " deleted successfully.");
}
}
} // [END pubsublite_delete_topic]
Loading

0 comments on commit 61b1981

Please sign in to comment.