Skip to content

Commit

Permalink
fix(readme): update readme snippets (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
anguillanneuf committed Dec 1, 2020
1 parent 4d9d185 commit cb262aa
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions README.md
Expand Up @@ -19,8 +19,9 @@

```java
import com.google.cloud.pubsublite.kafka.ProducerSettings;
import org.apache.kafka.clients.producer.*;
import com.google.cloud.pubsublite.*;

import org.apache.kafka.clients.producer.*;

...

Expand Down Expand Up @@ -51,17 +52,22 @@
1. Read some messages using:

```java
import com.google.cloud.pubsublite.cloudpubsub.FlowControlSettings;
import com.google.cloud.pubsublite.kafka.ConsumerSettings;
import org.apache.kafka.clients.consumer.*;
import com.google.cloud.pubsublite.*;
import com.google.cloud.pubsublite.cloudpubsub.FlowControlSettings;


import org.apache.kafka.clients.consumer.*;
...

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

...
TopicPath topic = TopicPath.newBuilder()
.setLocation(CloudZone.parse(ZONE))
.setProject(ProjectNumber.of(PROJECT_NUM))
.setName(TopicName.of("my-topic"))
.build();

SubscriptionPath subscription = SubscriptionPath.newBuilder()
.setLocation(CloudZone.parse(ZONE))
Expand All @@ -75,11 +81,13 @@
.setBytesOutstanding(10_000_000) // 10 MB
.setMessagesOutstanding(Long.MAX_VALUE)
.build())
.setAutocommit(true);
.setAutocommit(true)
.build();

try (Consumer<byte[], byte[]> consumer = settings.instantiate()) {
consumer.subscribe(Arrays.asList(topic.toString()));
while (true) {
ConsumerRecords<byte[], byte[]> records = consumer.poll(Long.MAX_VALUE);
ConsumerRecords<byte[], byte[]> records = consumer.poll(Duration.ofSeconds(30));
for (ConsumerRecord<byte[], byte[]> record : records) {
System.out.println(record.offset() +:+ record.value());
}
Expand Down

0 comments on commit cb262aa

Please sign in to comment.