Skip to content

Commit

Permalink
Merge pull request #461 from ztanczos/remove_message_scope
Browse files Browse the repository at this point in the history
Remove scoping feature from Message Router
  • Loading branch information
ztanczos authored Feb 8, 2024
2 parents 0f7445d + c4c289c commit baca61f
Show file tree
Hide file tree
Showing 28 changed files with 6 additions and 390 deletions.
4 changes: 0 additions & 4 deletions src/messaging/dotnet/src/Client/Client/MessageRouterClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ public ValueTask PublishAsync(
{
Topic = topic,
Payload = payload,
Scope = options.Scope,
CorrelationId = options.CorrelationId
},
cancellationToken);
Expand All @@ -100,7 +99,6 @@ public ValueTask PublishAsync(
RequestId = GenerateRequestId(),
Endpoint = endpoint,
Payload = payload,
Scope = options.Scope,
CorrelationId = options.CorrelationId,
};

Expand Down Expand Up @@ -370,7 +368,6 @@ private void HandleInvokeRequest(InvokeRequest message)
new MessageContext
{
SourceId = message.SourceId!,
Scope = message.Scope,
CorrelationId = message.CorrelationId,
});
Expand Down Expand Up @@ -446,7 +443,6 @@ private void HandleTopicMessage(Protocol.Messages.TopicMessage message)
new MessageContext
{
SourceId = message.SourceId,
Scope = message.Scope,
CorrelationId = message.CorrelationId
});

Expand Down
3 changes: 0 additions & 3 deletions src/messaging/dotnet/src/Core/Exceptions/ThrowHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ public static MessageRouterException InvalidTopic(string topic) =>
public static MessageRouterException UnknownEndpoint(string endpoint) =>
new(MessageRouterErrors.UnknownEndpoint, $"Unknown endpoint: {endpoint}");

public static MessageRouterException UnknownClient(string clientId) =>
new(MessageRouterErrors.UnknownClient, $"Unknown client: {clientId}");

public static MessageRouterException ConnectionClosed() =>
new(MessageRouterErrors.ConnectionClosed, "The connection has been closed");

Expand Down
1 change: 0 additions & 1 deletion src/messaging/dotnet/src/Core/InvokeOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@ namespace MorganStanley.ComposeUI.Messaging;

public readonly record struct InvokeOptions
{
public MessageScope Scope { get; init; }
public string? CorrelationId { get; init; }
}
5 changes: 0 additions & 5 deletions src/messaging/dotnet/src/Core/MessageContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ public sealed class MessageContext
/// </summary>
public string SourceId { get; init; } = "";

/// <summary>
/// Gets the scope of the message.
/// </summary>
public MessageScope Scope { get; init; }

/// <summary>
/// Gets the correlation ID of the message, if there's one.
/// </summary>
Expand Down
5 changes: 0 additions & 5 deletions src/messaging/dotnet/src/Core/MessageRouterErrors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ public static class MessageRouterErrors
/// </summary>
public const string UnknownEndpoint = "UnknownEndpoint";

/// <summary>
/// The scope of the request contains an unknown client ID.
/// </summary>
public const string UnknownClient = "UnknownClient";

/// <summary>
/// Client side error that occurs when user code tries to call a method after closing the connection.
/// </summary>
Expand Down
103 changes: 0 additions & 103 deletions src/messaging/dotnet/src/Core/MessageScope.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static class JsonMessageSerializer
new()
{
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
Converters = { new MessageConverter(), new MessageBufferConverter(), new MessageScopeConverter(), new JsonStringEnumConverter() },
Converters = { new MessageConverter(), new MessageBufferConverter(), new JsonStringEnumConverter() },
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
};

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public sealed class InvokeRequest : AbstractRequest<InvokeResponse>
{
public override MessageType Type => MessageType.Invoke;
public string Endpoint { get; init; } = null!;
public MessageScope Scope { get; init; }
public MessageBuffer? Payload { get; init; }
public string? SourceId { get; init; }
public string? CorrelationId { get; init; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@ public sealed class PublishMessage : Message
public override MessageType Type => MessageType.Publish;
public string Topic { get; init; } = null!;
public MessageBuffer? Payload { get; init; }
public MessageScope Scope { get; init; }
public string? CorrelationId { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public sealed class TopicMessage : Message
public override MessageType Type => MessageType.Topic;
public string Topic { get; init; } = null!;
public MessageBuffer? Payload { get; init; }
public MessageScope Scope { get; init; }
public string SourceId { get; init; } = null!;
public string? CorrelationId { get; init; }
}
1 change: 0 additions & 1 deletion src/messaging/dotnet/src/Core/PublishOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ namespace MorganStanley.ComposeUI.Messaging;

public readonly record struct PublishOptions
{
public MessageScope Scope { get; init; }
public string? CorrelationId { get; init; }

// TODO: Wait for delivery
Expand Down
12 changes: 1 addition & 11 deletions src/messaging/dotnet/src/Server/Server/MessageRouterServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,7 @@ private async Task HandleInvokeRequest(
{
Client? serviceClient = null;

if (message.Scope.IsClientId)
{
var clientId = message.Scope.GetClientId()!;

if (!_clients.TryGetValue(clientId, out serviceClient))
{
throw ThrowHelper.UnknownClient(clientId);
}
}
else if (!_serviceRegistrations.TryGetValue(message.Endpoint, out var serviceClientId)
if (!_serviceRegistrations.TryGetValue(message.Endpoint, out var serviceClientId)
|| !_clients.TryGetValue(serviceClientId, out serviceClient))
{
throw ThrowHelper.UnknownEndpoint(message.Endpoint);
Expand Down Expand Up @@ -242,7 +233,6 @@ private async Task HandlePublishMessage(
{
Topic = message.Topic,
Payload = message.Payload,
Scope = message.Scope,
SourceId = client.ClientId,
CorrelationId = message.CorrelationId,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ await _messageRouter.PublishAsync(
"test-topic",
"test-payload",
new PublishOptions
{CorrelationId = "test-correlation-id", Scope = MessageScope.FromClientId("other-client")});
{CorrelationId = "test-correlation-id"});


await WaitForCompletionAsync();
Expand All @@ -165,8 +165,7 @@ await _messageRouter.PublishAsync(
msg => msg.Topic == "test-topic"
&& msg.Payload != null
&& msg.Payload.GetString() == "test-payload"
&& msg.CorrelationId == "test-correlation-id"
&& msg.Scope == MessageScope.FromClientId("other-client"));
&& msg.CorrelationId == "test-correlation-id");
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,30 +93,6 @@ public SerializeDeserializeTheoryData()
RequestId = "testRequestId",
});

Add(
new InvokeRequest
{
Endpoint = "testEndpoint",
RequestId = "testRequestId",
Scope = default,
});

Add(
new InvokeRequest
{
Endpoint = "testEndpoint",
RequestId = "testRequestId",
Scope = MessageScope.Parse(""),
});

Add(
new InvokeRequest
{
Endpoint = "testEndpoint",
RequestId = "testRequestId",
Scope = MessageScope.Parse("testScope"),
});

Add(
new InvokeResponse
{
Expand All @@ -136,7 +112,6 @@ public SerializeDeserializeTheoryData()
{
Topic = "testTopic",
Payload = MessageBuffer.Create("testPayload"),
Scope = default,
CorrelationId = "testCorrelationId",
});

Expand Down
Loading

0 comments on commit baca61f

Please sign in to comment.