Class AmazonEventBus
- Namespace
- Savvyio.Extensions.SimpleQueueService.EventDriven
- Assembly
- Savvyio.Extensions.SimpleQueueService.dll
Provides a default implementation of the AmazonBus<TRequest> class tailored for messages holding an IIntegrationEvent implementation.
public class AmazonEventBus : AmazonBus<IIntegrationEvent>, IConfigurable<AmazonMessageOptions>, IPublishSubscribeChannel<IIntegrationEvent>, IPublisher<IIntegrationEvent>, ISubscriber<IIntegrationEvent>, IHealthCheckProvider<IAmazonSimpleNotificationService>
- Inheritance
-
AmazonEventBus
- Implements
-
IHealthCheckProvider<IAmazonSimpleNotificationService>
- Derived
- Inherited Members
Examples
AmazonEventBus publishes and subscribes to integration events through Amazon SNS/SQS. Configure it with AmazonEventBusOptions and use it as IPublishSubscribeChannel<IIntegrationEvent>.
using System;
using Amazon;
using Amazon.Runtime;
using Savvyio.EventDriven;
using Savvyio.Extensions.SimpleQueueService.EventDriven;
using Savvyio.Messaging;
namespace ExampleApp;
public class SnsEventBusConfig
{
public static AmazonEventBusOptions CreateOptions() => new AmazonEventBusOptions { Credentials = new AnonymousAWSCredentials(), Endpoint = RegionEndpoint.EUWest1, SourceQueue = new Uri("https://sqs.eu-west-1.amazonaws.com/123456789012/events") };
public static IPublishSubscribeChannel<IIntegrationEvent> AsChannel(AmazonEventBus b) => b;
}
Constructors
AmazonEventBus(IMarshaller, AmazonEventBusOptions)
Initializes a new instance of the AmazonEventBus class.
public AmazonEventBus(IMarshaller marshaller, AmazonEventBusOptions options)
Parameters
marshallerIMarshallerThe IMarshaller that is used when converting IIntegrationEvent implementations to messages.
optionsAmazonEventBusOptionsThe AmazonEventBusOptions used to configure this instance.
Exceptions
- ArgumentNullException
marshallercannot be null - or -optionscannot be null.- ArgumentException
optionsare not in a valid state.
Methods
CreateSimpleNotificationServiceClient()
Creates the AWS SNS client used by publish operations.
protected virtual IAmazonSimpleNotificationService CreateSimpleNotificationServiceClient()
Returns
- IAmazonSimpleNotificationService
An Amazon.SimpleNotificationService.IAmazonSimpleNotificationService client configured from Options.
GetHealthCheckTarget()
Returns a new Amazon.SimpleNotificationService.IAmazonSimpleNotificationService client instance configured for health probing of the underlying Amazon SNS service.
public IAmazonSimpleNotificationService GetHealthCheckTarget()
Returns
- IAmazonSimpleNotificationService
An Amazon.SimpleNotificationService.IAmazonSimpleNotificationService client instance used to probe the health status of the notification service.
PublishAsync(IMessage<IIntegrationEvent>, Action<AsyncOptions>)
Publishes the specified event asynchronous using Publish-Subscribe Channel/Pub-Sub MEP.
public override Task PublishAsync(IMessage<IIntegrationEvent> @event, Action<AsyncOptions> setup = null)
Parameters
eventIMessage<IIntegrationEvent>The event to publish.
setupAction<AsyncOptions>The AsyncOptions which may be configured.
Returns
SubscribeAsync(Func<IMessage<IIntegrationEvent>, CancellationToken, Task>, Action<SubscribeAsyncOptions>)
Subscribe to one or more message(s) asynchronous using Publish-Subscribe Channel/Pub-Sub MEP.
public override Task SubscribeAsync(Func<IMessage<IIntegrationEvent>, CancellationToken, Task> asyncHandler, Action<SubscribeAsyncOptions> setup = null)
Parameters
asyncHandlerFunc<IMessage<IIntegrationEvent>, CancellationToken, Task>The function delegate that will handle the message.
setupAction<SubscribeAsyncOptions>The SubscribeAsyncOptions which may be configured.