Memory Broker is the simplest Broker implementation provided by TriggerMesh and is used by default by
tmctl. The Redis Broker provides event durability and is used by default with TriggerMesh on Kubernetes.
apiVersion: eventing.triggermesh.io/v1alpha1 kind: MemoryBroker metadata: name: <broker instance name> spec: memory: bufferSize: <maximum number of events> broker: port: <HTTP port for ingesting events> observability: valueFromConfigMap: <kubernetes ConfigMap that contains observability configuration>
MemoryBroker specific parameter is
spec.memory.bufferSize which indicates the available size of the internal queue that the broker manages. When the maximum number of items is reached, new ingest requests will block and might eventually time out. This parameter is optional and defaults to 10000.
spec.broker section contains generic Broker parameters:
spec.broker.portthat the Broker service will be listening at. Optional, defaults to port 80.
spec.broker.observabilitycan be set to the name of a ConfigMap at the same namespace that contains observability settings (documentation coming soon). This parameter is optional.
Getting Started guide with the Memory Broker on Kubernetes
In this introduction tutorial we are going to setup a MemoryBroker with a Trigger that sends events to a Target endpoint, and if the delivery faisl to a Dead Letter Sink endpoint.
This guide uses 2 TriggerMesh components:
- MemoryBroker, which uses ephemeral memory to store events and routes them via Triggers.
- Trigger, which subscribes to events and push them to your targets.
Create a MemoryBroker named
Wait until the MemoryBroker is ready. It will inform in its status of the URL where events can be ingested.
To be able to use the broker we will create a Pod that allow us to send events inside the Kubernetes cluster.
It is possible now to send events to the broker address by issuing curl commands. The response for ingested events must be an
HTTP 200 which means that the broker has received it and will try to deliver them to configured triggers.
Unfortunately we haven't configured any trigger yet, which means any ingested event will not be delivered.
event_display is a CloudEvents consumer that logs to console the list of events received. We will be creating 2 instances of
event_display, one as the target for consumed events and another one for the Dead Letter Sink.
A Dead Letter Sink, abbreviated DLS is a destination that consumes events that a subscription was not able to deliver to the intended target.
# Target service kubectl apply -f https://raw.githubusercontent.com/triggermesh/triggermesh-core/main/docs/assets/manifests/common/display-target.yaml # DLS service kubectl apply -f https://raw.githubusercontent.com/triggermesh/triggermesh-core/main/docs/assets/manifests/common/display-deadlettersink.yaml
The Trigger object configures the broker to consume events and send them to a target. The Trigger object can include filters that select which events should be forwarded to the target, and delivery options to configure retries and fallback targets when the event cannot be delivered.
The Trigger created above filters by CloudEvents containing
type: demo.type1 attribute and delivers them to
display-target service, if delivery fails it will issue 3 retries and then forward the CloudEvent to the
curl Pod again we can send this CloudEvent to the broker.
The target display Pod will show the delivered event.
To simulate a target failure we will reconfigure the target display service to make it point to a non existing Pod set:
Any event that pass the filter will try to be sent to the target, and upon failing will be delivered to the DLS.
To clean up the getting started guide, delete each of the created assets:
# Removal of display-target not in this list, since it was deleted previously. kubectl delete -f \ https://raw.githubusercontent.com/triggermesh/triggermesh-core/main/docs/assets/manifests/getting-started-memory/trigger.yaml,\ https://raw.githubusercontent.com/triggermesh/triggermesh-core/main/docs/assets/manifests/common/display-deadlettersink.yaml,\ https://raw.githubusercontent.com/triggermesh/triggermesh-core/main/docs/assets/manifests/getting-started-memory/broker.yaml,\ https://raw.githubusercontent.com/triggermesh/triggermesh-core/main/docs/assets/manifests/common/curl.yaml