Skip to content

Commit

Permalink
Fix compatibility warnings
Browse files Browse the repository at this point in the history
Refactor things to make the public API analyser happy.
  • Loading branch information
martincostello committed Feb 2, 2024
1 parent 07fa93c commit 366fd64
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 31 deletions.
25 changes: 6 additions & 19 deletions src/JustSaying/AwsTools/MessageHandling/SnsMessagePublisher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public class SnsMessagePublisher : IMessagePublisher, IMessageBatchPublisher, II
private readonly IMessageSerializationRegister _serializationRegister;
private readonly IMessageSubjectProvider _messageSubjectProvider;
private readonly Func<Exception, Message, bool> _handleException;
private readonly Func<Exception, IReadOnlyCollection<Message>, bool> _handleBatchException;
private readonly ILogger _logger;

public Func<Exception, IReadOnlyCollection<Message>, bool> HandleBatchException { get; set; }
public Action<MessageResponse, Message> MessageResponseLogger { get; set; }
public Action<MessageBatchResponse, IReadOnlyCollection<Message>> MessageBatchResponseLogger { get; set; }
public string Arn { get; internal set; }
Expand All @@ -40,25 +40,12 @@ public class SnsMessagePublisher : IMessagePublisher, IMessageBatchPublisher, II
ILoggerFactory loggerFactory,
IMessageSubjectProvider messageSubjectProvider,
Func<Exception, Message, bool> handleException = null)
: this(topicArn, client, serializationRegister, loggerFactory, messageSubjectProvider, handleException, null)
{
}

public SnsMessagePublisher(
string topicArn,
IAmazonSimpleNotificationService client,
IMessageSerializationRegister serializationRegister,
ILoggerFactory loggerFactory,
IMessageSubjectProvider messageSubjectProvider,
Func<Exception, Message, bool> handleException,
Func<Exception, IReadOnlyCollection<Message>, bool> handleBatchException)
{
Arn = topicArn;
Client = client;
_serializationRegister = serializationRegister;
_logger = loggerFactory.CreateLogger("JustSaying.Publish");
_handleException = handleException;
_handleBatchException = handleBatchException;
_messageSubjectProvider = messageSubjectProvider;
}

Expand All @@ -85,10 +72,7 @@ public async Task PublishAsync(Message message, PublishMetadata metadata, Cancel
}
}

using (_logger.BeginScope(new Dictionary<string, object>
{
["AwsRequestId"] = response?.MessageId
}))
using (_logger.BeginScope(new Dictionary<string, object> { ["AwsRequestId"] = response?.MessageId }))
{
_logger.LogInformation(
"Published message {MessageId} of type {MessageType} to {DestinationType} '{MessageDestination}'.",
Expand Down Expand Up @@ -157,11 +141,13 @@ private static MessageAttributeValue BuildMessageAttributeValue(Messaging.Messag
};
}

/// <inheritdoc/>
public virtual InterrogationResult Interrogate()
{
return new InterrogationResult(new { Arn });
}

/// <inheritdoc/>
public async Task PublishAsync(IEnumerable<Message> messages, PublishBatchMetadata metadata, CancellationToken cancellationToken)
{
int size = metadata?.BatchSize ?? JustSayingConstants.MaximumSnsBatchSize;
Expand Down Expand Up @@ -245,7 +231,8 @@ public async Task PublishAsync(IEnumerable<Message> messages, PublishBatchMetada
}
}

private bool ClientExceptionHandler(Exception ex, IReadOnlyCollection<Message> messages) => _handleBatchException?.Invoke(ex, messages) ?? false;
private bool ClientExceptionHandler(Exception ex, IReadOnlyCollection<Message> messages)
=> HandleBatchException?.Invoke(ex, messages) ?? false;

private PublishBatchRequest BuildPublishBatchRequest(Message[] messages, PublishMetadata metadata)
{
Expand Down
6 changes: 4 additions & 2 deletions src/JustSaying/Fluent/TopicAddressPublicationBuilder`1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ public void Configure(JustSayingBus bus, IAwsClientFactoryProxy proxy, ILoggerFa
bus.SerializationRegister,
loggerFactory,
config.MessageSubjectProvider,
_exceptionHandler,
_exceptionBatchHandler);
_exceptionHandler)
{
HandleBatchException = _exceptionBatchHandler,
};

bus.AddMessagePublisher<T>(eventPublisher);

Expand Down
4 changes: 2 additions & 2 deletions src/JustSaying/Messaging/IMessageBatchPublisher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ public interface IMessageBatchPublisher : IInterrogable, IStartable
/// </summary>
/// <param name="publisher">The publisher to use.</param>
/// <param name="messages">The message(s) to publish.</param>
/// <param name="metadata">The message batch metadata.</param>
/// <param name="metadata">The optional message batch metadata.</param>
/// <param name="cancellationToken">The optional cancellation token to use.</param>
/// <returns>
/// A <see cref="Task"/> representing the asynchronous operation to publish the messages.
/// </returns>
Task PublishAsync(IEnumerable<Message> messages, PublishBatchMetadata metadata, CancellationToken cancellationToken = default);
Task PublishAsync(IEnumerable<Message> messages, PublishBatchMetadata metadata = default, CancellationToken cancellationToken = default);
}
2 changes: 1 addition & 1 deletion src/JustSaying/Messaging/MessagePublisherExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ await publisher.PublishAsync(message, null, cancellationToken)
/// A <see cref="Task"/> representing the asynchronous operation to publish the messages.
/// </returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="publisher"/> is <see langword="null"/>.</exception>"
public static Task PublishAsync(this IMessageBatchPublisher publisher, IEnumerable<Message> messages, CancellationToken cancellationToken = default)
public static Task PublishAsync(this IMessageBatchPublisher publisher, IEnumerable<Message> messages, CancellationToken cancellationToken)
{
if (publisher == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public async Task Then_The_Handler_Is_Resolved_ForMultiMessage()
future.ExpectedMessageCount = 10;
var messages = new List<Message>();
for (var i = 0; i < future.ExpectedMessageCount; i++)
for (int i = 0; i < future.ExpectedMessageCount; i++)
{
messages.Add(new OrderPlaced(Guid.NewGuid().ToString()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ private protected override Task<SnsMessagePublisher> CreateSystemUnderTestAsync(
Sns,
_serializationRegister,
NullLoggerFactory.Instance,
Substitute.For<IMessageSubjectProvider>(),
null,
(_, _) => true);
Substitute.For<IMessageSubjectProvider>())
{
HandleBatchException = (_, _) => true,
};

return Task.FromResult(topic);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ private protected override Task<SnsMessagePublisher> CreateSystemUnderTestAsync(
Sns,
_serializationRegister,
NullLoggerFactory.Instance,
Substitute.For<IMessageSubjectProvider>(),
null,
(_, _) => false);
Substitute.For<IMessageSubjectProvider>())
{
HandleBatchException = (_, _) => false,
};

return Task.FromResult(topic);
}
Expand Down

0 comments on commit 366fd64

Please sign in to comment.