Class MessageExtensions
- Namespace
- Savvyio.EventDriven.Messaging.CloudEvents
- Assembly
- Savvyio.EventDriven.Messaging.dll
Extension methods for the IMessage<T> interface.
public static class MessageExtensions
- Inheritance
-
MessageExtensions
Examples
This example shows how to convert a message envelope into a CloudEvents-compliant envelope before publishing it externally.
using System;
using Savvyio;
using Savvyio.EventDriven;
using Savvyio.EventDriven.Messaging.CloudEvents;
using Savvyio.Messaging;
namespace ExampleApp;
public sealed class CloudEventMessageExtensionsExample
{
public ICloudEvent<MemberCreatedEvent> Convert()
{
var message = new Message<MemberCreatedEvent>("msg-42", new Uri("https://api.example.com/members"), "members.created", new MemberCreatedEvent("MEM-42"));
return message.ToCloudEvent();
}
}
public sealed record MemberCreatedEvent(string MemberId) : Request, IIntegrationEvent;
Methods
ToCloudEvent<T>(IMessage<T>, string)
Converts the specified message to an ICloudEvent<T> equivalent.
public static ICloudEvent<T> ToCloudEvent<T>(this IMessage<T> message, string specversion = null) where T : IIntegrationEvent
Parameters
messageIMessage<T>The payload to attach within the message.
specversionstringThe version of the CloudEvents specification which the event uses.
Returns
- ICloudEvent<T>
An instance of Message<T> constraint to the IIntegrationEvent interface.
Type Parameters
TThe type of the payload constraint to the IIntegrationEvent interface.
Exceptions
- ArgumentNullException
messagecannot be null.