Class IntegrationEventExtensions
- Namespace
- Savvyio.EventDriven.Messaging
- Assembly
- Savvyio.EventDriven.Messaging.dll
Extension methods for the IIntegrationEvent interface.
public static class IntegrationEventExtensions
- Inheritance
-
IntegrationEventExtensions
Examples
The following example shows how to wrap an integration event in a transport-friendly Message<T> by calling ToMessage.
using System;
using Savvyio.EventDriven;
using Savvyio.EventDriven.Messaging;
using Savvyio.Messaging;
namespace ExampleApp.IntegrationMessages;
public sealed class IntegrationEventMessagingExtensionsUsage
{
public IntegrationEventMessagingExtensionsUsage()
{
var integrationEvent = new MemberWelcomeEmailQueued("member-42");
IMessage<MemberWelcomeEmailQueued> message = integrationEvent.ToMessage(
new Uri("https://api.example.com/messages/member-42"),
nameof(MemberWelcomeEmailQueued),
options => options.MessageId = "msg-member-42");
MessageId = message.Id;
Type = message.Type;
Source = message.Source;
}
public string MessageId { get; }
public string Type { get; }
public string Source { get; }
}
public sealed record MemberWelcomeEmailQueued(string MemberId) : IntegrationEvent;
Methods
ToMessage<T>(T, Uri, string, Action<MessageOptions>)
Encloses the specified event to an instance of Message<T>.
public static IMessage<T> ToMessage<T>(this T @event, Uri source, string type, Action<MessageOptions> setup = null) where T : IIntegrationEvent
Parameters
eventTThe payload to attach within the message.
sourceUriThe context that describes the origin of the message.
typestringThe type that describes the type of
eventrelated to the originating occurrence.setupAction<MessageOptions>The MessageOptions which may be configured.
Returns
- IMessage<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
eventcannot be null - or -sourcecannot be null.- ArgumentException
setupfailed to configure an instance of MessageOptions in a valid state.