Exemple #1
0
 public void SendModelToQueue(T model, QueueDeclaration declaration, IBasicProperties properties = null)
 {
     using (var channel = _connection.CreateModel())
     {
         channel.QueueDeclare(declaration.Name, declaration.IsDurable, declaration.IsExclusive, declaration.HasAutoDelete, declaration.Args);
         channel.BasicPublish(string.Empty, declaration.Name, false, properties, Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(model)));
     }
 }
        public T GetModelInQueue(QueueDeclaration declaration)
        {
            var model = default(T);

            _channel.QueueDeclare(declaration.Name, declaration.IsDurable, declaration.IsExclusive, declaration.HasAutoDelete, declaration.Args);
            var result = _channel.BasicGet(declaration.Name, true);

            if (result != null)
            {
                string data = Encoding.UTF8.GetString(result.Body);
                model = JsonConvert.DeserializeObject <T>(data);
            }

            return(model);
        }