|
1 | 1 | # Getting Started with Cloud Pub/Sub and the Google Cloud Client libraries
|
2 | 2 |
|
3 |
| -<a href="https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/java-docs-samples&page=editor&open_in_editor=pubsub/cloud-client/README.md"> |
4 |
| -<img alt="Open in Cloud Shell" src ="http://gstatic.com/cloudssh/images/open-btn.png"></a> |
5 |
| - |
6 |
| -[Google Cloud Pub/Sub][pubsub] is a fully-managed real-time messaging service that allows you to |
7 |
| -send and receive messages between independent applications. |
8 |
| -This sample Java application demonstrates how to access the Pub/Sub API using |
9 |
| -the [Google Cloud Client Library for Java][google-cloud-java]. |
10 |
| - |
11 |
| -[pubsub]: https://cloud.google.com/pubsub/ |
12 |
| -[google-cloud-java]: https://github.com/GoogleCloudPlatform/google-cloud-java |
13 |
| - |
14 |
| -For more samples, see the samples in |
15 |
| -[google-cloud-java](https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub). |
16 |
| - |
17 |
| -## Quickstart |
18 |
| - |
19 |
| -#### Setup |
20 |
| -- Install [Maven](http://maven.apache.org/). |
21 |
| -- [Enable](https://console.cloud.google.com/apis/api/pubsub.googleapis.com/overview) Pub/Sub API. |
22 |
| -- Set up [authentication](https://cloud.google.com/docs/authentication/getting-started). |
23 |
| - |
24 |
| -#### Build |
25 |
| -- Build your project with: |
26 |
| -``` |
27 |
| - mvn clean package -DskipTests |
28 |
| -``` |
29 |
| - |
30 |
| -#### Create a new topic |
31 |
| -``` |
32 |
| - mvn exec:java -Dexec.mainClass=com.example.pubsub.CreateTopicExample -Dexec.args=my-topic |
33 |
| -``` |
34 |
| - |
35 |
| -#### Create a subscription |
36 |
| -``` |
37 |
| - mvn exec:java -Dexec.mainClass=com.example.pubsub.CreatePullSubscriptionExample -Dexec.args="my-topic my-sub" |
38 |
| -``` |
39 |
| - |
40 |
| -#### Publish messages |
41 |
| -``` |
42 |
| - mvn exec:java -Dexec.mainClass=com.example.pubsub.PublisherExample -Dexec.args="my-topic 5" |
43 |
| -``` |
44 |
| -Publishes 5 messages to the topic `my-topic`. |
45 |
| - |
46 |
| -#### Receive messages |
47 |
| -``` |
48 |
| - mvn exec:java -Dexec.mainClass=com.example.pubsub.SubscriberExample -Dexec.args=my-sub |
49 |
| -``` |
50 |
| -Subscriber will continue to listen on the topic and print out message id and data as messages are received. Press `Ctrl+C` to exit the application. |
51 |
| - |
52 |
| -#### Testing |
53 |
| -Run the test with Maven. |
54 |
| -``` |
55 |
| - mvn verify |
56 |
| -``` |
| 3 | +The samples have been moved to live alongside the Java client library for Cloud Pub/Sub: https://github.com/googleapis/java-pubsub/tree/master/samples/snippets/src/main/java/pubsub/ |
0 commit comments