Cloud Events Support

What are CloudEvents?

CloudEvents is a CNCF specification for describing event data in a common, standardized way. Without a standard for metadata, each messaging framework uses its own set of metadata fields, making it difficult to write interoperable code that works across different messaging systems.

CloudEvents solves this problem by providing a specification that defines:

  • A standard set of metadata attributes for events

  • Multiple content modes (binary and structured)

  • Protocol bindings for various transport protocols

Brighter V10 provides full CloudEvents specification support, making it easy to build interoperable, event-driven systems.

CloudEvents Attributes

CloudEvents defines both required and optional attributes for events. Brighter supports all CloudEvents attributes.

Required Attributes

These attributes must be present in every CloudEvent:

Attribute
Type
Description

id

String

Unique identifier for the event (Brighter message ID)

source

URI-reference

Context in which the event occurred

type

String

Type of event (e.g., "com.example.order.created")

specversion

String

CloudEvents specification version (e.g., "1.0")

Important Optional Attributes

Attribute
Type
Description

datacontenttype

String

Content type of the data (e.g., "application/json")

dataschema

URI

Schema that the data adheres to

subject

String

Subject of the event in the context of the source

time

Timestamp

When the event occurred

Extension Attributes

CloudEvents supports extension attributes for additional metadata:

Extension
Specification
Purpose

traceparent

W3C Trace Context for distributed tracing

tracestate

Vendor-specific trace information

dataref

Reference to data stored elsewhere (Claim Check pattern)

Content Modes

CloudEvents can be transmitted in two modes, and Brighter supports both:

In binary-mode, CloudEvents attributes are mapped to protocol headers, and the event data is placed in the message body.

When to use binary mode:

  • The transport protocol supports headers (RabbitMQ, Kafka, AMQP)

  • You want efficient serialization

  • You want to inspect event metadata without deserializing the body

Example RabbitMQ message with binary CloudEvents:

Structured Content Mode

In structured mode, both CloudEvents attributes and data are placed in the message body as a JSON object.

When to use structured mode:

  • The transport has insufficient header support (AWS SNS/SQS)

  • You need to preserve all metadata in a single payload

  • The protocol doesn't support custom headers well

Example SNS/SQS message with structured CloudEvents:

Setting CloudEvents in Publication

CloudEvents properties are configured in the Publication when you register producers. The Publication is passed to your message mapper, which can access these properties.

Basic Publication with CloudEvents

Additional CloudEvents Properties

You can set additional CloudEvents properties in the Publication:

Using CloudEvents in Message Mappers

In V10, Brighter passes the Publication to your message mapper, giving you access to CloudEvents properties. However, most users won't need custom mappers anymore thanks to default message mappers.

Default Mappers Handle CloudEvents Automatically

Brighter V10 includes default message mappers that automatically handle CloudEvents:

  • JsonMessageMapper<T>: Uses binary mode CloudEvents (headers)

  • CloudEventJsonMessageMapper<T>: Uses structured mode CloudEvents (JSON body)

If you're using default mappers (recommended), CloudEvents are handled automatically based on your Publication configuration.

Custom Mapper with CloudEvents

If you need a custom mapper (e.g., for transforms), you can access CloudEvents from the Publication:

CloudEvents Across Transports

Brighter maps CloudEvents to transport-specific formats automatically. The transport layer handles the conversion based on the protocol's capabilities.

RabbitMQ (AMQP 0-9-1)

RabbitMQ uses binary mode with CloudEvents mapped to message headers:

See: AMQP Protocol Binding for CloudEvents

Kafka

Kafka uses binary mode with CloudEvents in message headers:

See: Kafka Protocol Binding for CloudEvents

AWS SNS/SQS

AWS SNS/SQS has limited header support, so Brighter uses structured mode:

Azure Service Bus

Azure Service Bus supports binary mode with headers:

See: HTTP Protocol Binding for CloudEvents (Azure Service Bus follows HTTP binding)

CloudEvents Type for Message Routing

One powerful use of CloudEvents is content-based routing using the type attribute. This allows multiple message types on a single channel.

See Dynamic Message Deserialization for details on using CloudEvents type for routing.

Example:

OpenTelemetry Integration

CloudEvents includes extensions for distributed tracing that integrate with OpenTelemetry:

  • traceparent: W3C Trace Context propagation

  • tracestate: Vendor-specific trace information

Brighter automatically propagates OpenTelemetry trace context using CloudEvents distributed tracing extensions. See OpenTelemetry Integration for details.

Claim Check Pattern with DataRef

CloudEvents supports the DataRef extension for the Claim Check pattern, where large payloads are stored externally and only a reference is included in the message.

See Claim Check Pattern for more details.

Breaking Changes

When migrating to V10, be aware of these CloudEvents-related breaking changes:

  1. Message ID: Changed from Guid to string

  2. Correlation ID: Changed from Guid to string

  3. Publication passed to mapper: Message mappers now receive Publication parameter

See the V10 Migration Guide for complete migration instructions.

Best Practices

1. Choose the Right Content Mode

  • Use binary mode for protocols with header support (RabbitMQ, Kafka, Azure Service Bus)

  • Use structured mode for protocols with limited headers (AWS SNS/SQS)

  • Brighter selects the appropriate mode automatically based on the transport

2. Use Meaningful CloudEvents Type

The type attribute should follow reverse-DNS naming:

3. Include Source Context

The source should uniquely identify where the event originated:

4. Use Subject for Fine-Grained Routing

The subject provides additional context in the scope of the source:

5. Leverage Default Mappers

In most cases, use Brighter's default message mappers rather than implementing custom mappers:

Only create custom mappers when you need transform pipelines.

Further Reading

Last updated

Was this helpful?