Exemplo n.º 1
0
        /// <summary>
        /// Publish message
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="message"></param>
        public void Send <T>(Send <T> action)
        {
            using (var connection = _connectionFactory.CreateConnection(action.Host))
                using (var channel = connection.CreateModel())
                {
                    channel.ExchangeDeclare(exchange: action.ExhangeName, type: ExchangeType.Fanout);

                    var body = ByteConvertor.ObjectToByteArray <T>(action.Message);

                    channel.BasicPublish(exchange: action.ExhangeName,
                                         routingKey: "",
                                         basicProperties: null,
                                         body: body);
                }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Publish message.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="message"></param>
        public void Send <T>(Send <T> action)
        {
            using (var connection = _connectionFactory.CreateConnection(action.Host))
                using (var channel = connection.CreateModel())
                {
                    channel.QueueDeclare(queue: action.QueueName,
                                         durable: true,
                                         exclusive: false,
                                         autoDelete: false,
                                         arguments: null);

                    var body = ByteConvertor.ObjectToByteArray <T>(action.Message);

                    channel.BasicPublish(exchange: "",
                                         routingKey: action.RouteKey,
                                         basicProperties: null,
                                         body: body);
                }
        }