You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| Native Image Pub Sub Sample |[source code](https://github.com/googleapis/java-pubsub/blob/main/samples/native-image-sample/src/main/java/pubsub/NativeImagePubSubSample.java)|[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/native-image-sample/src/main/java/pubsub/NativeImagePubSubSample.java)|
244
+
| Publish Operations |[source code](https://github.com/googleapis/java-pubsub/blob/main/samples/native-image-sample/src/main/java/utilities/PublishOperations.java)|[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/native-image-sample/src/main/java/utilities/PublishOperations.java)|
243
245
| Create Avro Schema Example |[source code](https://github.com/googleapis/java-pubsub/blob/main/samples/snippets/src/main/java/pubsub/CreateAvroSchemaExample.java)|[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/CreateAvroSchemaExample.java)|
244
246
| Create Proto Schema Example |[source code](https://github.com/googleapis/java-pubsub/blob/main/samples/snippets/src/main/java/pubsub/CreateProtoSchemaExample.java)|[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/CreateProtoSchemaExample.java)|
245
247
| Create Pull Subscription Example |[source code](https://github.com/googleapis/java-pubsub/blob/main/samples/snippets/src/main/java/pubsub/CreatePullSubscriptionExample.java)|[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-pubsub&page=editor&open_in_editor=samples/snippets/src/main/java/pubsub/CreatePullSubscriptionExample.java)|
The Pub/Sub sample application demonstrates some common operations with Pub/Sub and is compatible with Native Image compilation.
4
+
5
+
## Setup Instructions
6
+
7
+
You will need to follow these prerequisite steps in order to run the samples:
8
+
9
+
1. If you have not already, [create a Google Cloud Platform Project](https://cloud.google.com/resource-manager/docs/creating-managing-projects#creating_a_project).
10
+
11
+
2. Install the [Google Cloud SDK](https://cloud.google.com/sdk/) which will allow you to run the sample with your project's credentials.
12
+
13
+
Once installed, log in with Application Default Credentials using the following command:
14
+
15
+
```
16
+
gcloud auth application-default login
17
+
```
18
+
19
+
**Note:** Authenticating with Application Default Credentials is convenient to use during development, but we recommend [alternate methods of authentication](https://cloud.google.com/docs/authentication/production) during production use.
20
+
21
+
3. Install the GraalVM compiler.
22
+
23
+
You can follow the [official installation instructions](https://www.graalvm.org/docs/getting-started/#install-graalvm) from the GraalVM website.
24
+
After following the instructions, ensure that you install the native image extension installed by running:
25
+
26
+
```
27
+
gu install native-image
28
+
```
29
+
30
+
Once you finish following the instructions, verify that the default version of Java is set to the GraalVM version by running `java -version` in a terminal.
31
+
32
+
You will see something similar to the below output:
33
+
34
+
```
35
+
$ java -version
36
+
37
+
openjdk version "11.0.7" 2020-04-14
38
+
OpenJDK Runtime Environment GraalVM CE 20.1.0 (build 11.0.7+10-jvmci-20.1-b02)
39
+
OpenJDK 64-Bit Server VM GraalVM CE 20.1.0 (build 11.0.7+10-jvmci-20.1-b02, mixed mode, sharing)
40
+
```
41
+
42
+
4. [Enable the Pub/Sub APIs](https://console.cloud.google.com/apis/api/pubsub.googleapis.com).
43
+
44
+
### Sample
45
+
46
+
Navigate to this directory in a new terminal.
47
+
48
+
1. Compile the application using the Native Image Compiler. This step may take a few minutes.
49
+
50
+
```
51
+
mvn package -P native -DskipTests
52
+
```
53
+
54
+
2. Run the application:
55
+
56
+
```
57
+
./target/native-image-sample
58
+
```
59
+
60
+
3. The application will create a new Pub/Sub topic, send and receive a message from it, and then delete the topic.
61
+
62
+
```
63
+
Created topic: projects/YOUR_PROJECT_ID/topics/graal-pubsub-test-00e72640-4e36-4aff-84d2-13b7569b2289 under project: YOUR_PROJECT_ID
64
+
Created pull subscription: projects/YOUR_PROJECT_ID/subscriptions/graal-pubsub-test-sub2fb5e3f3-cb26-439b-b88c-9cb0cfca9e45
65
+
Published message with ID: 457327433078420
66
+
Received Payload: Pub/Sub Native Image Test published message at timestamp: 2020-09-23T19:45:42.746514Z
0 commit comments