Here is an example of an implementation that accesses the {@code messageId} property from a - * payload that matches a user-defined {@code PubSubMessage} class: - * - * - *
- * public class Example implements{@code BackgroundFunction} {
- * private static final Logger logger = Logger.getLogger(Example.class.getName());
- *
- * {@code @Override}
- * public void accept(PubSubMessage pubSubMessage, Context context) {
- * logger.info("Got messageId " + pubSubMessage.messageId);
- * }
- * }
- *
- * // Where PubSubMessage is a user-defined class like this:
- * public class PubSubMessage {
- * String data;
- * {@code Map} attributes;
- * String messageId;
- * String publishTime;
- * }
- *
- *
- * @param The map returned by this method may be empty but is never null.
- *
- * @return additional attributes form this event.
- */
- default Map Here is an example of an implementation that parses the JSON payload using Gson, to access its
- * {@code messageId} property:
- *
- *
- * Here is an example of an implementation that deserializes the JSON payload into a Java object
- * for simpler access, again using Gson:
- *
- *
+ * ...then the returned value will map {@code "Content-Type"} to a one-element list containing
+ * {@code "text/plain"}, and {@code "Some-Header"} to a two-element list containing {@code "some
+ * value"} and {@code "another value"}.
+ *
+ * @return a map where each key is an HTTP header and the corresponding {@code List} value has one
+ * element for each occurrence of that header.
+ */
+ Map
+ * ...then {@code getFirstHeader("Some-Header")} will return {@code Optional.of("some value")},
+ * and {@code getFirstHeader("Another-Header")} will return {@code Optional.empty()}.
+ *
+ * @param name an HTTP header name.
+ * @return the first value of the given header, if present.
+ */
+ default Optional
- * Content-Type: text/plain
- * Some-Header: some value
- * Some-Header: another value
- *
- *
- * ...then the returned value will map {@code "Content-Type"} to a one-element list containing
- * {@code "text/plain"}, and {@code "Some-Header"} to a two-element list containing {@code "some
- * value"} and {@code "another value"}.
- *
- * @return a map where each key is an HTTP header and the corresponding {@code List} value has one
- * element for each occurrence of that header.
- */
- Map
- * Content-Type: text/plain
- * Some-Header: some value
- * Some-Header: another value
- *
- *
- * ...then {@code getFirstHeader("Some-Header")} will return {@code Optional.of("some value")},
- * and {@code getFirstHeader("Another-Header")} will return {@code Optional.empty()}.
- *
- * @param name an HTTP header name.
- * @return the first value of the given header, if present.
- */
- default Optional
- * {@code setStatusCode(400, "Something went wrong")}. The named constants in {@link
- * java.net.HttpURLConnection}, such as {@link java.net.HttpURLConnection#HTTP_BAD_REQUEST
- * HTTP_BAD_REQUEST}, can be used as an alternative to writing numbers in your source code.
- *
- * @param code the status code.
- * @param message the status message.
- */
- void setStatusCode(int code, String message);
-
- /**
- * Sets the value to use for the {@code Content-Type} header in the response. This may include a
- * character encoding, for example {@code setContentType("text/plain; charset=utf-8")}.
- *
- * @param contentType the content type.
- */
- void setContentType(String contentType);
-
- /**
- * Returns the {@code Content-Type} that was previously set by {@link #setContentType}, or by
- * {@link #appendHeader} with a header name of {@code Content-Type}. If no {@code Content-Type}
- * has been set, returns {@code Optional.empty()}.
- *
- * @return the content type, if any.
- */
- Optional
- * public class Example implements RawBackgroundFunction {
- * private static final Logger logger = Logger.getLogger(Example.class.getName());
- *
- * {@code @Override}
- * public void accept(String json, Context context) {
- * JsonObject jsonObject = new Gson().fromJson(json, JsonObject.class);
- * JsonElement messageId = jsonObject.get("messageId");
- * String messageIdString = messageId.getAsJsonString();
- * logger.info("Got messageId " + messageIdString);
- * }
- * }
- *
- *
- *
- * public class Example implements RawBackgroundFunction {
- * private static final Logger logger = Logger.getLogger(Example.class.getName());
- *
- * {@code @Override}
- * public void accept(String json, Context context) {
- * PubSubMessage message = new Gson().fromJson(json, PubSubMessage.class);
- * logger.info("Got messageId " + message.messageId);
- * }
- * }
- *
- * // Where PubSubMessage is a user-defined class like this:
- * public class PubSubMessage {
- * String data;
- * {@code Map
- */
-@FunctionalInterface
-public interface RawBackgroundFunction {
- /**
- * Called to service an incoming event. This interface is implemented by user code to provide the
- * action for a given background function. If this method throws any exception (including any
- * {@link Error}) then the HTTP response will have a 500 status code.
- *
- * @param json the payload of the event, as a JSON string.
- * @param context the context of the event. This is a set of values that every event has,
- * separately from the payload, such as timestamp and event type.
- * @throws Exception to produce a 500 status code in the HTTP response.
- */
- void accept(String json, Context context) throws Exception;
-}
diff --git a/functions-framework-api/src/main/java/dev/openfunction/functions/BindingEvent.java b/functions-framework-api/src/main/java/dev/openfunction/functions/BindingEvent.java
new file mode 100644
index 00000000..96cc80c5
--- /dev/null
+++ b/functions-framework-api/src/main/java/dev/openfunction/functions/BindingEvent.java
@@ -0,0 +1,49 @@
+/*
+Copyright 2022 The OpenFunction Authors.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package dev.openfunction.functions;
+
+import java.nio.ByteBuffer;
+import java.util.Map;
+
+public class BindingEvent {
+ /**
+ * The name of the input binding component.
+ */
+ private final String name;
+
+ private final ByteBuffer data;
+
+ private final Map
+ * Content-Type: text/plain
+ * Some-Header: some value
+ * Some-Header: another value
+ *
+ *
+ * Content-Type: text/plain
+ * Some-Header: some value
+ * Some-Header: another value
+ *
+ *
+ * {@code setStatusCode(400, "Something went wrong")}. The named constants in {@link
+ * java.net.HttpURLConnection}, such as {@link java.net.HttpURLConnection#HTTP_BAD_REQUEST
+ * HTTP_BAD_REQUEST}, can be used as an alternative to writing numbers in your source code.
+ *
+ * @param code the status code.
+ * @param message the status message.
+ */
+ void setStatusCode(int code, String message);
+
+ /**
+ * Sets the value to use for the {@code Content-Type} header in the response. This may include a
+ * character encoding, for example {@code setContentType("text/plain; charset=utf-8")}.
+ *
+ * @param contentType the content type.
+ */
+ void setContentType(String contentType);
+
+ /**
+ * Returns the {@code Content-Type} that was previously set by {@link #setContentType}, or by
+ * {@link #appendHeader} with a header name of {@code Content-Type}. If no {@code Content-Type}
+ * has been set, returns {@code Optional.empty()}.
+ *
+ * @return the content type, if any.
+ */
+ Optional