Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove WithMessageHandler<IHandlerAsync<T>> #624

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 0 additions & 40 deletions src/JustSaying/JustSayingFluently.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,46 +250,6 @@ public IFluentSubscription IntoQueue(string queueName)
return this;
}

/// <summary>
/// Set message handlers for the given topic
/// </summary>
/// <typeparam name="T">Message type to be handled</typeparam>
/// <param name="handler">Handler for the message type</param>
/// <returns></returns>
public IHaveFulfilledSubscriptionRequirements WithMessageHandler<T>(IHandlerAsync<T> handler) where T : Message
{
if (handler == null)
{
throw new ArgumentNullException(nameof(handler));
}

if (_serializationFactory == null)
{
throw new InvalidOperationException($"No {nameof(IMessageSerializationFactory)} has been configured.");
}

// TODO - Subscription listeners should be just added once per queue,
// and not for each message handler
var thing = _subscriptionConfig.SubscriptionType == SubscriptionType.PointToPoint
? PointToPointHandler<T>()
: TopicHandler<T>();

Bus.SerializationRegister.AddSerializer<T>(_serializationFactory.GetSerializer<T>());

foreach (var region in Bus.Config.Regions)
{
Bus.AddMessageHandler(region, _subscriptionConfig.QueueName, () => handler);
}

_log.LogInformation(
"Added a message handler of type '{HandlerType}' for message type '{MessageType}' on queue '{QueueName}'.",
handler.GetType(),
typeof(T),
_subscriptionConfig.QueueName);

return thing;
}

public IHaveFulfilledSubscriptionRequirements WithMessageHandler<T>(IHandlerResolver handlerResolver) where T : Message
{
if (_serializationFactory == null)
Expand Down
25 changes: 0 additions & 25 deletions src/JustSaying/JustSayingFluentlyExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
using System;
using System.Collections.Generic;
using JustSaying.AwsTools;
using JustSaying.AwsTools.QueueCreation;
using JustSaying.Messaging.MessageHandling;
using JustSaying.Messaging.MessageSerialization;
using JustSaying.Messaging.Monitoring;
using JustSaying.Models;

namespace JustSaying
{
Expand Down Expand Up @@ -62,27 +59,5 @@ public static IFluentSubscription IntoDefaultQueue(this ISubscriberIntoQueue sub
{
return subscriber.IntoQueue(string.Empty);
}

public static IHaveFulfilledSubscriptionRequirements WithMessageHandlers<T>(
this IFluentSubscription sub, params IHandlerAsync<T>[] handlers) where T : Message
{
if (handlers == null)
{
throw new ArgumentNullException(nameof(handlers));
}

if (handlers.Length == 0)
{
throw new ArgumentException("No message handlers specified.", nameof(handlers));
}

if (handlers.Length == 1)
{
sub.WithMessageHandler(handlers[0]);
}

var listHandler = new ListHandler<T>(handlers);
return sub.WithMessageHandler(listHandler);
}
}
}
2 changes: 0 additions & 2 deletions src/JustSaying/JustSayingFluentlyInterfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ public interface IAmJustSayingFluently : IMessagePublisher

public interface IFluentSubscription
{
IHaveFulfilledSubscriptionRequirements WithMessageHandler<T>(IHandlerAsync<T> handler) where T : Message;

IHaveFulfilledSubscriptionRequirements WithMessageHandler<T>(IHandlerResolver handlerResolver) where T : Message;

IFluentSubscription ConfigureSubscriptionWith(Action<SqsReadConfiguration> config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ public class WhenAddingASubscriptionHandler : JustSayingFluentlyTestBase
private readonly IHandlerAsync<Message> _handler = Substitute.For<IHandlerAsync<Message>>();
private object _response;

protected override void Given()
{
HandlerResolver.ResolveHandler<Message>(new HandlerResolutionContext("queue-name")).Returns(_handler);
}

protected override Task WhenAsync()
{
_response = SystemUnderTest
.WithSqsTopicSubscriber()
.IntoDefaultQueue()
.WithMessageHandler(_handler);
.WithMessageHandler<Message>(HandlerResolver);

return Task.CompletedTask;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@ public class WhenAddingASubscriptionHandlerForAGenericMessage : JustSayingFluent
private readonly IHandlerAsync<JustSayingMessage<MyMessage>> _handler = Substitute.For<IHandlerAsync<JustSayingMessage<MyMessage>>>();
private object _response;

protected override void Given()
{
HandlerResolver.ResolveHandler<JustSayingMessage<MyMessage>>(new HandlerResolutionContext("queue-name")).Returns(_handler);
}

protected override Task WhenAsync()
{
_response = SystemUnderTest
.WithSqsTopicSubscriber()
.IntoDefaultQueue()
.WithMessageHandler(_handler);
.WithMessageHandler<JustSayingMessage<MyMessage>>(HandlerResolver);

return Task.CompletedTask;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Reflection.Metadata;
using System.Threading.Tasks;
using JustSaying.AwsTools.QueueCreation;
using JustSaying.Messaging;
Expand All @@ -16,12 +17,17 @@ public class WhenSubscribingPointToPoint : JustSayingFluentlyTestBase
private readonly IHandlerAsync<Message> _handler = Substitute.For<IHandlerAsync<Message>>();
private object _response;

protected override void Given()
{
HandlerResolver.ResolveHandler<Message>(new HandlerResolutionContext("queue-name")).Returns(_handler);
}

protected override Task WhenAsync()
{
_response = SystemUnderTest
.WithSqsPointToPointSubscriber()
.IntoDefaultQueue()
.WithMessageHandler(_handler);
.WithMessageHandler<Message>(HandlerResolver);

return Task.CompletedTask;
}
Expand Down
1 change: 1 addition & 0 deletions tests/JustSaying.UnitTests/JustSayingFluentlyTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public abstract class JustSayingFluentlyTestBase : IAsyncLifetime
{
protected IPublishConfiguration Configuration;
protected IAmJustSaying Bus;
protected readonly IHandlerResolver HandlerResolver = Substitute.For<IHandlerResolver>();
protected readonly IVerifyAmazonQueues QueueVerifier = Substitute.For<IVerifyAmazonQueues>();
private bool _recordThrownExceptions;
protected Exception ThrownException { get; private set; }
Expand Down