コード例 #1
0
        /// <summary>
        /// 发布消息
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="message"></param>
        public void RaiseMessage <T>(MqMessage <T> message)
        {
            _logger.Debug($"RaiseMessage, message[{JsonConvert.SerializeObject(message)}]");

            MqMessagePayload messagePayload = message.ToMessagePayload();

            byte[] messageBody = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(messagePayload));

            List <string> routingKeys = _options.GetQueueBindRoutingKey();

            routingKeys.ForEach(key =>
            {
                _logger.Debug($"Publish message to routeKey[{key}].");
                _channel.Publish(messageBody, key, false);
            });
        }
コード例 #2
0
        /// <summary>
        /// 发布消息(延迟)
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="message"></param>
        /// <param name="delaySeconds"></param>
        public void RaiseMessage <T>(MqMessage <T> message, int delaySeconds)
        {
            _logger.Debug($"RaiseMessage, message[{JsonConvert.SerializeObject(message)}],delay [{delaySeconds}] seconds");

            MqMessagePayload messagePayload = message.ToMessagePayload();

            byte[] messageBody = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(messagePayload));

            var headers = new Dictionary <string, object> {
                { "x-delay", delaySeconds * 1000 }
            };
            List <string> routingKeys = _options.GetQueueBindRoutingKey();

            routingKeys.ForEach(key =>
            {
                _logger.Debug($"Publish message to routeKey[{key}], and delay [{delaySeconds}] seconds.");
                _channel.Publish(messageBody, key, false, headers);
            });
        }
コード例 #3
0
 public abstract void OnMessageReceived(MqMessagePayload message);