static void Main(string[] args) { Modelo modelo = new Modelo { Id = 1, Name = "Adriano Maurmann" }; modelo.Print("Inicializado modelo"); Manager manager = new Manager(); manager.Send(modelo); manager.Listen(); Console.ReadKey(); }
public override void HandleBasicDeliver(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey, IBasicProperties properties, byte[] body) { if (properties.ContentType != Constants.JsonMimeType) { throw new ArgumentException("Content Type recebido não pode ser tratado"); } var message = Encoding.UTF8.GetString(body); Modelo modelo = JsonConvert.DeserializeObject <Modelo>(message); _manager.SendAck(deliveryTag); modelo.Print("Lido do Rabbit"); }
public void Send(Modelo modelo) { channel.ExchangeDeclare(exchange: Constants.TestExchange, type: ExchangeType.Direct); channel.QueueDeclare(queue: Constants.TestQueue, durable: false, exclusive: false, autoDelete: false, arguments: null); channel.QueueBind(queue: Constants.TestQueue, exchange: Constants.TestExchange, routingKey: ""); var serializedCommand = JsonConvert.SerializeObject(modelo); var messageProperties = channel.CreateBasicProperties(); messageProperties.ContentType = Constants.JsonMimeType; channel.BasicPublish( exchange: Constants.TestExchange, routingKey: "", basicProperties: messageProperties, body: Encoding.UTF8.GetBytes(serializedCommand)); modelo.Print("Enviado para o Rabbit"); }