Пример #1
0
        public void Publish <TMessage>(TMessage message) where TMessage : Message
        {
            _log.LogInfo($"Publishing Add Value Command: {message.CorrelationId}");

            using (var connection = _natsConnectionFactory.CreateConnection(brokerUrl))
            {
                var payload = MessageSerializer.Serialize(message);

                connection.Publish(message.Subject, payload);

                connection.Close();
            }
        }
Пример #2
0
        public Msg Send <TMessage>(TMessage message) where TMessage : Message
        {
            _log.LogInfo($"NATs: sending message");

            using (var connection = _natsConnectionFactory.CreateConnection(brokerUrl))
            {
                var payload = MessageSerializer.Serialize(message);

                _log.LogInfo($"Message Payload: \r\n {payload.ToString()}");

                var response = connection.Request(message.Subject, payload, 1);

                connection.Close();

                return(response);
            }
        }