Skip to content

Latest commit

 

History

History
63 lines (47 loc) · 2.13 KB

README.md

File metadata and controls

63 lines (47 loc) · 2.13 KB

Google CloudEvents – Java

Maven Central

This repository contains POJOs for CloudEvents issued by Google.

Prerequisites

  • Java 7 (or higher)

Installation

To use Maven, add the following lines to your pom.xml file:

<project>
  <dependencies>
    <dependency>
      <groupId>google.events</groupId>
      <artifactId>google-cloudevent-types</artifactId>
      <version>1.0-SNAPSHOT</version>
    </dependency>
  </dependencies>
</project>

CloudEvent Types

This repo contains these types:

Note: This repo is generated from the Google CloudEvent schema sources in https://github.com/googleapis/google-cloudevents.

Usage

The event types can be used to transform a HTTP POST request's body to a Java object.

For example, in the Spring Framework, this library can be used as such:

import com.google.events.cloud.pubsub.v1.MessagePublishedData;
import com.google.events.cloud.pubsub.v1.PubsubMessage;
//...
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class EventController {
  @RequestMapping(value = "/", method = RequestMethod.POST)
  public ResponseEntity<String> receiveMessage(
      @RequestBody MessagePublishedData messagePublishedData, @RequestHeader Map<String, String> headers) {
    // Get PubSub message from request body.
    PubsubMessage message = messagePublishedData.getMessage();
    // Use message data
  }
}