Class RmqMessagePublisher.
예제 #1
0
        /// <summary>
        /// Send the specified message with specified delay
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="delayMilliseconds">Number of milliseconds to delay delivery of the message.</param>
        /// <returns>Task.</returns>
        public Task Send(Message message, int delayMilliseconds)
        {
            //RabbitMQ .NET Client does not have an async publish, so fake this for now as we want to support messaging frameworks that do have this option
            var tcs = new TaskCompletionSource<object>();

            Logger.DebugFormat("RmqMessageProducer: Preparing  to sending message via exchange {0}", Configuration.Exchange.Name);

            try
            {
                EnsureChannel();
                var rmqMessagePublisher = new RmqMessagePublisher(Channel, Configuration.Exchange.Name, Logger);
                Logger.DebugFormat("RmqMessageProducer: Publishing message to exchange {0} on connection {1} with a delay of {5} and topic {2} and id {3} and body: {4}", Configuration.Exchange.Name, Configuration.AMPQUri.GetSanitizedUri(), message.Header.Topic, message.Id, message.Body.Value, delayMilliseconds);
                rmqMessagePublisher.PublishMessage(message, delayMilliseconds);
                Logger.InfoFormat("RmqMessageProducer: Published message to exchange {0} on connection {1} with a delay of {5} and topic {2} and id {3} and message: {4} at {5}", Configuration.Exchange.Name, Configuration.AMPQUri.GetSanitizedUri(), message.Header.Topic, message.Id, JsonConvert.SerializeObject(message), DateTime.UtcNow, delayMilliseconds);
            }
            catch (Exception e)
            {
                if (Channel != null)
                    tcs.SetException(e);
                throw;
            }

            tcs.SetResult(new object());
            return tcs.Task;
        }
예제 #2
0
        /// <summary>
        /// Sends the specified message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <returns>Task.</returns>
        public Task Send(Message message)
        {
            //RabbitMQ .NET Client does not have an async publish, so fake this for now as we want to support messaging frameworks that do have this option
            var tcs = new TaskCompletionSource <object>();

            Logger.Debug(m => m("RmqMessageProducer: Preparing  to sending message {0} via exchange {1}", Configuration.Exchange.Name, JsonConvert.SerializeObject(message)));

            if (!Connect())
            {
                tcs.SetException(ConnectionFailure);
                throw ConnectionFailure;
            }

            try
            {
                var rmqMessagePublisher = new RmqMessagePublisher(Channel, Configuration.Exchange.Name);
                Logger.Debug(m => m("RmqMessageProducer: Publishing message to exchange {0} on connection {1} with topic {2} and id {3} and body: {4}", Configuration.Exchange.Name, Configuration.AMPQUri.Uri.ToString(), message.Header.Topic, message.Id, message.Body.Value));
                rmqMessagePublisher.PublishMessage(message);
                Logger.Debug(m => m("RmqMessageProducer: Published message to exchange {0} on connection {1} with topic {2} and id {3} and body: {4} at {5}", Configuration.Exchange.Name, Configuration.AMPQUri.Uri.ToString(), message.Header.Topic, message.Id, message.Body.Value, DateTime.UtcNow));
            }
            catch (Exception e)
            {
                if (Channel != null)
                {
                    tcs.SetException(e);
                }
                throw;
            }

            tcs.SetResult(new object());
            return(tcs.Task);
        }
예제 #3
0
        /// <summary>
        /// Send the specified message with specified delay
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="delayMilliseconds">Number of milliseconds to delay delivery of the message.</param>
        /// <returns>Task.</returns>
        public void SendWithDelay(Message message, int delayMilliseconds = 0)
        {
            Logger.DebugFormat("RmqMessageProducer: Preparing  to sending message via exchange {0}", Configuration.Exchange.Name);

            EnsureChannel();
            var rmqMessagePublisher = new RmqMessagePublisher(Channel, Configuration.Exchange.Name, Logger);
            Logger.DebugFormat("RmqMessageProducer: Publishing message to exchange {0} on connection {1} with a delay of {5} and topic {2} and id {3} and body: {4}", Configuration.Exchange.Name, Configuration.AMPQUri.GetSanitizedUri(), message.Header.Topic, message.Id, message.Body.Value, delayMilliseconds);
            rmqMessagePublisher.PublishMessage(message, delayMilliseconds);
            Logger.InfoFormat("RmqMessageProducer: Published message to exchange {0} on connection {1} with a delay of {5} and topic {2} and id {3} and message: {4} at {5}", Configuration.Exchange.Name, Configuration.AMPQUri.GetSanitizedUri(), message.Header.Topic, message.Id, JsonConvert.SerializeObject(message), DateTime.UtcNow, delayMilliseconds);
        }
예제 #4
0
 public void Requeue(Message message)
 {
     if (Channel != null)
     {
         var rmqMessagePublisher = new RmqMessagePublisher(Channel, Configuration.Exchange.Name);
         Logger.Debug(m => m("RmqMessageConsumer: Re-queueing message"));
         rmqMessagePublisher.PublishMessage(message);
         Reject(message, false);
     }
 }
예제 #5
0
 /// <summary>
 /// Send the specified message with specified delay
 /// </summary>
 /// <param name="message">The message.</param>
 /// <param name="delayMilliseconds">Number of milliseconds to delay delivery of the message.</param>
 /// <returns>Task.</returns>
 public void SendWithDelay(Message message, int delayMilliseconds = 0)
 {
     lock (_lock)
     {
         Logger.DebugFormat("RmqMessageProducer: Preparing  to sending message via exchange {0}", Configuration.Exchange.Name);
         EnsureChannel();
         var rmqMessagePublisher = new RmqMessagePublisher(Channel, Configuration.Exchange.Name, Logger);
         Logger.DebugFormat("RmqMessageProducer: Publishing message to exchange {0} on connection {1} with a delay of {5} and topic {2} and id {3} and body: {4}", Configuration.Exchange.Name, Configuration.AMPQUri.GetSanitizedUri(), message.Header.Topic, message.Id, message.Body.Value, delayMilliseconds);
         rmqMessagePublisher.PublishMessage(message, delayMilliseconds);
         Logger.InfoFormat("RmqMessageProducer: Published message to exchange {0} on connection {1} with a delay of {5} and topic {2} and id {3} and message: {4} at {5}", Configuration.Exchange.Name, Configuration.AMPQUri.GetSanitizedUri(), message.Header.Topic, message.Id, JsonConvert.SerializeObject(message), DateTime.UtcNow, delayMilliseconds);
     }
 }
예제 #6
0
 public void Requeue(Message message, int delayMilliseconds)
 {
     try
     {
         _logger.Value.DebugFormat("RmqMessageConsumer: Re-queueing message {0} with a delay of {1} milliseconds", message.Id, delayMilliseconds);
         EnsureChannel(_queueName);
         var rmqMessagePublisher = new RmqMessagePublisher(Channel, Connection.Exchange.Name);
         rmqMessagePublisher.RequeueMessage(message, _queueName, delayMilliseconds);
         Reject(message, false);
     }
     catch (Exception exception)
     {
         _logger.Value.ErrorException("RmqMessageConsumer: Error re-queueing message {0}", exception, message.Id);
         throw;
     }
 }
예제 #7
0
 public void Requeue(Message message)
 {
     try
     {
         EnsureChannel(queueName);
         var rmqMessagePublisher = new RmqMessagePublisher(Channel, Configuration.Exchange.Name);
         Logger.DebugFormat("RmqMessageConsumer: Re-queueing message {0}", message.Id);
         rmqMessagePublisher.PublishMessage(message);
         Reject(message, false);
     }
     catch (Exception exception)
     {
         Logger.ErrorException("RmqMessageConsumer: Error re-queueing message {0}", exception, message.Id);
         throw;
     }
 }
예제 #8
0
 public void Requeue(Message message, int delayMilliseconds)
 {
     try
     {
         Logger.DebugFormat("RmqMessageConsumer: Re-queueing message {0} with a delay of {1} milliseconds", message.Id, delayMilliseconds);
         EnsureChannel(_queueName);
         var rmqMessagePublisher = new RmqMessagePublisher(Channel, Configuration.Exchange.Name, Logger);
         rmqMessagePublisher.RequeueMessage(message, _queueName, delayMilliseconds);
         Reject(message, false);
     }
     catch (Exception exception)
     {
         Logger.ErrorException("RmqMessageConsumer: Error re-queueing message {0}", exception, message.Id);
         throw;
     }
 }