Skip to content

MigrationTo20

Denys Zaliznyak edited this page Mar 7, 2023 · 1 revision

First of all, the process of creating a MetaPubSub object has changed - now it needs to be created in two stages: first create a local MetaPubSub, then create a PubSubPipeServer/PubSubPipeClient wrapper to provide inter-process communication:

        // Creating the server hub.
        var serverHub = new MetaPubSub();
        using var pipeServer = new PubSubPipeServer("Meta", serverHub);
        // Client hub creation.
        var clientHub = new MetaPubSub();
        using var pipeClient = new PubSubPipeClient("Meta", clientHub);

To establish a connection, you need to start the server and connect clients to it:

        // Starting the hub as a server named 'Meta'.
        pipeServer.StartServer();
        // Connecting to the remote server.
        await pipeClient.ConnectToServer();

Message subscription is also divided into two stages - you need to subscribe separately to the local MetaPubSub and to the PubSubPipeServer:

        // Subscribing to MyMessage on the server and locally
        await pipeClient.SubscribeOnServer<MyMessage>();
        clientHub.Subscribe<MyMessage>(Handler);

Note that SubscribeOnServer does not contain a message handler as a parameter. It simply informs the server that all messages of type MyMessage should be sent to this client. And already on the client side, those who subscribed to the local MetaPubSub will receive the corresponding message. The SubscribeOnServer method only needs to be called oncå, regardless of how many subscribers were registered with Subscribe method call. If you call it again, UnsubscribeOnServer should be called for each SubscribeOnServer call.

The Publish and PublishOnServer methods now have an optional PubSubOptions parameter. Previously, options for sending were set in the properties of the message itself, which required inheriting from the IPubSubMessage interface. Now options are passed separately, and IPubSubMessage has been removed.

Clone this wiki locally