Exemplo n.º 1
0
        public IBatchContainer FromRabbitMQMessage(RabbitMQMessage message, long sequenceId)
        {
            var rabbitMqQueueBatch = _serializationManager.DeserializeFromByteArray <RabbitMQBatchContainer>(message.Body);

            rabbitMqQueueBatch.RealSequenceToken = new EventSequenceTokenV2(sequenceId);
            return(rabbitMqQueueBatch);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds a new message to the queue.
        /// </summary>
        /// <param name="message">Message to be added to the queue.</param>
        public async Task AddQueueMessage(RabbitMQMessage message)
        {
            var startTime = DateTime.UtcNow;

            try
            {
                await Task.Run(() =>
                {
                    if (_isClosing)
                    {
                        throw new InvalidOperationException("Unable to add item, Queue close has been requested.");
                    }
                    if (!IsConnected)
                    {
                        Connect();
                    }
                    _channel.BasicPublish(_configuration.Exchange, _configuration.RoutingKey, _props,
                                          message.Body);
                });
            }
            catch (Exception exc)
            {
                ReportErrorAndRethrow(exc, "AddQueueMessage");
            }
            finally
            {
                CheckAlertSlowAccess(startTime, "AddQueueMessage");
            }
        }
Exemplo n.º 3
0
        public RabbitMQMessage ToRabbitMQMessage <T>(Guid streamGuid, string streamNamespace, IEnumerable <T> events, Dictionary <string, object> requestContext)
        {
            var rabbitMqQueueBatch = new RabbitMQBatchContainer(streamGuid, streamNamespace,
                                                                events.Cast <object>().ToList(), requestContext);
            var rawBytes        = _serializationManager.SerializeToByteArray(rabbitMqQueueBatch);
            var rabbitMqMessage = new RabbitMQMessage(rawBytes);

            return(rabbitMqMessage);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Deletes a messages from the queue.
        /// </summary>
        /// <param name="message">A message to be deleted from the queue.</param>
        public async Task DeleteQueueMessage(RabbitMQMessage message)
        {
            var startTime = DateTime.UtcNow;

            try
            {
                await Task.Run(() =>
                {
                    _channel.BasicAck(message.DeliveryTag, false);
                });
            }
            catch (Exception exc)
            {
                ReportErrorAndRethrow(exc, "DeleteMessage");
            }
            finally
            {
                CheckAlertSlowAccess(startTime, "DeleteQueueMessage");
            }
        }
Exemplo n.º 5
0
 public PendingDelivery(StreamSequenceToken token, RabbitMQMessage message)
 {
     this.Token   = token;
     this.Message = message;
 }