HTTP Source Adapter


The HTTP Source adapter is an HTTP server that receives CloudEvents in version 1.0 and proxies them to a preconfigured sink. The adapter is written using Go SDK for CloudEvents and is fully compatible with the CloudEvents 1.0 specification.

It accepts binary and structured content modes. The batched mode is not implemented. See this document for details about the content types and the HTTP protocol binding.


Run the adapter locally

To use the adapter locally:

  1. Start with exporting the variables. Run:
export SINK_URI=http://localhost:55555
export NAMESPACE=foo
export K_METRICS_CONFIG='{"config-observability":"{\"metrics.backend\":\"prometheus\"}"}'
export K_LOGGING_CONFIG='{"zap-logger-config": "{\"level\":\"info\",\"development\":\"true\",\"outputPaths\":[\"stdout\"],\"errorOutputPaths\":[\"stderr\"],\"encoding\":\"console\",\"encoderConfig\":{\"timeKey\":\"ts\",\"levelKey\":\"level\",\"nameKey\":\"logger\",\"callerKey\":\"caller\",\"messageKey\":\"msg\",\"stack traceKey\":\"stacktrace\",\"lineEnding\":\"\",\"levelEncoder\":\"\",\"timeEncoder\":\"iso8601\",\"durationEncoder\":\"\",\"callerEncoder\":\"\"}}"}'
export EVENT_SOURCE="varkes"
  1. Run the adapter:
go run cmd/http-adapter/main.go

As a result, the adapter will send events to the SINK_URI. When running the adapter locally, you can simply use netcat as a sink:

printf "HTTP/1.1 200 OK\r\n\r\n" | nc -vl 55555
Send events to the adapter

You can send events using the structured or binary content mode.

To use the structured content mode, run:

curl -v -d '{
    "specversion" : "1.0",
    "source": "will be replaced",
    "type": "foo",
    "eventtypeversion": "0.3",
    "id" : "A234-1234-1234",
    "datacontenttype" : "text/xml",
    "data" : "<much wow=\"xml\"/>"
}' -H "Content-Type: application/cloudevents+json" -X POST http://localhost:8080

To use the binary content mode, run:

curl -v \
    -H "ce-specversion: 1.0" \
    -H "ce-source: will be replaced" \
    -H "ce-type: foo" \
    -H "ce-eventtypeversion: 0.3" \
    -H "ce-id: A234-1234-1234" \
    -H "content-type: text/xml" \
    -d '<much wow=\"xml\"/>' \



Run unit and integration tests:

make test-local
# or: go test ./adapter/http/
Expand ▾ Collapse ▴




View Source
const (
	ErrorResponseCEVersionUnsupported = "unsupported cloudevents version"
	ErrorResponseSendToSinkFailed     = "unable to forward event to sink"


This section is empty.


func NewAdapter

func NewAdapter(ctx context.Context, processed adapter.EnvConfigAccessor, ceClient cloudevents.Client, reporter source.StatsReporter) adapter.Adapter

func NewCloudEventsClient

func NewCloudEventsClient(port int) (cloudevents.Client, error)

NewCloudEventsClient creates a new client for receiving and sending cloud events

func NewEnvConfig

func NewEnvConfig() adapter.EnvConfigAccessor

func WithReadinessMiddleware

func WithReadinessMiddleware(next http.Handler) http.Handler


type AdapterEnvConfigAccessor

type AdapterEnvConfigAccessor interface {
	GetSource() string
	GetPort() int

Source Files