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

chore(messaging): Added Publish-, Subscribe- and UnsubscribeResponse types on both .NET and Typescript side, fixed DesktopAgent ModuleNotFound exception when removing module from the dictionary -running the chart and grid example. #471

Merged
merged 4 commits into from
Mar 8, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -695,10 +695,17 @@ private Dictionary<string, AppIntent> GetAppIntentsFromIntentMetadaCollection(

private Task RemoveModuleAsync(IModuleInstance instance)
{
var fdc3InstanceId = GetFdc3InstanceId(instance);
if (!_runningModules.TryRemove(new(fdc3InstanceId), out _))
try
{
var fdc3InstanceId = GetFdc3InstanceId(instance);
if (!_runningModules.TryRemove(new(fdc3InstanceId), out _))
{
_logger.LogError($"Could not remove the closed window with instanceId: {fdc3InstanceId}.");
}
}
catch (Fdc3DesktopAgentException exception)
lilla28 marked this conversation as resolved.
Show resolved Hide resolved
{
_logger.LogError($"Could not remove the closed window with instanceId: {fdc3InstanceId}.");
_logger.LogError(exception, $"Exception thrown while removing module: {instance.Manifest.Id}, {instance.Manifest.Name} from running instances in FDC3DesktopAgent.");
lilla28 marked this conversation as resolved.
Show resolved Hide resolved
}

return Task.CompletedTask;
Expand Down
1 change: 0 additions & 1 deletion src/messaging/dotnet/examples/TestServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using MorganStanley.ComposeUI.Messaging.Server.WebSocket;

namespace TestServer;

Expand Down
29 changes: 22 additions & 7 deletions src/messaging/dotnet/src/Client/Client/MessageRouterClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,18 @@ public ValueTask<IAsyncDisposable> SubscribeAsync(
return SubscribeAsyncCore(GetTopic(topic), subscriber, cancellationToken);
}

public ValueTask PublishAsync(
public async ValueTask PublishAsync(
string topic,
MessageBuffer? payload = null,
PublishOptions options = default,
CancellationToken cancellationToken = default)
{
Protocol.Topic.Validate(topic);

return SendMessageAsync(
await SendRequestAsync(
new PublishMessage
{
RequestId = GenerateRequestId(),
Topic = topic,
Payload = payload,
CorrelationId = options.CorrelationId
Expand Down Expand Up @@ -616,9 +617,10 @@ private async ValueTask<IAsyncDisposable> SubscribeAsyncCore(

try
{
await SendMessageAsync(
await SendRequestAsync(
new SubscribeMessage
{
RequestId = GenerateRequestId(),
Topic = topic.Name
},
cancellationToken);
Expand Down Expand Up @@ -797,11 +799,24 @@ async Task CloseTopics()
}
}

private ValueTask TryUnsubscribe(Topic topic)
private async ValueTask TryUnsubscribe(Topic topic)
{
return topic.CanUnsubscribe
? SendMessageAsync(new UnsubscribeMessage {Topic = topic.Name}, CancellationToken.None)
: default;
var requestId = GenerateRequestId();

try
{
if (topic.CanUnsubscribe)
{
await SendRequestAsync(new UnsubscribeMessage { RequestId = requestId, Topic = topic.Name }, CancellationToken.None);
}
}
catch (MessageRouterException exception)
{
if (_logger.IsEnabled(LogLevel.Error))
{
_logger.LogError(exception, $"Exception thrown while unsubscribing, topic: {topic.Name}, request id: {requestId}.");
}
}
}

private void OnConnectStart()
Expand Down
3 changes: 3 additions & 0 deletions src/messaging/dotnet/src/Core/Protocol/Messages/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ public static Type ResolveMessageType(MessageType messageType)
MessageType.Connect => typeof(ConnectRequest),
MessageType.ConnectResponse => typeof(ConnectResponse),
MessageType.Subscribe => typeof(SubscribeMessage),
MessageType.SubscribeResponse => typeof(SubscribeResponse),
MessageType.Unsubscribe => typeof(UnsubscribeMessage),
MessageType.UnsubscribeResponse => typeof(UnsubscribeResponse),
MessageType.Publish => typeof(PublishMessage),
MessageType.PublishResponse => typeof(PublishResponse),
MessageType.Topic => typeof(TopicMessage),
MessageType.Invoke => typeof(InvokeRequest),
MessageType.RegisterService => typeof(RegisterServiceRequest),
Expand Down
15 changes: 12 additions & 3 deletions src/messaging/dotnet/src/Core/Protocol/Messages/MessageType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,30 @@ public enum MessageType : int
/// </summary>
Subscribe,

// TODO: SubscribeResponse
/// <summary>
/// Server confirms that the client subscribed.
/// </summary>
SubscribeResponse,

/// <summary>
/// Client unsubscribes from a topic.
/// </summary>
Unsubscribe,

// TODO: UnsubscribeResponse
/// <summary>
/// Server confirms that the client unsubscribed.
/// </summary>
UnsubscribeResponse,

/// <summary>
/// Client publishes a message to a topic.
/// </summary>
Publish,

// TODO: PublishResponse
/// <summary>
/// Server confirms that the message was published to a topic by the client.
/// </summary>
PublishResponse,

/// <summary>
/// Server notifies client of a message from a subscribed topic.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace MorganStanley.ComposeUI.Messaging.Protocol.Messages;

public sealed class PublishMessage : Message
public sealed class PublishMessage : AbstractRequest<PublishResponse>
{
public override MessageType Type => MessageType.Publish;
public string Topic { get; init; } = null!;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Morgan Stanley makes this available to you under the Apache License,
// Version 2.0 (the "License"). You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0.
//
// See the NOTICE file distributed with this work for additional information
// regarding copyright ownership. Unless required by applicable law or agreed
// to in writing, software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
// or implied. See the License for the specific language governing permissions
// and limitations under the License.

namespace MorganStanley.ComposeUI.Messaging.Protocol.Messages;

public class PublishResponse : AbstractResponse
{
public override MessageType Type => MessageType.PublishResponse;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace MorganStanley.ComposeUI.Messaging.Protocol.Messages;

public sealed class SubscribeMessage : Message
public sealed class SubscribeMessage : AbstractRequest<SubscribeResponse>
{
public override MessageType Type => MessageType.Subscribe;
public string Topic { get; init; } = null!;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Morgan Stanley makes this available to you under the Apache License,
// Version 2.0 (the "License"). You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0.
//
// See the NOTICE file distributed with this work for additional information
// regarding copyright ownership. Unless required by applicable law or agreed
// to in writing, software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
// or implied. See the License for the specific language governing permissions
// and limitations under the License.

namespace MorganStanley.ComposeUI.Messaging.Protocol.Messages;

public class SubscribeResponse : AbstractResponse
{
public override MessageType Type => MessageType.SubscribeResponse;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace MorganStanley.ComposeUI.Messaging.Protocol.Messages;

public sealed class UnsubscribeMessage : Message
public sealed class UnsubscribeMessage : AbstractRequest<UnsubscribeResponse>
{
public override MessageType Type => MessageType.Unsubscribe;
public string Topic { get; init; } = null!;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Morgan Stanley makes this available to you under the Apache License,
// Version 2.0 (the "License"). You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0.
//
// See the NOTICE file distributed with this work for additional information
// regarding copyright ownership. Unless required by applicable law or agreed
// to in writing, software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
// or implied. See the License for the specific language governing permissions
// and limitations under the License.

namespace MorganStanley.ComposeUI.Messaging.Protocol.Messages;

public class UnsubscribeResponse : AbstractResponse
{
public override MessageType Type => MessageType.UnsubscribeResponse;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
Expand All @@ -22,7 +22,6 @@

<ItemGroup>
<ProjectReference Include="../Core/MorganStanley.ComposeUI.Messaging.Core.csproj" />
<ProjectReference Include="..\..\..\..\module-loader\dotnet\src\MorganStanley.ComposeUI.ModuleLoader.Abstractions\MorganStanley.ComposeUI.ModuleLoader.Abstractions.csproj" />
</ItemGroup>

</Project>
Loading
Loading