Skip to content

Commit cb262aa

Browse files
fix(readme): update readme snippets (#31)
1 parent 4d9d185 commit cb262aa

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

README.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919

2020
```java
2121
import com.google.cloud.pubsublite.kafka.ProducerSettings;
22-
import org.apache.kafka.clients.producer.*;
2322
import com.google.cloud.pubsublite.*;
23+
24+
import org.apache.kafka.clients.producer.*;
2425

2526
...
2627

@@ -51,17 +52,22 @@
5152
1. Read some messages using:
5253

5354
```java
55+
import com.google.cloud.pubsublite.cloudpubsub.FlowControlSettings;
5456
import com.google.cloud.pubsublite.kafka.ConsumerSettings;
55-
import org.apache.kafka.clients.consumer.*;
5657
import com.google.cloud.pubsublite.*;
57-
import com.google.cloud.pubsublite.cloudpubsub.FlowControlSettings;
58-
58+
59+
import org.apache.kafka.clients.consumer.*;
5960
...
6061

6162
private final static String ZONE = "us-central1-b";
6263
private final static Long PROJECT_NUM = 123L;
6364

6465
...
66+
TopicPath topic = TopicPath.newBuilder()
67+
.setLocation(CloudZone.parse(ZONE))
68+
.setProject(ProjectNumber.of(PROJECT_NUM))
69+
.setName(TopicName.of("my-topic"))
70+
.build();
6571

6672
SubscriptionPath subscription = SubscriptionPath.newBuilder()
6773
.setLocation(CloudZone.parse(ZONE))
@@ -75,11 +81,13 @@
7581
.setBytesOutstanding(10_000_000) // 10 MB
7682
.setMessagesOutstanding(Long.MAX_VALUE)
7783
.build())
78-
.setAutocommit(true);
84+
.setAutocommit(true)
85+
.build();
7986

8087
try (Consumer<byte[], byte[]> consumer = settings.instantiate()) {
88+
consumer.subscribe(Arrays.asList(topic.toString()));
8189
while (true) {
82-
ConsumerRecords<byte[], byte[]> records = consumer.poll(Long.MAX_VALUE);
90+
ConsumerRecords<byte[], byte[]> records = consumer.poll(Duration.ofSeconds(30));
8391
for (ConsumerRecord<byte[], byte[]> record : records) {
8492
System.out.println(record.offset() +:+ record.value());
8593
}

0 commit comments

Comments
 (0)