/// <summary> /// Publica a mensagem na fila /// </summary> /// <param name="obj"></param> public void Publish <T>(T obj, string exchange = null, string routingKey = null, IBasicProperties basicProperties = null, short numberOfTries = 3) { var buffer = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(obj)); ProcessHandler.Retry(() => { this.EnsureConnected(); basicProperties = basicProperties ?? new BasicProperties { DeliveryMode = 2, Persistent = true }; _channel.BasicPublish(exchange: exchange ?? "", routingKey: routingKey, basicProperties: basicProperties, body: buffer); numberOfTries = 0; }, ref numberOfTries); }
/// <summary> /// Publica a mensagem na fila /// </summary> /// <param name="obj"></param> public void Publish <T>(T obj, string exchange = null, string routingKey = null, IBasicProperties basicProperties = null, short numberOfTries = 3) { var buffer = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(obj)); ProcessHandler.Retry(() => { if (_channel == null || _channel.IsClosed) { _channel = _channelFactory.Create(automaticRecoveryEnabled: true, requestedHeartbeat: 60); } basicProperties = basicProperties ?? new BasicProperties { DeliveryMode = 2, Persistent = true }; _channel.BasicPublish(exchange: exchange ?? "", routingKey: routingKey, basicProperties: basicProperties, body: buffer); numberOfTries = 0; }, ref numberOfTries); }