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
,java.io.Closeable
,java.lang.AutoCloseable
public abstract class GoogleCloudEventsFunction<T> extends GoogleFunctionInitializer implements com.google.cloud.functions.CloudEventsFunction
A super class that extendsGoogleFunctionInitializer
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:
- Google Cloud Events.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
GoogleCloudEventsFunction()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
accept(io.cloudevents.CloudEvent event)
protected abstract void
accept(io.cloudevents.CloudEventContext context, T data)
Called to service an incoming event.protected java.lang.Class<T>
getType()
protected java.util.Optional<T>
map(io.cloudevents.CloudEvent event, java.lang.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
-
-
-
-
Method Detail
-
accept
public void accept(io.cloudevents.CloudEvent event) throws java.lang.Exception
- Specified by:
accept
in interfacecom.google.cloud.functions.CloudEventsFunction
- Throws:
java.lang.Exception
-
accept
protected abstract void accept(@NonNull io.cloudevents.CloudEventContext context, @Nullable T data) throws java.lang.Exception
Called to service an incoming event. If this method throws any exception (including anyError
) then the HTTP response will have a 500 status code.- Parameters:
context
- Cloud Event contextdata
- Google Cloud Event- Throws:
java.lang.Exception
- to produce a 500 status code in the HTTP response.
-
getType
@NonNull protected java.lang.Class<T> getType()
- Returns:
- Google Cloud Event Type.
-
map
@NonNull protected java.util.Optional<T> map(@NonNull io.cloudevents.CloudEvent event, @NonNull java.lang.Class<T> type)
Maps a cloud event to the target type.- Parameters:
event
- The Cloud Eventtype
- The target mapping type.- Returns:
- The bound type if possible, or an empty optional in case of error.
-
-