public MessagePublish PublishMessage(MessagePublish msgPublish) { try { #region Validates message publish object if (msgPublish == null || string.IsNullOrWhiteSpace(msgPublish.QueueName.Trim()) || string.IsNullOrWhiteSpace(msgPublish.Message.Trim())) { throw new ArgumentNullException("Argumento inválido!"); } #endregion #region Opens the channel and connection to RabbitMQ server ConnectionRabbitMQ connectionRabbitMQ = new ConnectionRabbitMQ(); connectionRabbitMQ.GetConnection(); connectionRabbitMQ.routingKey = msgPublish.QueueName; connectionRabbitMQ.OpenChannel(); #endregion #region Publishes the message on RabbitMQ msgPublish.PublishSuceed = connectionRabbitMQ.PublishMessage(msgPublish.Message); #endregion #region Closes the connection to RabbitMQ try { connectionRabbitMQ.CloseChannel(); } catch { } #endregion } catch (Exception e) { msgPublish.PublishSuceed = false; msgPublish.ErrorMessage = e.Message; } return(msgPublish); }
public static bool SendMessage(string queue, string message) { try { MessagePublish messagePublish = new MessagePublish(); messagePublish.QueueName = queue; messagePublish.Message = message; messagePublish = messageBrokerServiceClient.PublishMessageAsync(messagePublish).Result; if (!messagePublish.PublishSuceed) { throw new Exception(messagePublish.ErrorMessage); } return(true); } catch //(Exception ex) { //todo: Log error message in ex.message propertie return(false); } }
internal void PublishMessage(MessagePublish messagePublish) { throw new NotImplementedException(); }