Exemplo n.º 1
0
        public async Task HandleMessage(Guid clientId, NanoPublishMessage nanoPublishMessage)
        {
            var         tasks          = new List <Task>();
            NanoMessage publishMessage = null;

            List <NanoHandler> nanoSubscribers;


            if (nanoPublishMessage.NanoDocumentId != NanoDocumentId.Empty)
            {
                if (_handlersByDocumentId.TryGetValue(nanoPublishMessage.NanoDocumentId, out nanoSubscribers))
                {
                    publishMessage = nanoPublishMessage.ToNewPublishMessage();
                    //TODO: find a solution elliminating where condition...
                    tasks.AddRange(nanoSubscribers.AsSnapshot().Where(a => a.ClientId != clientId).Select(subscriber => subscriber.HandleMessageAsync(publishMessage)));
                }
            }
            if (_handlersByDocumentId.TryGetValue(NanoDocumentId.Empty, out nanoSubscribers))
            {
                publishMessage = publishMessage ?? nanoPublishMessage.ToNewPublishMessage();
                //TODO: find a solution elliminating where condition...
                tasks.AddRange(nanoSubscribers.AsSnapshot().Where(a => a.ClientId != clientId).Select(subscriber => subscriber.HandleMessageAsync(publishMessage)));
            }

            await TaskHelpers.Iterate(tasks);
        }
Exemplo n.º 2
0
        public Task DistributeAsync(NanoPublishMessage publishMessage)
        {
            Type messageType;

            if (!_messageTypeMap.TryGetValue(publishMessage.MessageTypeName, out messageType))
            {
                return(Task.FromResult(0));
            }

            var message = publishMessage.DeseralizePayload(messageType);

            INanoSubscription nanoSubscription;
            var tasks = new List <Task>(2);

            var key = new NanoSubsciptionKey(messageType, publishMessage.NanoDocumentId);

            if (_subscriptions.TryGetValue(key, out nanoSubscription))
            {
                var task = nanoSubscription.InvokeHandlers(message);
                tasks.Add(task);
            }

            key = new NanoSubsciptionKey(messageType, NanoDocumentId.Empty);
            if (_subscriptions.TryGetValue(key, out nanoSubscription))
            {
                var task = nanoSubscription.InvokeHandlers(message);
                tasks.Add(task);
            }

            return(Task.WhenAll(tasks));
        }
Exemplo n.º 3
0
 private Task PublishAsync(Guid clientId, NanoPublishMessage publishMessage)
 {
     return(_nanoBusService
            .NanoServiceBus
            .GetEventBus(publishMessage.DocumentTypeName)
            .GetMessageBus(publishMessage.MessageTypeName)
            .HandleMessage(clientId, publishMessage));
 }
Exemplo n.º 4
0
        internal Task DistributePublishMessageAsync(NanoPublishMessage publishMessage)
        {
            //distribute nano message local callbacks
            Type documentType;

            if (DocumentTypeMap.TryGetValue(publishMessage.DocumentTypeName, out documentType))
            {
                INanoEventBus nanoEventBus;
                if (NanoEventBusses.TryGetValue(documentType, out nanoEventBus))
                {
                    return(nanoEventBus.DistributeAsync(publishMessage));
                }
            }

            throw new InvalidOperationException();
        }
Exemplo n.º 5
0
        private Task OnReceivedPublishMessageAsync(NanoPublishMessage publishMessage)
        {
            Trace.TraceEvent(TraceEventType.Verbose, 1000, () => "OnReceivedPublishMessageAsync");

            return(NanoBusClient.DistributePublishMessageAsync(publishMessage));
        }