Пример #1
0
        public void PublishMessage(ISubscriberCallback subscriber, IPublishableMessage message)
        {
            bool   success        = subscribers.TryGetValue(subscriber, out Queue <IPublishableMessage> queueOfMessages);
            string subscriberName = GetSubscriberName(subscriber);

            if (success)
            {
                queueOfMessages.Enqueue(message);
                //TODO: check this log in particular
                Logger.LogDebug($"Published message [{message}] SUCCESSFYLLY enqueued on Subscriber [{subscriberName}]");
            }
            else if (!subscribers.ContainsKey(subscriber))
            {
                Logger.LogWarn($"Subscriber [{subscriberName}, HasCode: {subscriber.GetHashCode()}] does not exist in collection of all subscribers.");
            }
        }
Пример #2
0
        public bool TryAddSubscriber(ISubscriberCallback subscriber, string subscriberName)
        {
            bool success = subscribers.TryAdd(subscriber, new Queue <IPublishableMessage>());

            subscriberNames.TryAdd(subscriber, subscriberName);

            if (success)
            {
                Logger.LogDebug($"Subscriber [{subscriberName}] SUCCESSFYLLY added to collection of all subscribers.");
            }
            else if (subscribers.ContainsKey(subscriber))
            {
                Logger.LogWarn($"Subscriber [{subscriberName}, HashCode: {subscriber.GetHashCode()}] already exists in collection of all subscibers.");
            }



            return(success);
        }