CE Wrapper is a wrapper to generate CloudEvents events for services that do not emit events themselves. It will initially work for RESTful APIs.
It is a completely stateless proxy that passes the request unmodified to the downstream service, and emits an event for requests that are of interest.
Default these are requests that change state, like POST, PUT, PATCH and DELETE, but other methods can be added.
The mandatory cloud event context attributes are set using the information of the incoming http request, or with values set by the user. This way ample information is available for filtering and subscribing.
Context Attributes
- id, will be set with an autogenerated UUID
- source, needs to be configured
- subject, the path of the request
- type, this value will be a configured prefix follow by the methodname and the suffix _handled
- time, the time the forwarded request finished
- datacontenttype, the content type of the response from the downstream service
- dataschema, can be configured
The data will contain a json struct with the response body the downstream service returned.
Example
Assume the downstream service is on service.example.com
and it returns json formatted responses with person information.
A successful post request to http://service.example.com/persons/id12345
resource that contains persons will result in an event with the following attributes.
- subject:
/persons/id12345
- type:
com.example.persons.post_handled
- source:
http://service.example.com/
parameter | env var | description |
---|---|---|
-sink | K_SINK, CWE_SINK | The url of the event sink. |
-source | CEW_SOURCE | The source of the event. |
-type | CEW_TYPE_PREFIX | The prefix for the type. |
-dataschema | CEW_DATASCHEMA | The URL for the dataschema of the event data. |
-downstream | CEW_DOWNSTREAM | Downstream service. |
-port | PORT | Listening port of the wrapper, defaults to 8080. |
-extra-methods | CEW_EXTRA_METHODS | Extra methods to add to the standard state changing methods |
Run go-httpbin on port 9090.
podman run --rm -p 9090:8080 docker.io/mccutchen/go-httpbin:v2.11.1
Run cesourcewrap on port 8080.
podman run --rm \
-p 8080:8080 \
-e CEW_SINK=http://192.168.0.202:10000 \
-e CEW_DOWNSTREAM=http://192.168.0.202:9090 \
-e CEW_EXTRA_METHODS=GET \
docker.io/peterzandbergen/cesourcewrap:v0.0.1
Run event display on port 10000
podman run --rm \
-p 10000:80 \
gcr.io/knative-releases/knative.dev/eventing/cmd/event_display