/// <summary>
        /// Initializes a new instance of the <see cref="ReceiveMessageQueryHandler" /> class.
        /// </summary>
        /// <param name="serializer">The serializer.</param>
        /// <param name="receivedMessageFactory">The received message factory.</param>
        /// <param name="deleteMessage">The delete message.</param>
        /// <param name="redisHeaders">The redisHeaders.</param>
        /// <param name="dequeueLua">The dequeue.</param>
        /// <param name="dequeueRpcLua">The dequeue RPC.</param>
        /// <param name="unixTimeFactory">The unix time factory.</param>
        /// <param name="messageFactory">The message factory.</param>
        public ReceiveMessageQueryHandler(
            ICompositeSerialization serializer,
            IReceivedMessageFactory receivedMessageFactory,
            ICommandHandlerWithOutput <DeleteMessageCommand, bool> deleteMessage,
            RedisHeaders redisHeaders,
            DequeueLua dequeueLua,
            DequeueRpcLua dequeueRpcLua,
            IUnixTimeFactory unixTimeFactory,
            IMessageFactory messageFactory)
        {
            Guard.NotNull(() => serializer, serializer);
            Guard.NotNull(() => receivedMessageFactory, receivedMessageFactory);
            Guard.NotNull(() => deleteMessage, deleteMessage);
            Guard.NotNull(() => redisHeaders, redisHeaders);
            Guard.NotNull(() => dequeueLua, dequeueLua);
            Guard.NotNull(() => dequeueRpcLua, dequeueRpcLua);
            Guard.NotNull(() => unixTimeFactory, unixTimeFactory);

            _serializer             = serializer;
            _receivedMessageFactory = receivedMessageFactory;
            _deleteMessage          = deleteMessage;
            _redisHeaders           = redisHeaders;
            _dequeueLua             = dequeueLua;
            _dequeueRpcLua          = dequeueRpcLua;
            _unixTimeFactory        = unixTimeFactory;
            _messageFactory         = messageFactory;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="SendMessageCommandHandler" /> class.
        /// </summary>
        /// <param name="serializer">The serializer.</param>
        /// <param name="headers">The headers.</param>
        /// <param name="enqueueLua">The enqueue.</param>
        /// <param name="enqueueDelayedLua">The enqueue delayed.</param>
        /// <param name="enqueueExpirationLua">The enqueue expiration.</param>
        /// <param name="enqueueDelayedAndExpirationLua">The enqueue delayed and expiration.</param>
        /// <param name="unixTimeFactory">The unix time factory.</param>
        /// <param name="messageIdFactory">The message identifier factory.</param>
        /// <param name="jobSchedulerMetaData">The job scheduler meta data.</param>
        public SendMessageCommandHandlerAsync(
            ICompositeSerialization serializer,
            IHeaders headers,
            EnqueueLua enqueueLua,
            EnqueueDelayedLua enqueueDelayedLua,
            EnqueueExpirationLua enqueueExpirationLua,
            EnqueueDelayedAndExpirationLua enqueueDelayedAndExpirationLua,
            IUnixTimeFactory unixTimeFactory,
            IGetMessageIdFactory messageIdFactory,
            IJobSchedulerMetaData jobSchedulerMetaData)
        {
            Guard.NotNull(() => serializer, serializer);
            Guard.NotNull(() => headers, headers);
            Guard.NotNull(() => enqueueLua, enqueueLua);
            Guard.NotNull(() => enqueueDelayedLua, enqueueDelayedLua);
            Guard.NotNull(() => enqueueExpirationLua, enqueueExpirationLua);
            Guard.NotNull(() => enqueueDelayedAndExpirationLua, enqueueDelayedAndExpirationLua);
            Guard.NotNull(() => unixTimeFactory, unixTimeFactory);
            Guard.NotNull(() => messageIdFactory, messageIdFactory);

            _serializer           = serializer;
            _headers              = headers;
            _enqueueLua           = enqueueLua;
            _messageIdFactory     = messageIdFactory;
            _jobSchedulerMetaData = jobSchedulerMetaData;

            _enqueueDelayedLua = enqueueDelayedLua;
            _enqueueDelayedAndExpirationLua = enqueueDelayedAndExpirationLua;
            _unixTimeFactory      = unixTimeFactory;
            _enqueueExpirationLua = enqueueExpirationLua;
        }
Beispiel #3
0
 /// <summary>Initializes a new instance of the <see cref="DeleteMessageCommandHandler"/> class.</summary>
 /// <param name="errorLua">The error lua.</param>
 /// <param name="timeFactory">Time factory</param>
 public MoveRecordToErrorQueueCommandHandler(ErrorLua errorLua, IUnixTimeFactory timeFactory)
 {
     Guard.NotNull(() => errorLua, errorLua);
     Guard.NotNull(() => timeFactory, timeFactory);
     _errorLua = errorLua;
     _unixTime = timeFactory.Create();
 }
Beispiel #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SendMessageCommandBatchHandler" /> class.
        /// </summary>
        /// <param name="serializer">The serializer.</param>
        /// <param name="enqueue">The enqueue.</param>
        /// <param name="unixTimeFactory">The unix time factory.</param>
        /// <param name="messageIdFactory">The message identifier factory.</param>
        /// <param name="sentMessageFactory">The sent message factory.</param>
        /// <param name="redisHeaders">The redis headers.</param>
        /// <param name="sendBatchSize">Size of the send batch.</param>
        public SendMessageCommandBatchHandler(
            ICompositeSerialization serializer,
            EnqueueBatchLua enqueue,
            IUnixTimeFactory unixTimeFactory,
            IGetMessageIdFactory messageIdFactory,
            ISentMessageFactory sentMessageFactory,
            RedisHeaders redisHeaders,
            ISendBatchSize sendBatchSize)
        {
            Guard.NotNull(() => serializer, serializer);
            Guard.NotNull(() => enqueue, enqueue);
            Guard.NotNull(() => unixTimeFactory, unixTimeFactory);
            Guard.NotNull(() => messageIdFactory, messageIdFactory);
            Guard.NotNull(() => sentMessageFactory, sentMessageFactory);
            Guard.NotNull(() => redisHeaders, redisHeaders);
            Guard.NotNull(() => sendBatchSize, sendBatchSize);

            _serializer         = serializer;
            _enqueue            = enqueue;
            _messageIdFactory   = messageIdFactory;
            _sentMessageFactory = sentMessageFactory;
            _redisHeaders       = redisHeaders;
            _sendBatchSize      = sendBatchSize;
            _unixTimeFactory    = unixTimeFactory;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="RedisQueueSendHeartBeat"/> class.
        /// </summary>
        /// <param name="sendHeartBeat">The send heart beat.</param>
        /// <param name="unixTimeFactory">The unix time factory.</param>
        public RedisQueueSendHeartBeat(ICommandHandlerWithOutput<SendHeartBeatCommand, long> sendHeartBeat, 
            IUnixTimeFactory unixTimeFactory)
        {
            Guard.NotNull(() => sendHeartBeat, sendHeartBeat);
            Guard.NotNull(() => unixTimeFactory, unixTimeFactory);

            _sendHeartBeat = sendHeartBeat;
            _unixTimeFactory = unixTimeFactory;
        }
Beispiel #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DeleteMessageCommandHandler" /> class.
        /// </summary>
        /// <param name="sendHeartbeatLua">The send heartbeat lua.</param>
        /// <param name="unixTimeFactory">The unix time factory.</param>
        public SendHeartBeatCommandHandler(SendHeartbeatLua sendHeartbeatLua,
                                           IUnixTimeFactory unixTimeFactory)
        {
            Guard.NotNull(() => sendHeartbeatLua, sendHeartbeatLua);
            Guard.NotNull(() => unixTimeFactory, unixTimeFactory);

            _sendHeartbeatLua = sendHeartbeatLua;
            _unixTimeFactory  = unixTimeFactory;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="RedisQueueSendHeartBeat"/> class.
        /// </summary>
        /// <param name="sendHeartBeat">The send heart beat.</param>
        /// <param name="unixTimeFactory">The unix time factory.</param>
        public RedisQueueSendHeartBeat(ICommandHandlerWithOutput <SendHeartBeatCommand <string>, long> sendHeartBeat,
                                       IUnixTimeFactory unixTimeFactory)
        {
            Guard.NotNull(() => sendHeartBeat, sendHeartBeat);
            Guard.NotNull(() => unixTimeFactory, unixTimeFactory);

            _sendHeartBeat   = sendHeartBeat;
            _unixTimeFactory = unixTimeFactory;
        }
Beispiel #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RollbackMessageCommandHandler" /> class.
 /// </summary>
 /// <param name="rollbackLua">The rollback.</param>
 /// <param name="rollbackDelayLua">The rollback delay.</param>
 /// <param name="unixTimeFactory">The unix time factory.</param>
 public RollbackMessageCommandHandler(RollbackLua rollbackLua,
                                      RollbackDelayLua rollbackDelayLua,
                                      IUnixTimeFactory unixTimeFactory)
 {
     Guard.NotNull(() => rollbackLua, rollbackLua);
     Guard.NotNull(() => rollbackDelayLua, rollbackDelayLua);
     Guard.NotNull(() => unixTimeFactory, unixTimeFactory);
     _rollbackLua      = rollbackLua;
     _rollbackDelayLua = rollbackDelayLua;
     _unixTimeFactory  = unixTimeFactory;
 }
Beispiel #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ClearExpiredMessagesCommandHandler" /> class.
        /// </summary>
        /// <param name="clearExpiredMessagesLua">The clear expired messages.</param>
        /// <param name="unixTimeFactory">The unix time factory.</param>
        /// <param name="options">The options.</param>
        public ClearExpiredMessagesCommandHandler(ClearExpiredMessagesLua clearExpiredMessagesLua,
                                                  IUnixTimeFactory unixTimeFactory,
                                                  RedisQueueTransportOptions options)
        {
            Guard.NotNull(() => clearExpiredMessagesLua, clearExpiredMessagesLua);
            Guard.NotNull(() => unixTimeFactory, unixTimeFactory);
            Guard.NotNull(() => options, options);

            _clearExpiredMessagesLua = clearExpiredMessagesLua;
            _unixTimeFactory         = unixTimeFactory;
            _options = options;
        }
Beispiel #10
0
 public GetErrorRecordsToDeleteQueryHandler(IRedisConnection connection,
                                            IUnixTimeFactory timeFactory,
                                            IMessageErrorConfiguration errorConfiguration,
                                            RedisNames names,
                                            RedisQueueTransportOptions options)
 {
     _connection         = connection;
     _names              = names;
     _errorConfiguration = errorConfiguration;
     _options            = options;
     _unixTime           = timeFactory;
 }
        /// <summary>
        /// Creates the messages to send.
        /// </summary>
        /// <param name="redisHeaders">The redis headers.</param>
        /// <param name="messages">The messages.</param>
        /// <param name="meta">The meta data, already serialized.</param>
        /// <param name="unixTimeFactory">The unix time factory.</param>
        /// <param name="messageIdFactory">The message identifier factory.</param>
        /// <param name="serializer">The composite serializer.</param>
        /// <returns></returns>
        public static List <EnqueueBatchLua.MessageToSend> CreateMessagesToSend(RedisHeaders redisHeaders,
                                                                                IReadOnlyCollection <QueueMessage <IMessage, IAdditionalMessageData> > messages,
                                                                                byte[] meta,
                                                                                IUnixTimeFactory unixTimeFactory,
                                                                                IGetMessageIdFactory messageIdFactory,
                                                                                ICompositeSerialization serializer)
        {
            var messagesToSend = new ConcurrentBag <EnqueueBatchLua.MessageToSend>();

            Parallel.ForEach(messages, m =>
            {
                //the correlation ID must be saved as a message header
                m.Message.SetHeader(redisHeaders.CorrelationId, new RedisQueueCorrelationIdSerialized((Guid)m.MessageData.CorrelationId.Id.Value));

                //check for delay and expiration
                long unixTimeStampDelay      = 0;
                long unixTimeStampExpiration = 0;
                if (m.MessageData.GetDelay().HasValue)
                {
                    // ReSharper disable once PossibleInvalidOperationException
                    unixTimeStampDelay = unixTimeFactory.Create().GetAddDifferenceMilliseconds(m.MessageData.GetDelay().Value);
                }
                // ReSharper disable once PossibleInvalidOperationException
                if (m.MessageData.GetExpiration().HasValue&& m.MessageData.GetExpiration().Value != TimeSpan.Zero)
                {
                    var unixTime = unixTimeFactory.Create();
                    var timeSpan = m.MessageData.GetExpiration();
                    if (timeSpan != null)
                    {
                        var timespan            = timeSpan.Value;
                        unixTimeStampExpiration = unixTime.GetAddDifferenceMilliseconds(timespan);
                    }
                }

                var serialized = serializer.Serializer.MessageToBytes(new MessageBody {
                    Body = m.Message.Body
                }, m.Message.Headers);
                m.Message.SetHeader(redisHeaders.Headers.StandardHeaders.MessageInterceptorGraph, serialized.Graph);

                messagesToSend.Add(new EnqueueBatchLua.MessageToSend
                {
                    Message         = serialized.Output,
                    Headers         = serializer.InternalSerializer.ConvertToBytes(m.Message.Headers),
                    MessageId       = messageIdFactory.Create().Create().ToString(),
                    MetaData        = meta,
                    CorrelationId   = m.MessageData.CorrelationId.ToString(),
                    TimeStamp       = unixTimeStampDelay,
                    ExpireTimeStamp = unixTimeStampExpiration,
                    Route           = m.MessageData.Route
                });
            });
            return(messagesToSend.ToList());
        }
        /// <summary>Initializes a new instance of the <see cref="DeleteMessageCommandHandler"/> class.</summary>
        /// <param name="unixTimeFactory">The unix time factory.</param>
        /// <param name="connection">Redis connection</param>
        /// <param name="redisNames">Redis key names</param>
        public SendHeartBeatCommandHandler(IUnixTimeFactory unixTimeFactory,
                                           IRedisConnection connection,
                                           RedisNames redisNames)
        {
            Guard.NotNull(() => unixTimeFactory, unixTimeFactory);
            Guard.NotNull(() => connection, connection);
            Guard.NotNull(() => redisNames, redisNames);

            _unixTimeFactory = unixTimeFactory;
            _connection      = connection;
            _redisNames      = redisNames;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="MoveDelayedRecordsCommandHandler" /> class.
        /// </summary>
        /// <param name="moveDelayedToPendingLua">The move delayed to pending lua.</param>
        /// <param name="unixTimeFactory">The unix time factory.</param>
        /// <param name="options">The options.</param>
        public MoveDelayedRecordsCommandHandler(
            MoveDelayedToPendingLua moveDelayedToPendingLua,
            IUnixTimeFactory unixTimeFactory,
            RedisQueueTransportOptions options)
        {
            Guard.NotNull(() => moveDelayedToPendingLua, moveDelayedToPendingLua);
            Guard.NotNull(() => unixTimeFactory, unixTimeFactory);
            Guard.NotNull(() => options, options);

            _moveDelayedToPendingLua = moveDelayedToPendingLua;
            _unixTimeFactory         = unixTimeFactory;
            _options = options;
        }
        /// <summary>
        /// Creates the messages to send.
        /// </summary>
        /// <param name="redisHeaders">The redis headers.</param>
        /// <param name="messages">The messages.</param>
        /// <param name="meta">The meta data, already serialized.</param>
        /// <param name="unixTimeFactory">The unix time factory.</param>
        /// <param name="messageIdFactory">The message identifier factory.</param>
        /// <param name="serializer">The composite serializer.</param>
        /// <returns></returns>
        public static List<EnqueueBatchLua.MessageToSend> CreateMessagesToSend(RedisHeaders redisHeaders, 
            IReadOnlyCollection<QueueMessage<IMessage, IAdditionalMessageData>> messages,
            byte[] meta, 
            IUnixTimeFactory unixTimeFactory,
            IGetMessageIdFactory messageIdFactory,
            ICompositeSerialization serializer)
        {
            var messagesToSend = new ConcurrentBag<EnqueueBatchLua.MessageToSend>();
            Parallel.ForEach(messages, m =>
            {
                //the correlation ID must be saved as a message header
                m.Message.SetHeader(redisHeaders.CorelationId, new RedisQueueCorrelationIdSerialized((Guid)m.MessageData.CorrelationId.Id.Value));

                //check for delay and expiration
                long unixTimeStampDelay = 0;
                long unixTimeStampExpiration = 0;
                if (m.MessageData.GetDelay().HasValue)
                {
                    // ReSharper disable once PossibleInvalidOperationException
                    unixTimeStampDelay = unixTimeFactory.Create().GetAddDifferenceMilliseconds(m.MessageData.GetDelay().Value);
                }
                // ReSharper disable once PossibleInvalidOperationException
                if (m.MessageData.GetExpiration().HasValue && m.MessageData.GetExpiration().Value != TimeSpan.Zero)
                {
                    var unixTime = unixTimeFactory.Create();
                    var timeSpan = m.MessageData.GetExpiration();
                    if (timeSpan != null)
                    {
                        var timespan = timeSpan.Value;
                        unixTimeStampExpiration = unixTime.GetAddDifferenceMilliseconds(timespan);
                    }
                }

                var serialized = serializer.Serializer.MessageToBytes(new MessageBody { Body = m.Message.Body });
                m.Message.SetHeader(redisHeaders.Headers.StandardHeaders.MessageInterceptorGraph, serialized.Graph);

                messagesToSend.Add(new EnqueueBatchLua.MessageToSend()
                {
                    Message = serialized.Output,
                    Headers = serializer.InternalSerializer.ConvertToBytes(m.Message.Headers),
                    MessageId = messageIdFactory.Create().Create().ToString(),
                    MetaData = meta,
                    CorrelationId = m.MessageData.CorrelationId.ToString(),
                    TimeStamp = unixTimeStampDelay,
                    ExpireTimeStamp = unixTimeStampExpiration
                });
            });
            return messagesToSend.ToList();
        }
Beispiel #15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RollbackMessageCommandHandler" /> class.
        /// </summary>
        /// <param name="rollbackLua">The rollback.</param>
        /// <param name="rollbackDelayLua">The rollback delay.</param>
        /// <param name="unixTimeFactory">The unix time factory.</param>
        /// <param name="queueContext">The queue context.</param>
        public RollbackMessageCommandHandler(RollbackLua rollbackLua,
                                             RollbackDelayLua rollbackDelayLua,
                                             IUnixTimeFactory unixTimeFactory,
                                             QueueContext queueContext)
        {
            Guard.NotNull(() => rollbackLua, rollbackLua);
            Guard.NotNull(() => rollbackDelayLua, rollbackDelayLua);
            Guard.NotNull(() => unixTimeFactory, unixTimeFactory);
            Guard.NotNull(() => queueContext, queueContext);

            _rollbackLua      = rollbackLua;
            _rollbackDelayLua = rollbackDelayLua;
            _unixTimeFactory  = unixTimeFactory;
            _rpcQueue         = queueContext.Context == QueueContexts.RpcQueue;
        }
Beispiel #16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MoveDelayedRecordsCommandHandler" /> class.
        /// </summary>
        /// <param name="moveDelayedToPendingLua">The move delayed to pending lua.</param>
        /// <param name="unixTimeFactory">The unix time factory.</param>
        /// <param name="options">The options.</param>
        /// <param name="queueContext">The queue context.</param>
        public MoveDelayedRecordsCommandHandler(
            MoveDelayedToPendingLua moveDelayedToPendingLua,
            IUnixTimeFactory unixTimeFactory,
            RedisQueueTransportOptions options,
            QueueContext queueContext)
        {
            Guard.NotNull(() => moveDelayedToPendingLua, moveDelayedToPendingLua);
            Guard.NotNull(() => unixTimeFactory, unixTimeFactory);
            Guard.NotNull(() => options, options);
            Guard.NotNull(() => queueContext, queueContext);

            _moveDelayedToPendingLua = moveDelayedToPendingLua;
            _unixTimeFactory         = unixTimeFactory;
            _options  = options;
            _rpcQueue = queueContext.Context == QueueContexts.RpcQueue;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="RollbackMessageCommandHandler" /> class.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <param name="resetHeartbeatLua">The reset heartbeat lua.</param>
        /// <param name="unixTimeFactory">The unix time factory.</param>
        /// <param name="options">The options.</param>
        /// <param name="queueContext">The queue context.</param>
        public ResetHeartBeatCommandHandler(IHeartBeatConfiguration configuration,
                                            ResetHeartbeatLua resetHeartbeatLua,
                                            IUnixTimeFactory unixTimeFactory,
                                            RedisQueueTransportOptions options,
                                            QueueContext queueContext)
        {
            Guard.NotNull(() => configuration, configuration);
            Guard.NotNull(() => resetHeartbeatLua, resetHeartbeatLua);
            Guard.NotNull(() => unixTimeFactory, unixTimeFactory);
            Guard.NotNull(() => options, options);
            Guard.NotNull(() => queueContext, queueContext);

            _configuration     = configuration;
            _resetHeartbeatLua = resetHeartbeatLua;
            _unixTimeFactory   = unixTimeFactory;
            _options           = options;
        }
        /// <summary>Initializes a new instance of the <see cref="ReceiveMessageQueryHandler"/> class.</summary>
        /// <param name="serializer">The serializer.</param>
        /// <param name="receivedMessageFactory">The received message factory.</param>
        /// <param name="removeMessage">removes a message from the queue</param>
        /// <param name="redisHeaders">The redisHeaders.</param>
        /// <param name="dequeueLua">The dequeue.</param>
        /// <param name="unixTimeFactory">The unix time factory.</param>
        /// <param name="messageFactory">The message factory.</param>
        public ReceiveMessageQueryHandlerAsync(
            ICompositeSerialization serializer,
            IReceivedMessageFactory receivedMessageFactory,
            IRemoveMessage removeMessage,
            RedisHeaders redisHeaders,
            DequeueLua dequeueLua,
            IUnixTimeFactory unixTimeFactory,
            IMessageFactory messageFactory)
        {
            Guard.NotNull(() => serializer, serializer);
            Guard.NotNull(() => receivedMessageFactory, receivedMessageFactory);
            Guard.NotNull(() => removeMessage, removeMessage);
            Guard.NotNull(() => redisHeaders, redisHeaders);
            Guard.NotNull(() => dequeueLua, dequeueLua);
            Guard.NotNull(() => unixTimeFactory, unixTimeFactory);

            _serializer             = serializer;
            _receivedMessageFactory = receivedMessageFactory;
            _removeMessage          = removeMessage;
            _redisHeaders           = redisHeaders;
            _dequeueLua             = dequeueLua;
            _unixTimeFactory        = unixTimeFactory;
            _messageFactory         = messageFactory;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="GetRedisTimeFactory" /> class.
 /// </summary>
 /// <param name="unixTimeFactory">The unix time factory.</param>
 public GetRedisTimeFactory(IUnixTimeFactory unixTimeFactory)
 {
     Guard.NotNull(() => unixTimeFactory, unixTimeFactory);
     _unixTimeFactory = unixTimeFactory;
 }