Ejemplo n.º 1
0
        public void Publish <TMessage>(TMessage message)
        {
            var sw    = Stopwatch.StartNew();
            var topic = _topicNameProvider.Get <TMessage>();

            var subscribers = _subscriptionAgent.GetSubscribers(topic);

            if (subscribers != null && subscribers.Any())
            {
                foreach (var subscriber in subscribers)
                {
                    var payload = JsonConvert.SerializeObject(message);
                    _publishingAgent.PublishToSubscriber(subscriber.Name, topic, payload);
                }
            }
            else
            {
                _messagingLogger.Debug($"no subsriptions for {topic}");
            }
            _messagingLogger.Debug($"{topic} sent in {sw.ElapsedMilliseconds}");
        }
Ejemplo n.º 2
0
        ///<inheritdoc/>
        public void Publish(string topic, object message, Ack ack = Ack.Master)
        {
            var sw      = Stopwatch.StartNew();
            var payload = JsonConvert.SerializeObject(message);

            var subscribers = _subscriptionAgent.GetSubscribers(topic);

            if (subscribers != null && subscribers.Any())
            {
                foreach (var subscriber in subscribers)
                {
                    _publishingAgent.PublishToSubscriber(subscriber.Name, topic, payload, ack);
                }
            }
            else
            {
                _messagingLogger.Debug($"no subsriptions for {topic}");
                _deadLettersAgent.Publish(topic, payload, ack);
            }
            _messagingLogger.Debug($"{topic} sent in {sw.ElapsedMilliseconds}");
        }