Skip to content

Commit f5c57c7

Browse files
Fokkopongad
authored andcommitted
---
yaml --- r: 9253 b: refs/heads/spanner-gapic-migration c: bdcdf59 h: refs/heads/master i: 9251: d5ccc55
1 parent 9e3f796 commit f5c57c7

2 files changed

Lines changed: 31 additions & 33 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ refs/tags/v0.35.0: c28951c5f4cc97a1be07900d19df6984115a4bd6
8181
refs/tags/v0.36.0: 6b75c61f73e6827b3ca379bd54f88f750290162f
8282
refs/tags/v0.37.0: db2e142f92601709fdd48db159776f905742e30f
8383
refs/heads/mrschmidt-sizefix: 627a3bfa30bb6f4f76af47b228c38b208dd921e0
84-
refs/heads/spanner-gapic-migration: 54670a8691fb1ff75680580f1400bc2a5375ac9c
84+
refs/heads/spanner-gapic-migration: bdcdf596b14667a92d6fb367483331614c1ce1ef
8585
refs/tags/v0.38.0: c235ee4df5e1248e1769dae3f86a0d7ab7fd8301
8686
refs/tags/v0.39.0: ab231c9d22475242a43d6d9554aa4a3f736dab01
8787
refs/tags/v0.40.0: a1d5b05206cce7734365f1b910396a2c9d6605ec

branches/spanner-gapic-migration/google-cloud-pubsub/README.md

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@ publishers. Add the following imports at the top of your file:
9090

9191
```java
9292
import com.google.cloud.pubsub.v1.TopicAdminClient;
93-
import com.google.pubsub.v1.TopicName;
93+
import com.google.pubsub.v1.ProjectTopicName;
9494
```
9595
Then, to create the topic, use the following code:
9696

9797
```java
98-
TopicName topic = TopicName.create("test-project", "test-topic");
98+
ProjectTopicName topic = ProjectTopicName.of("test-project", "test-topic");
9999
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
100100
topicAdminClient.createTopic(topic);
101101
}
@@ -115,13 +115,13 @@ Then, to publish messages asynchronously, use the following code:
115115
```java
116116
Publisher publisher = null;
117117
try {
118-
publisher = Publisher.defaultBuilder(topic).build();
118+
publisher = Publisher.newBuilder(topic).build();
119119
ByteString data = ByteString.copyFromUtf8("my-message");
120120
PubsubMessage pubsubMessage = PubsubMessage.newBuilder().setData(data).build();
121121
ApiFuture<String> messageIdFuture = publisher.publish(pubsubMessage);
122122
} finally {
123123
if (publisher != null) {
124-
publisher.shutdown();
124+
publisher.shutdown();
125125
}
126126
}
127127
```
@@ -133,14 +133,14 @@ single, specific topic. Add the following imports at the top of your file:
133133
```java
134134
import com.google.cloud.pubsub.v1.SubscriptionAdminClient;
135135
import com.google.pubsub.v1.PushConfig;
136-
import com.google.pubsub.v1.SubscriptionName;
137-
import com.google.pubsub.v1.TopicName;
136+
import com.google.pubsub.v1.ProjectSubscriptionName;
137+
import com.google.pubsub.v1.ProjectTopicName;
138138
```
139139
Then, to create the subscription, use the following code:
140140

141141
```java
142-
TopicName topic = TopicName.create("test-project", "test-topic");
143-
SubscriptionName subscription = SubscriptionName.create("test-project", "test-subscription");
142+
ProjectTopicName topic = ProjectTopicName.of("test-project", "test-topic");
143+
ProjectSubscriptionName subscription = ProjectSubscriptionName.of("test-project", "test-subscription");
144144

145145
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
146146
subscriptionAdminClient.createSubscription(subscription, topic, PushConfig.getDefaultInstance(), 0);
@@ -157,32 +157,35 @@ import com.google.cloud.pubsub.v1.MessageReceiver;
157157
import com.google.cloud.pubsub.v1.Subscriber;
158158
import com.google.common.util.concurrent.MoreExecutors;
159159
import com.google.pubsub.v1.PubsubMessage;
160-
import com.google.pubsub.v1.SubscriptionName;
161-
import com.google.pubsub.v1.TopicName;
160+
import com.google.pubsub.v1.ProjectSubscriptionName;
161+
import com.google.pubsub.v1.ProjectTopicName;
162162
```
163163
Then, to pull messages asynchronously, use the following code:
164164

165165
```java
166+
ProjectSubscriptionName subscription = ProjectSubscriptionName.of("test-project", "test-subscription");
167+
166168
MessageReceiver receiver =
167-
new MessageReceiver() {
168-
@Override
169-
public void receiveMessage(PubsubMessage message, AckReplyConsumer consumer) {
170-
System.out.println("got message: " + message.getData().toStringUtf8());
171-
consumer.ack();
172-
}
173-
};
169+
new MessageReceiver() {
170+
@Override
171+
public void receiveMessage(PubsubMessage message, AckReplyConsumer consumer) {
172+
System.out.println("got message: " + message.getData().toStringUtf8());
173+
consumer.ack();
174+
}
175+
};
176+
174177
Subscriber subscriber = null;
175178
try {
176-
subscriber = Subscriber.defaultBuilder(subscriptionName, receiver).build();
179+
subscriber = Subscriber.newBuilder(subscription, receiver).build();
177180
subscriber.addListener(
178-
new Subscriber.Listener() {
179-
@Override
180-
public void failed(Subscriber.State from, Throwable failure) {
181-
// Handle failure. This is called when the Subscriber encountered a fatal error and is shutting down.
182-
System.err.println(failure);
183-
}
184-
},
185-
MoreExecutors.directExecutor());
181+
new Subscriber.Listener() {
182+
@Override
183+
public void failed(Subscriber.State from, Throwable failure) {
184+
// Handle failure. This is called when the Subscriber encountered a fatal error and is shutting down.
185+
System.err.println(failure);
186+
}
187+
},
188+
MoreExecutors.directExecutor());
186189
subscriber.startAsync().awaitRunning();
187190
//...
188191
} finally {
@@ -193,12 +196,7 @@ try {
193196
```
194197
#### Complete source code
195198

196-
In
197-
[CreateTopicAndPublishMessages.java](../google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/CreateTopicAndPublishMessages.java)
198-
and
199-
[CreateSubscriptionAndConsumeMessages.java](../google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/CreateSubscriptionAndConsumeMessages.java)
200-
we put together all the code shown above into two programs. The programs assume that you are
201-
running on Compute Engine, App Engine Flexible or from your own desktop.
199+
In [CreateTopicAndPublishMessages.java](../google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/CreateTopicAndPublishMessages.java) and [CreateSubscriptionAndConsumeMessages.java](../google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/CreateSubscriptionAndConsumeMessages.java) we put together all the code shown above into two programs. The programs assume that you are running on Compute Engine, App Engine Flexible or from your own desktop.
202200

203201
Transport
204202
---------

0 commit comments

Comments
 (0)