Skip to content

Commit

Permalink
chore(messaging): Added Publish-, Subscribe- and UnsubscribeResponse …
Browse files Browse the repository at this point in the history
…types on both .NET and Typescript side, fixed DesktopAgent ModuleNotFound exception when removing module from the dictionary -running the chart and grid example.
  • Loading branch information
lilla28 committed Feb 28, 2024
1 parent d0c9389 commit 3913e39
Show file tree
Hide file tree
Showing 28 changed files with 538 additions and 69 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions src/fdc3/dotnet/DesktopAgent/src/DesktopAgent/Fdc3DesktopAgent.cs
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)
{
_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.");
}

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
26 changes: 19 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,21 @@ 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)
{
_logger.LogWarning(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
18 changes: 18 additions & 0 deletions src/messaging/dotnet/src/Core/Protocol/Messages/PublishResponse.cs
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

0 comments on commit 3913e39

Please sign in to comment.