Table of Contents

CloudEvent<T> Class

Definition

Namespace
Savvyio.EventDriven.Messaging.CloudEvents
Assemblies
Savvyio.EventDriven.Messaging.dll
Source
src/Savvyio.EventDriven.Messaging/CloudEvents/CloudEvent.cs

Provides a default implementation of the ICloudEvent<T> interface.

public record CloudEvent<T> : CloudEvent, IEquatable<Acknowledgeable>, IEquatable<CloudEvent>, ICloudEvent<T>, IMessage<T>, IAcknowledgeable, IDictionary<string, object>, ICollection<KeyValuePair<string, object>>, IEnumerable<KeyValuePair<string, object>>, IEnumerable, IEquatable<CloudEvent<T>> where T : IIntegrationEvent

Type Parameters

T

The type of the payload constraint to the IIntegrationEvent interface.

Inheritance
CloudEvent<T>
Implements
Derived
Inherited Members
Extension Methods

Examples

This example shows how to convert a transport message into a concrete CloudEvent envelope and add extension attributes before publishing it. The explicit CloudEvent type is then available for downstream inspection of specversion, payload, and custom partition metadata.

using System;
using Savvyio;
using Savvyio.EventDriven;
using Savvyio.EventDriven.Messaging.CloudEvents;
using Savvyio.Messaging;

namespace ExampleApp;

public sealed class CloudEventExample
{
    public string Create()
    {
        var message = new Message<MemberCreatedEvent>("msg-42", new Uri("https://api.example.com/members"), "members.created", new MemberCreatedEvent("MEM-42"));
        var cloudEvent = (CloudEvent<MemberCreatedEvent>)message.ToCloudEvent();
        cloudEvent["partitionkey"] = "members";
        return $"{cloudEvent.Specversion}:{cloudEvent["partitionkey"]}";
    }
}

public sealed record MemberCreatedEvent(string MemberId) : Request, IIntegrationEvent;

Constructors

Name Description
CloudEvent(IMessage<T>, string)

Initializes a new instance of the CloudEvent<T> class.

Properties

Name Description
Data

Gets the event payload.

this[string]

Gets or sets the element with the specified key.

Methods

Name Description
Add(string, object)

Adds an element with the provided key and value to the CloudEvent.

Clear()

Removes all items from the CloudEvent.

ContainsKey(string)

Determines whether the CloudEvent contains an element with the specified key.

Remove(string)

Removes the element with the specified key from the CloudEvent.

TryGetValue(string, out object)

Gets the value associated with the specified key.

See Also