http

package
v0.0.0-...-18cdee1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 15, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

README

HTTP Source Adapter

Overview

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.

Usage

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\"/>' \
    http://localhost:8080

Development

Testing

Run unit and integration tests:

make test-local
# or: go test ./adapter/http/

Documentation

Index

Constants

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

Variables

This section is empty.

Functions

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

Types

type AdapterEnvConfigAccessor

type AdapterEnvConfigAccessor interface {
	adapter.EnvConfigAccessor
	GetSource() string
	GetPort() int
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL