Beispiel #1
0
        public void SendMessage(ConvertRequest message)
        {
            var factory = new ConnectionFactory()
            {
                HostName = "localhost"
            };

            using (var connection = factory.CreateConnection())
                using (var channel = connection.CreateModel())
                {
                    channel.ExchangeDeclare(exchange: "convert_tasks",
                                            type: "topic",
                                            durable: true);


                    var routingKey = "convert." + _routingKey.GetRoutingKey(message.Type);

                    var body = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(message));

                    channel.BasicPublish(exchange: "convert_tasks",
                                         routingKey: routingKey,
                                         basicProperties: null,
                                         body: body);

                    //Debug.WriteLine(" [x] Sent '{0}'", routingKey);
                }
        }