コード例 #1
0
        protected virtual async ValueTask OnMessageAsync(Message message, CancellationToken cancellationToken)
        {
            var isProcessed = false;

            switch (message)
            {
            case SubscribeMessage sm:
                if (sm.PublisherId != Publisher.Id)
                {
                    break;
                }
                var publication = Publisher.TryGet(sm.PublicationId);
                if (publication == null)
                {
                    break;
                }
                await PublisherImpl
                .SubscribeAsync(Channel, publication, sm, cancellationToken)
                .ConfigureAwait(false);

                isProcessed = true;
                break;

            case UnsubscribeMessage um:
                if (um.PublisherId != Publisher.Id)
                {
                    break;
                }
                publication = Publisher.TryGet(um.PublicationId);
                if (publication == null)
                {
                    break;
                }
                await PublisherImpl
                .UnsubscribeAsync(Channel, publication, cancellationToken)
                .ConfigureAwait(false);

                isProcessed = true;
                break;
            }
            if (!isProcessed && message is PublicationMessage pm)
            {
                var response = new PublicationAbsentsMessage()
                {
                    PublisherId   = pm.PublisherId,
                    PublicationId = pm.PublicationId,
                };
                await Channel.Writer
                .WriteAsync(response, cancellationToken)
                .ConfigureAwait(false);
            }
        }
コード例 #2
0
 protected virtual async ValueTask OnUnsupportedMessage(BridgeMessage message, CancellationToken cancellationToken)
 {
     if (message is ReplicaMessage rm)
     {
         var response = new PublicationAbsentsMessage()
         {
             PublisherId   = rm.PublisherId,
             PublicationId = rm.PublicationId,
         };
         await Channel.Writer
         .WriteAsync(response, cancellationToken)
         .ConfigureAwait(false);
     }
 }