Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR was generated using Autosynth. 🌈 <details><summary>Log from Synthtool</summary> ``` 2021-01-22 18:43:07,265 synthtool [DEBUG] > Executing /root/.cache/synthtool/java-pubsublite-kafka/.github/readme/synth.py. On branch autosynth-readme nothing to commit, working tree clean 2021-01-22 18:43:08,184 synthtool [DEBUG] > Wrote metadata to .github/readme/synth.metadata/synth.metadata. ``` </details> Full log will be available here: https://source.cloud.google.com/results/invocations/e9279f80-8b93-42be-8dff-4f9a7cedc3a7/targets - [ ] To automatically regenerate this PR, check this box.
- Loading branch information
1 parent
2416797
commit 472c382
Showing
2 changed files
with
175 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"sources": [ | ||
{ | ||
"git": { | ||
"name": ".", | ||
"remote": "https://github.com/googleapis/java-pubsublite-kafka.git", | ||
"sha": "24167976e9bc4a14fb0754dfd174ea75516ada1e" | ||
} | ||
}, | ||
{ | ||
"git": { | ||
"name": "synthtool", | ||
"remote": "https://github.com/googleapis/synthtool.git", | ||
"sha": "b259489b06b25f399768b74b8baa943991f38ea7" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,98 +1,166 @@ | ||
# Instructions for Pub/Sub Lite Kafka usage. | ||
# Google Pub/Sub Lite Kafka Shim Client for Java | ||
|
||
Java idiomatic client for [Pub/Sub Lite Kafka Shim][product-docs]. | ||
|
||
[![Maven][maven-version-image]][maven-version-link] | ||
![Stability][stability-image] | ||
|
||
- [Product Documentation][product-docs] | ||
- [Client Library Documentation][javadocs] | ||
|
||
> Note: This client is a work-in-progress, and may occasionally | ||
> make backwards-incompatible changes. | ||
## Quickstart | ||
|
||
|
||
If you are using Maven, add this to your pom.xml file: | ||
|
||
1. Add the following to your POM file to download the Pub/Sub Lite Kafka shim. | ||
```xml | ||
<dependency> | ||
<groupId>org.apache.kafka</groupId> | ||
<artifactId>kafka-clients</artifactId> | ||
<version>2.6.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.cloud</groupId> | ||
<artifactId>pubsublite-kafka</artifactId> | ||
<version>0.1.1</version> | ||
</dependency> | ||
``` | ||
|
||
1. Create a topic using `gcloud pubsub lite-topics create` | ||
1. Write some messages using: | ||
|
||
```java | ||
import com.google.cloud.pubsublite.kafka.ProducerSettings; | ||
import com.google.cloud.pubsublite.*; | ||
|
||
import org.apache.kafka.clients.producer.*; | ||
|
||
... | ||
|
||
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(); | ||
|
||
ProducerSettings settings = ProducerSettings.newBuilder() | ||
.setTopicPath(topic) | ||
.build(); | ||
|
||
try (Producer<byte[], byte[]> producer = settings.instantiate()) { | ||
Future<RecordMetadata> sent = producer.send(new ProducerRecord( | ||
topic.toString(), // Required to be the same topic. | ||
"key".getBytes(), | ||
"value".getBytes() | ||
)); | ||
RecordMetadata meta = sent.get(); | ||
} | ||
``` | ||
1. Create a subscription using `gcloud pubsub lite-subscriptions create` | ||
1. Read some messages using: | ||
|
||
```java | ||
import com.google.cloud.pubsublite.cloudpubsub.FlowControlSettings; | ||
import com.google.cloud.pubsublite.kafka.ConsumerSettings; | ||
import com.google.cloud.pubsublite.*; | ||
|
||
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)) | ||
.setProject(ProjectNumber.of(PROJECT_NUM)) | ||
.setName(SubscriptionName.of("my-sub")) | ||
.build(); | ||
|
||
ConsumerSettings settings = ConsumerSettings.newBuilder() | ||
.setSubscriptionPath(subscription) | ||
.setPerPartitionFlowControlSettings(FlowControlSettings.builder() | ||
.setBytesOutstanding(10_000_000) // 10 MB | ||
.setMessagesOutstanding(Long.MAX_VALUE) | ||
.build()) | ||
.setAutocommit(true) | ||
.build(); | ||
|
||
try (Consumer<byte[], byte[]> consumer = settings.instantiate()) { | ||
consumer.subscribe(Arrays.asList(topic.toString())); | ||
while (true) { | ||
ConsumerRecords<byte[], byte[]> records = consumer.poll(Duration.ofSeconds(30)); | ||
for (ConsumerRecord<byte[], byte[]> record : records) { | ||
System.out.println(record.offset() + “: ” + record.value()); | ||
} | ||
} | ||
} catch (WakeupException e) { | ||
// ignored | ||
} | ||
``` | ||
If you are using Gradle without BOM, add this to your dependencies | ||
```Groovy | ||
compile 'com.google.cloud:pubsublite-kafka:0.1.1' | ||
``` | ||
|
||
If you are using SBT, add this to your dependencies | ||
```Scala | ||
libraryDependencies += "com.google.cloud" % "pubsublite-kafka" % "0.1.1" | ||
``` | ||
|
||
## Authentication | ||
|
||
See the [Authentication][authentication] section in the base directory's README. | ||
|
||
## Getting Started | ||
|
||
### Prerequisites | ||
|
||
You will need a [Google Cloud Platform Console][developer-console] project with the Pub/Sub Lite Kafka Shim [API enabled][enable-api]. | ||
You will need to [enable billing][enable-billing] to use Google Pub/Sub Lite Kafka Shim. | ||
[Follow these instructions][create-project] to get your project set up. You will also need to set up the local development environment by | ||
[installing the Google Cloud SDK][cloud-sdk] and running the following commands in command line: | ||
`gcloud auth login` and `gcloud config set project [YOUR PROJECT ID]`. | ||
|
||
### Installation and setup | ||
|
||
You'll need to obtain the `pubsublite-kafka` library. See the [Quickstart](#quickstart) section | ||
to add `pubsublite-kafka` as a dependency in your code. | ||
|
||
## About Pub/Sub Lite Kafka Shim | ||
|
||
|
||
[Pub/Sub Lite Kafka Shim][product-docs] is designed to provide reliable, | ||
many-to-many, asynchronous messaging between applications. Publisher | ||
applications can send messages to a topic and other applications can | ||
subscribe to that topic to receive the messages. By decoupling senders and | ||
receivers, Google Cloud Pub/Sub allows developers to communicate between | ||
independently written applications. | ||
|
||
Compared to Google Pub/Sub, Pub/Sub Lite provides partitioned zonal data | ||
storage with predefined capacity. Both products present a similar API, but | ||
Pub/Sub Lite has more usage caveats. | ||
|
||
See the [Google Pub/Sub Lite docs](https://cloud.google.com/pubsub/quickstart-console#before-you-begin) for more details on how to activate | ||
Pub/Sub Lite for your project, as well as guidance on how to choose between | ||
Cloud Pub/Sub and Pub/Sub Lite. | ||
|
||
See the [Pub/Sub Lite Kafka Shim client library docs][javadocs] to learn how to | ||
use this Pub/Sub Lite Kafka Shim Client Library. | ||
|
||
|
||
|
||
|
||
|
||
## Samples | ||
|
||
Samples are in the [`samples/`](https://github.com/googleapis/java-pubsublite-kafka/tree/master/samples) directory. The samples' `README.md` | ||
has instructions for running the samples. | ||
|
||
| Sample | Source Code | Try it | | ||
| --------------------------- | --------------------------------- | ------ | | ||
| Consumer Example | [source code](https://github.com/googleapis/java-pubsublite-kafka/blob/master/samples/snippets/src/main/java/pubsublite/ConsumerExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsublite-kafka&page=editor&open_in_editor=samples/snippets/src/main/java/pubsublite/ConsumerExample.java) | | ||
| Producer Example | [source code](https://github.com/googleapis/java-pubsublite-kafka/blob/master/samples/snippets/src/main/java/pubsublite/ProducerExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsublite-kafka&page=editor&open_in_editor=samples/snippets/src/main/java/pubsublite/ProducerExample.java) | | ||
|
||
|
||
|
||
## Troubleshooting | ||
|
||
To get help, follow the instructions in the [shared Troubleshooting document][troubleshooting]. | ||
|
||
## Transport | ||
|
||
Pub/Sub Lite Kafka Shim uses gRPC for the transport layer. | ||
|
||
## Java Versions | ||
|
||
Java 8 or above is required for using this client. | ||
|
||
## Versioning | ||
|
||
|
||
This library follows [Semantic Versioning](http://semver.org/). | ||
|
||
|
||
It is currently in major version zero (``0.y.z``), which means that anything may change at any time | ||
and the public API should not be considered stable. | ||
|
||
## Contributing | ||
|
||
|
||
Contributions to this library are always welcome and highly encouraged. | ||
|
||
See [CONTRIBUTING][contributing] for more information how to get started. | ||
|
||
Please note that this project is released with a Contributor Code of Conduct. By participating in | ||
this project you agree to abide by its terms. See [Code of Conduct][code-of-conduct] for more | ||
information. | ||
|
||
## License | ||
|
||
Apache 2.0 - See [LICENSE][license] for more information. | ||
|
||
## CI Status | ||
|
||
Java Version | Status | ||
------------ | ------ | ||
Java 8 | [![Kokoro CI][kokoro-badge-image-2]][kokoro-badge-link-2] | ||
Java 8 OSX | [![Kokoro CI][kokoro-badge-image-3]][kokoro-badge-link-3] | ||
Java 8 Windows | [![Kokoro CI][kokoro-badge-image-4]][kokoro-badge-link-4] | ||
Java 11 | [![Kokoro CI][kokoro-badge-image-5]][kokoro-badge-link-5] | ||
|
||
Java is a registered trademark of Oracle and/or its affiliates. | ||
|
||
[product-docs]: https://cloud.google.com/pubsub/lite/docs | ||
[javadocs]: https://googleapis.dev/java/google-cloud-pubsublite/latest/index.html | ||
[kokoro-badge-image-1]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-pubsublite-kafka/java7.svg | ||
[kokoro-badge-link-1]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-pubsublite-kafka/java7.html | ||
[kokoro-badge-image-2]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-pubsublite-kafka/java8.svg | ||
[kokoro-badge-link-2]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-pubsublite-kafka/java8.html | ||
[kokoro-badge-image-3]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-pubsublite-kafka/java8-osx.svg | ||
[kokoro-badge-link-3]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-pubsublite-kafka/java8-osx.html | ||
[kokoro-badge-image-4]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-pubsublite-kafka/java8-win.svg | ||
[kokoro-badge-link-4]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-pubsublite-kafka/java8-win.html | ||
[kokoro-badge-image-5]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-pubsublite-kafka/java11.svg | ||
[kokoro-badge-link-5]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-pubsublite-kafka/java11.html | ||
[stability-image]: https://img.shields.io/badge/stability-beta-yellow | ||
[maven-version-image]: https://img.shields.io/maven-central/v/com.google.cloud/pubsublite-kafka.svg | ||
[maven-version-link]: https://search.maven.org/search?q=g:com.google.cloud%20AND%20a:pubsublite-kafka&core=gav | ||
[authentication]: https://github.com/googleapis/google-cloud-java#authentication | ||
[developer-console]: https://console.developers.google.com/ | ||
[create-project]: https://cloud.google.com/resource-manager/docs/creating-managing-projects | ||
[cloud-sdk]: https://cloud.google.com/sdk/ | ||
[troubleshooting]: https://github.com/googleapis/google-cloud-common/blob/master/troubleshooting/readme.md#troubleshooting | ||
[contributing]: https://github.com/googleapis/java-pubsublite-kafka/blob/master/CONTRIBUTING.md | ||
[code-of-conduct]: https://github.com/googleapis/java-pubsublite-kafka/blob/master/CODE_OF_CONDUCT.md#contributor-code-of-conduct | ||
[license]: https://github.com/googleapis/java-pubsublite-kafka/blob/master/LICENSE | ||
[enable-billing]: https://cloud.google.com/apis/docs/getting-started#enabling_billing | ||
[enable-api]: https://console.cloud.google.com/flows/enableapi?apiid=pubsublite.googleapis.com | ||
[libraries-bom]: https://github.com/GoogleCloudPlatform/cloud-opensource-java/wiki/The-Google-Cloud-Platform-Libraries-BOM | ||
[shell_img]: https://gstatic.com/cloudssh/images/open-btn.png |