|
19 | 19 |
|
20 | 20 | ```java |
21 | 21 | import com.google.cloud.pubsublite.kafka.ProducerSettings; |
22 | | - import org.apache.kafka.clients.producer.*; |
23 | 22 | import com.google.cloud.pubsublite.*; |
| 23 | + |
| 24 | + import org.apache.kafka.clients.producer.*; |
24 | 25 |
|
25 | 26 | ... |
26 | 27 |
|
|
51 | 52 | 1. Read some messages using: |
52 | 53 |
|
53 | 54 | ```java |
| 55 | + import com.google.cloud.pubsublite.cloudpubsub.FlowControlSettings; |
54 | 56 | import com.google.cloud.pubsublite.kafka.ConsumerSettings; |
55 | | - import org.apache.kafka.clients.consumer.*; |
56 | 57 | import com.google.cloud.pubsublite.*; |
57 | | - import com.google.cloud.pubsublite.cloudpubsub.FlowControlSettings; |
58 | | - |
| 58 | + |
| 59 | + import org.apache.kafka.clients.consumer.*; |
59 | 60 | ... |
60 | 61 |
|
61 | 62 | private final static String ZONE = "us-central1-b"; |
62 | 63 | private final static Long PROJECT_NUM = 123L; |
63 | 64 |
|
64 | 65 | ... |
| 66 | + TopicPath topic = TopicPath.newBuilder() |
| 67 | + .setLocation(CloudZone.parse(ZONE)) |
| 68 | + .setProject(ProjectNumber.of(PROJECT_NUM)) |
| 69 | + .setName(TopicName.of("my-topic")) |
| 70 | + .build(); |
65 | 71 |
|
66 | 72 | SubscriptionPath subscription = SubscriptionPath.newBuilder() |
67 | 73 | .setLocation(CloudZone.parse(ZONE)) |
|
75 | 81 | .setBytesOutstanding(10_000_000) // 10 MB |
76 | 82 | .setMessagesOutstanding(Long.MAX_VALUE) |
77 | 83 | .build()) |
78 | | - .setAutocommit(true); |
| 84 | + .setAutocommit(true) |
| 85 | + .build(); |
79 | 86 |
|
80 | 87 | try (Consumer<byte[], byte[]> consumer = settings.instantiate()) { |
| 88 | + consumer.subscribe(Arrays.asList(topic.toString())); |
81 | 89 | while (true) { |
82 | | - ConsumerRecords<byte[], byte[]> records = consumer.poll(Long.MAX_VALUE); |
| 90 | + ConsumerRecords<byte[], byte[]> records = consumer.poll(Duration.ofSeconds(30)); |
83 | 91 | for (ConsumerRecord<byte[], byte[]> record : records) { |
84 | 92 | System.out.println(record.offset() + “: ” + record.value()); |
85 | 93 | } |
|
0 commit comments