Skip to content

0.2.4

Choose a tag to compare

@mziccard mziccard released this 29 Jun 09:49

Features

Pub/Sub

  • gcloud-java-pubsub, a new client library to interact with Google Cloud Pub/Sub, is released and is in alpha. See the docs for more information.
    gcloud-java-pubsub uses gRPC as transport layer, which is not (yet) supported by App Engine Standard. gcloud-java-pubsub will work on App Engine Flexible.
    See PubSubExample for a complete example or API Documentation for gcloud-java-pubsub javadoc.
    The following snippet shows how to create a Pub/Sub topic and asynchronously publish messages to it. See CreateTopicAndPublishMessages.java for the full source code.
  try (PubSub pubsub = PubSubOptions.defaultInstance().service()) {
    Topic topic = pubsub.create(TopicInfo.of("test-topic"));
    Message message1 = Message.of("First message");
    Message message2 = Message.of("Second message");
    topic.publishAsync(message1, message2);
  }

The following snippet, instead, shows how to create a Pub/Sub pull subscription and asynchronously pull messages from it. See CreateSubscriptionAndPullMessages.java for the full source code.

  try (PubSub pubsub = PubSubOptions.defaultInstance().service()) {
    Subscription subscription =
        pubsub.create(SubscriptionInfo.of("test-topic", "test-subscription"));
    MessageProcessor callback = new MessageProcessor() {
      @Override
      public void process(Message message) throws Exception {
        System.out.printf("Received message \"%s\"%n", message.payloadAsString());
      }
    };
    // Create a message consumer and pull messages (for 60 seconds)
    try (MessageConsumer consumer = subscription.pullAsync(callback)) {
      Thread.sleep(60_000);
    }
  }