Class GoogleCloudEventsFunction<T>

java.lang.Object
io.micronaut.function.executor.AbstractExecutor
io.micronaut.function.executor.FunctionInitializer
io.micronaut.gcp.function.GoogleFunctionInitializer
io.micronaut.gcp.function.cloudevents.GoogleCloudEventsFunction<T>
Type Parameters:
T - Google Cloud Events Type
All Implemented Interfaces:
com.google.cloud.functions.CloudEventsFunction, io.micronaut.context.ApplicationContextProvider, Closeable, AutoCloseable

public abstract class GoogleCloudEventsFunction<T> extends GoogleFunctionInitializer implements com.google.cloud.functions.CloudEventsFunction
A super class that extends GoogleFunctionInitializer and can be used to map cloud events payloads. To be used with CloudEvents POJOs issued by Google.
Since:
4.8.0
Author:
Guillermo Calvo
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from class io.micronaut.function.executor.FunctionInitializer

    io.micronaut.function.executor.FunctionInitializer.ParseContext
  • Field Summary

    Fields inherited from class io.micronaut.function.executor.FunctionInitializer

    closeContext

    Fields inherited from class io.micronaut.function.executor.AbstractExecutor

    applicationContext
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected abstract void
    accept(@NonNull io.cloudevents.CloudEventContext context, T data)
    Called to service an incoming event.
    void
    accept(io.cloudevents.CloudEvent event)
     
    protected @NonNull Class<T>
     
    protected @NonNull Optional<T>
    map(@NonNull io.cloudevents.CloudEvent event, @NonNull Class<T> type)
    Maps a cloud event to the target type.

    Methods inherited from class io.micronaut.gcp.function.GoogleFunctionInitializer

    newApplicationContextBuilder

    Methods inherited from class io.micronaut.function.executor.FunctionInitializer

    close, injectThis, run, startThis

    Methods inherited from class io.micronaut.function.executor.AbstractExecutor

    buildApplicationContext, getApplicationContext, resolveFunction, resolveFunctionName, startEnvironment

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • GoogleCloudEventsFunction

      protected GoogleCloudEventsFunction()
  • Method Details

    • accept

      public void accept(io.cloudevents.CloudEvent event) throws Exception
      Specified by:
      accept in interface com.google.cloud.functions.CloudEventsFunction
      Throws:
      Exception
    • accept

      protected abstract void accept(@NonNull @NonNull io.cloudevents.CloudEventContext context, @Nullable T data) throws Exception
      Called to service an incoming event. If this method throws any exception (including any Error) then the HTTP response will have a 500 status code.
      Parameters:
      context - Cloud Event context
      data - Google Cloud Event
      Throws:
      Exception - to produce a 500 status code in the HTTP response.
    • getType

      @NonNull protected @NonNull Class<T> getType()
      Returns:
      Google Cloud Event Type.
    • map

      @NonNull protected @NonNull Optional<T> map(@NonNull @NonNull io.cloudevents.CloudEvent event, @NonNull @NonNull Class<T> type)
      Maps a cloud event to the target type.
      Parameters:
      event - The Cloud Event
      type - The target mapping type.
      Returns:
      The bound type if possible, or an empty optional in case of error.