Skip to content

chore(general): remove deprecated general 'route message' with string #576

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -100,46 +100,6 @@ protected AzureServiceBusMessageRouter(IServiceProvider serviceProvider, AzureSe
/// </summary>
protected AzureServiceBusMessageRouterOptions ServiceBusOptions { get; }

/// <summary>
/// Handle a new <paramref name="message"/> that was received by routing them through registered <see cref="IMessageHandler{TMessage,TMessageContext}"/>s
/// and optionally through an registered <see cref="IFallbackMessageHandler"/> if none of the message handlers were able to process the <paramref name="message"/>.
/// </summary>
/// <param name="message">The message that was received.</param>
/// <param name="messageContext">The context providing more information concerning the processing.</param>
/// <param name="correlationInfo">The information concerning correlation of telemetry and processes by using a variety of unique identifiers.</param>
/// <param name="cancellationToken">The token to cancel the message processing.</param>
/// <exception cref="ArgumentNullException">
/// Thrown when the <paramref name="message"/>, <paramref name="messageContext"/>, or <paramref name="correlationInfo"/> is <c>null</c>.
/// </exception>
/// <exception cref="InvalidOperationException">Thrown when no message handlers or none matching message handlers are found to process the message.</exception>
[Obsolete("Will be removed in v3.0 as only concrete implementations of message routing will be supported from now on")]
public override async Task RouteMessageAsync<TMessageContext>(
string message,
TMessageContext messageContext,
MessageCorrelationInfo correlationInfo,
CancellationToken cancellationToken)
{
var isSuccessful = false;
using (DurationMeasurement measurement = DurationMeasurement.Start())
{
try
{
await base.RouteMessageAsync(message, messageContext, correlationInfo, cancellationToken);
isSuccessful = true;
}
finally
{
Logger.LogServiceBusRequest(
serviceBusNamespace: "<not-available>",
entityName: "<not-available>",
Options.Telemetry.OperationName,
isSuccessful,
measurement,
ServiceBusEntityType.Unknown);
}
}
}

/// <summary>
/// Handle a new <paramref name="message"/> that was received by routing them through registered <see cref="IAzureServiceBusMessageHandler{TMessage}"/>s
/// and optionally through <see cref="IAzureServiceBusFallbackMessageHandler"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Threading;
using System.Threading.Tasks;

namespace Arcus.Messaging.Abstractions.MessageHandling
{
Expand All @@ -10,24 +8,5 @@ namespace Arcus.Messaging.Abstractions.MessageHandling
[Obsolete("Will be removed in v3.0 as only concrete implementations of message routing will be supported from now on")]
public interface IMessageRouter
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we remove the interface entirely ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Step by step, keeping changes separated to reduce ripple effects.

{
/// <summary>
/// Handle a new <paramref name="message"/> that was received by routing them through registered <see cref="IMessageHandler{TMessage,TMessageContext}"/>s
/// and optionally through a registered <see cref="IFallbackMessageHandler"/> if none of the message handlers were able to process the <paramref name="message"/>.
/// </summary>
/// <param name="message">The message that was received.</param>
/// <param name="messageContext">The context providing more information concerning the processing.</param>
/// <param name="correlationInfo">The information concerning correlation of telemetry and processes by using a variety of unique identifiers.</param>
/// <param name="cancellationToken">The token to cancel the message processing.</param>
/// <exception cref="ArgumentNullException">
/// Thrown when the <paramref name="message"/>, <paramref name="messageContext"/>, or <paramref name="correlationInfo"/> is <c>null</c>.
/// </exception>
/// <exception cref="InvalidOperationException">Thrown when no message handlers or none matching message handlers are found to process the message.</exception>
[Obsolete("Will be removed in v3.0 as only concrete implementations of message routing will be supported from now on")]
Task RouteMessageAsync<TMessageContext>(
string message,
TMessageContext messageContext,
MessageCorrelationInfo correlationInfo,
CancellationToken cancellationToken)
where TMessageContext : MessageContext;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,53 +181,6 @@ protected async Task<bool> RouteMessageWithoutFallbackAsync<TMessageContext>(
}
}

/// <summary>
/// Handle a new <paramref name="message"/> that was received by routing them through registered <see cref="IMessageHandler{TMessage,TMessageContext}"/>s
/// and optionally through an registered <see cref="IFallbackMessageHandler"/> if none of the message handlers were able to process the <paramref name="message"/>.
/// </summary>
/// <param name="message">The message that was received.</param>
/// <param name="messageContext">The context providing more information concerning the processing.</param>
/// <param name="correlationInfo">The information concerning correlation of telemetry and processes by using a variety of unique identifiers.</param>
/// <param name="cancellationToken">The token to cancel the message processing.</param>
/// <exception cref="ArgumentNullException">
/// Thrown when the <paramref name="message"/>, <paramref name="messageContext"/>, or <paramref name="correlationInfo"/> is <c>null</c>.
/// </exception>
/// <exception cref="InvalidOperationException">Thrown when no message handlers or none matching message handlers are found to process the message.</exception>
[Obsolete("Will be removed in v3.0 as only concrete implementations of message routing will be supported from now on")]
public virtual async Task RouteMessageAsync<TMessageContext>(
string message,
TMessageContext messageContext,
MessageCorrelationInfo correlationInfo,
CancellationToken cancellationToken)
where TMessageContext : MessageContext
{
if (message is null)
{
throw new ArgumentNullException(nameof(message));
}

if (messageContext is null)
{
throw new ArgumentNullException(nameof(messageContext));
}

if (correlationInfo is null)
{
throw new ArgumentNullException(nameof(correlationInfo));
}

using (IServiceScope serviceScope = ServiceProvider.CreateScope())
#pragma warning disable CS0618 // Type or member is obsolete: will be refactored when moving towards v3.0.
using (LogContext.Push(new MessageCorrelationInfoEnricher(correlationInfo, Options.CorrelationEnricher)))
#pragma warning restore CS0618 // Type or member is obsolete
{
var accessor = serviceScope.ServiceProvider.GetService<IMessageCorrelationInfoAccessor>();
accessor?.SetCorrelationInfo(correlationInfo);

await RouteMessageAsync(serviceScope.ServiceProvider, message, messageContext, correlationInfo, cancellationToken);
}
}

/// <summary>
/// Handle a new <paramref name="message"/> that was received by routing them through registered <see cref="IMessageHandler{TMessage,TMessageContext}"/>s
/// and optionally through an registered <see cref="IFallbackMessageHandler"/> if none of the message handlers were able to process the <paramref name="message"/>.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Newtonsoft.Json;
using Xunit;
using Xunit.Abstractions;
#pragma warning disable 618
Expand Down Expand Up @@ -362,69 +361,6 @@ public void SubtractsMessageHandlers_SelectsAllRegistrations()
Assert.Equal(4, messageHandlers.Count());
}

[Fact]
public async Task CustomMessageHandler_WithContextFilter_UsesFilterDuringSelection()
{
// Arrange
var messageId = Guid.NewGuid().ToString();
var message = new TestMessage { TestProperty = Guid.NewGuid().ToString() };
string messageJson = JsonConvert.SerializeObject(message);
var context = new TestMessageContext(messageId, new Dictionary<string, object>());
var correlationInfo = new MessageCorrelationInfo("operation-id", "transaction-id");
var spyHandler1 = new TestMessageHandler();
var spyHandler2 = new TestMessageHandler();

var collection = new MessageHandlerCollection(new ServiceCollection());
collection.WithMessageHandler<TestMessageHandler, TestMessage, TestMessageContext>(
messageContextFilter: ctx => ctx.MessageId == "some other ID",
implementationFactory: provider => spyHandler2);
collection.WithMessageHandler<TestMessageHandler, TestMessage, TestMessageContext>(
messageContextFilter: ctx => ctx.MessageId == messageId,
implementationFactory: provider => spyHandler1);
collection.WithMessageHandler<TestMessageHandler, TestMessage, TestMessageContext>();
collection.WithMessageHandler<DefaultTestMessageHandler, TestMessage>();

IServiceProvider serviceProvider = collection.Services.BuildServiceProvider();
var router = new TestMessageRouter(serviceProvider, _logger);

// Act
await router.RouteMessageAsync(messageJson, context, correlationInfo, CancellationToken.None);

// Assert
Assert.True(spyHandler1.IsProcessed);
Assert.False(spyHandler2.IsProcessed);
}

[Fact]
public async Task CustomMessageHandler_WithContextFilter_UsesMessageTypeDuringSelection()
{
// Arrange
var spyHandler = new StubTestMessageHandler<Purchase, MessageContext>();

var collection = new MessageHandlerCollection(new ServiceCollection());
collection.WithMessageHandler<StubTestMessageHandler<Order, MessageContext>, Order>();
collection.WithMessageHandler<StubTestMessageHandler<Purchase, TestMessageContext>, Purchase, TestMessageContext>();
collection.WithMessageHandler<StubTestMessageHandler<Purchase, MessageContext>, Purchase>(provider => spyHandler);

IServiceProvider serviceProvider = collection.Services.BuildServiceProvider();
var router = new TestMessageRouter(serviceProvider, _logger);

var purchase = new Purchase
{
CustomerName = _bogusGenerator.Name.FullName(),
Price = _bogusGenerator.Commerce.Price()
};
string purchaseJson = JsonConvert.SerializeObject(purchase);
var context = new MessageContext("message-id", new Dictionary<string, object>());
var correlationInfo = new MessageCorrelationInfo("operation-id", "transaction-id");

// Act
await router.RouteMessageAsync(purchaseJson, context, correlationInfo, CancellationToken.None);

// Assert
Assert.True(spyHandler.IsProcessed);
}

[Fact]
public void WithMultipleMessageHandlers_WithSameMessageType_RegistersBoth()
{
Expand Down
Loading