public void Create_Default(string number) { var id = new RedisQueueId(number); var test = new DeleteMessageCommand(id); Assert.Equal(id, test.Id); }
public void Create_Default_ToString() { const long id = 1; var test = new RedisQueueId(id.ToString()); Assert.Equal("1", test.ToString()); }
public void Create_Default(string number) { var id = new RedisQueueId(number); var test = new SendHeartBeatCommand(id); Assert.Equal(id, test.QueueId); }
public void Create_Default(string number) { var id = new RedisQueueId(number); var test = new MoveRecordToErrorQueueCommand(id); Assert.Equal(id, test.QueueId); }
/// <summary> /// Initializes a new instance of the <see cref="SaveMetaDataCommand" /> class. /// </summary> /// <param name="id">The identifier.</param> /// <param name="metaData">The meta data.</param> public SaveMetaDataCommand(RedisQueueId id, RedisMetaData metaData) { Guard.NotNull(() => id, id); Guard.NotNull(() => metaData, metaData); Id = id; MetaData = metaData; }
public void Create_Default(string number) { var id = new RedisQueueId(number); var test = new GetMetaDataQuery(id); Assert.Equal(id, test.Id); }
public void Create_Default() { const long id = 1; var test = new RedisQueueId(id.ToString()); Assert.Equal(id.ToString(), test.Id.Value); Assert.True(test.HasValue); }
public void Create_Default_Empty() { var id = string.Empty; var test = new RedisQueueId(id); Assert.Equal(id, test.Id.Value); Assert.False(test.HasValue); }
public void Create_Default(string number, int metaNumber) { var id = new RedisQueueId(number); var meta = new RedisMetaData(metaNumber); var test = new SaveMetaDataCommand(id, meta); Assert.Equal(id, test.Id); Assert.Equal(meta, test.MetaData); }
public void Create_Default(string number) { var id = new RedisQueueId(number); var test = new RollbackMessageCommand(id, null); Assert.Equal(id, test.Id); Assert.Null(test.IncreaseQueueDelay); TimeSpan?time = TimeSpan.MinValue; test = new RollbackMessageCommand(id, time); Assert.Equal(id, test.Id); Assert.Equal(time, test.IncreaseQueueDelay); }
/// <summary> /// Initializes a new instance of the <see cref="MoveRecordToErrorQueueCommand" /> class. /// </summary> /// <param name="queueId">The queue identifier.</param> public MoveRecordToErrorQueueCommand(RedisQueueId queueId) { Guard.NotNull(() => queueId, queueId); QueueId = queueId; }
/// <summary> /// Initializes a new instance of the <see cref="SendHeartBeatCommand"/> class. /// </summary> /// <param name="queueId">The queue identifier.</param> public SendHeartBeatCommand(RedisQueueId queueId) { Guard.NotNull(() => queueId, queueId); QueueId = queueId; }
/// <summary> /// Initializes a new instance of the <see cref="DeleteMessageCommand" /> class. /// </summary> /// <param name="id">The identifier.</param> public DeleteMessageCommand(RedisQueueId id) { Guard.NotNull(() => id, id); Id = id; }
/// <summary> /// Initializes a new instance of the <see cref="GetMetaDataQuery"/> class. /// </summary> /// <param name="id">The identifier.</param> public GetMetaDataQuery(RedisQueueId id) { Guard.NotNull(() => id, id); Id = id; }
/// <summary> /// Initializes a new instance of the <see cref="RollbackMessageCommand" /> class. /// </summary> /// <param name="id">The identifier.</param> /// <param name="increaseQueueDelay">The increase queue delay.</param> public RollbackMessageCommand(RedisQueueId id, TimeSpan?increaseQueueDelay) { Guard.NotNull(() => id, id); Id = id; IncreaseQueueDelay = increaseQueueDelay; }
/// <summary> /// Initializes a new instance of the <see cref="GetHeaderQuery"/> class. /// </summary> /// <param name="id">The identifier.</param> public GetHeaderQuery(RedisQueueId id) { Id = id; }
/// <inheritdoc /> public RedisMessage Handle(ReceiveMessageQuery query) { byte[] message = null; byte[] headers = null; string messageId; var poisonMessage = false; RedisQueueCorrelationIdSerialized correlationId = null; try { var unixTimestamp = _unixTimeFactory.Create().GetCurrentUnixTimestampMilliseconds(); RedisValue[] result; if (query.MessageId != null && query.MessageId.HasValue) { result = _dequeueRpcLua.Execute(query.MessageId.Id.Value.ToString(), unixTimestamp); } else { result = _dequeueLua.Execute(unixTimestamp); } if (result == null || result.Length == 1 && !result[0].HasValue || !result[0].HasValue) { return(null); } if (!result[1].HasValue) { //at this point, the record has been de-queued, but it can't be processed. poisonMessage = true; } messageId = result[0]; var id = new RedisQueueId(messageId); query.MessageContext.MessageId = id; if (!poisonMessage) { message = result[1]; headers = result[2]; if (result[3].HasValue) { if (result[3].TryParse(out long messageExpiration)) { if (messageExpiration - unixTimestamp < 0) { //message has expired _deleteMessage.Handle(new DeleteMessageCommand(new RedisQueueId(messageId))); return(new RedisMessage(messageId, null, true)); } } } } } catch (Exception error) { throw new ReceiveMessageException("Failed to dequeue a message", error); } if (poisonMessage) { //at this point, the record has been de-queued, but it can't be processed. throw new PoisonMessageException( "An error has occurred trying to re-assemble a message de-queued from Redis; a messageId was returned, but the LUA script returned a null message. The message payload has most likely been lost.", null, new RedisQueueId(messageId), new RedisQueueCorrelationId(Guid.Empty), null, null); } try { var allHeaders = _serializer.InternalSerializer.ConvertBytesTo <IDictionary <string, object> > (headers); correlationId = (RedisQueueCorrelationIdSerialized)allHeaders[_redisHeaders.CorrelationId.Name]; var messageGraph = (MessageInterceptorsGraph)allHeaders[_redisHeaders.Headers.StandardHeaders.MessageInterceptorGraph.Name]; var messageData = _serializer.Serializer.BytesToMessage <MessageBody>(message, messageGraph); var newMessage = _messageFactory.Create(messageData.Body, allHeaders); return(new RedisMessage( messageId, _receivedMessageFactory.Create( newMessage, new RedisQueueId(messageId), new RedisQueueCorrelationId(correlationId.Id)), false)); } catch (Exception error) { //at this point, the record has been de-queued, but it can't be processed. throw new PoisonMessageException( "An error has occurred trying to re-assemble a message de-queued from redis", error, new RedisQueueId(messageId), new RedisQueueCorrelationId(correlationId), message, headers); } }
/// <summary> /// Initializes a new instance of the <see cref="RollbackMessageCommand" /> class. /// </summary> /// <param name="id">The identifier.</param> /// <param name="increaseQueueDelay">The increase queue delay.</param> public RollbackMessageCommand(RedisQueueId id, TimeSpan? increaseQueueDelay) { Guard.NotNull(() => id, id); Id = id; IncreaseQueueDelay = increaseQueueDelay; }