CloudEvents source
The TriggerMesh CloudEventsSource
is used to ingest CloudEvents produced from external sources via HTTP. The CloudEventsSource
acts as an HTTP server that can receives requests.
With tmctl
:
On Kubernetes:
apiVersion: sources.triggermesh.io/v1alpha1
kind: CloudEventsSource
metadata:
name: sample
spec:
sink:
ref:
apiVersion: eventing.knative.dev/v1
kind: Broker
name: default
Events produced have the following attributes:
- type depends on the metadata passed as part of the CloudEvent at runtime, unless overridden
- Schema of the
data
attribute is not know by TriggerMesh out of the box
See the Kubernetes object reference for more details.
A CloudEvent can be sent to a CloudEventsSource by using curl
. The example below includes the optional Basic Authentication and Path.
Calling the CloudEventsSource
Configuring a CloudEventsSource Object
The CloudEventsSource accepts parameters to set authentication, URL path and rate limiter. When succesfuly created it exposes an HTTP endpoint to listen for CloudEvents.
Configuring Credentials (Optional)
Credentials can be configured using Basic Authentication using Kubernetes secrets to manage passwords.
Credentials are defined as arrays, allowing clients to use multiple user/password items.
The credentials are defined under spec.credentials.basicAuths
:
Credentials for 2 users
Configuring Path (Optional)
The spec.path
parameter is used configure the URL path where CloudEvents will be accepted. When specified clients using this component must add the designated path
to the URL, obtaining a 404 for any other requested location.
Using path
Path is not usually needed. Configure it when an existing CloudEvents producer is already emitting events using that path and cannot be re-configured.
Configuring Rate Limiter (Optional)
Rate Limiter is used to filter the quantity of requests per second that an adapter instance can receive. When the configured limit per time window is reached, HTTP code 429 is returned along information on when the client should retry.
Example response when rate limit reached
To configure the Rate Limiter use the spec.rateLimiter.requestsPerSecond
parameter:
It must be noted when configuring the Rate Limiter that:
Rate limiter is per instance
The CloudEventsSource component is able to scale under load. The rate limiter value is set individualy per each scaled instance, which means that setting this value does not limit the total ammount of requests that can be received, but protects each instance from receiving more the configured value while informing the caller to re-issue the request.
Rate limiter and scaling
A low value of the rate limiter might prevent the adapter from scaling if the configured value is below the scaling rate.
Configuring CloudEvents Sink
The spec.sink
parameter is a destination that points to an object or URL that will receive the ingested CloudEvents.
Using the CloudEventsSource
Given the CloudEventsSource configuration options depicted in the preceding sections we can create this example CloudEventsSource by creating this object at a TriggerMesh cluster:
Example CloudEventsSource
apiVersion: sources.triggermesh.io/v1alpha1
kind: CloudEventsSource
metadata:
name: sample
spec:
credentials:
basicAuths:
- username: user1
password:
valueFromSecret:
name: password1
key: password
- username: user2
password:
valueFromSecret:
name: password2
key: password
path: /mypath
rateLimiter:
requestsPerSecond: 1000
sink:
ref:
apiVersion: eventing.knative.dev/v1
kind: Broker
name: default