11using System ;
2+ using System . Collections . Generic ;
3+ using System . Linq ;
24using System . Reflection ;
35using System . Threading . Tasks ;
46using InEngine . Core . Exceptions ;
@@ -74,11 +76,7 @@ public bool Consume()
7476 var message = serializedMessage . DeserializeFromJson < Message > ( ) ;
7577 if ( message == null )
7678 return false ;
77-
78- var commandType = Type . GetType ( $ "{ message . CommandClassName } , { message . CommandAssemblyName } ") ;
79- if ( commandType == null )
80- throw new CommandFailedException ( "Consumed command failed: could not locate command type." ) ;
81- var commandInstance = JsonConvert . DeserializeObject ( message . SerializedCommand , commandType ) as ICommand ;
79+ var commandInstance = ExtractCommandInstanceFromMessage ( message ) ;
8280
8381 try
8482 {
@@ -103,6 +101,14 @@ public bool Consume()
103101 return true ;
104102 }
105103
104+ public ICommand ExtractCommandInstanceFromMessage ( Message message )
105+ {
106+ var commandType = Type . GetType ( $ "{ message . CommandClassName } , { message . CommandAssemblyName } ") ;
107+ if ( commandType == null )
108+ throw new CommandFailedException ( "Could not locate command type." ) ;
109+ return JsonConvert . DeserializeObject ( message . SerializedCommand , commandType ) as ICommand ;
110+ }
111+
106112 #region Queue Management Methods
107113 public long GetPendingQueueLength ( )
108114 {
@@ -138,6 +144,26 @@ public void RepublishFailedMessages()
138144 {
139145 Redis . ListRightPopLeftPush ( FailedQueueName , PendingQueueName ) ;
140146 }
147+
148+ public List < Message > PeekPendingMessages ( long from , long to )
149+ {
150+ return GetMessages ( PendingQueueName , from , to ) ;
151+ }
152+
153+ public List < Message > PeekInProgressMessages ( long from , long to )
154+ {
155+ return GetMessages ( InProgressQueueName , from , to ) ;
156+ }
157+
158+ public List < Message > PeekFailedMessages ( long from , long to )
159+ {
160+ return GetMessages ( FailedQueueName , from , to ) ;
161+ }
162+
163+ public List < Message > GetMessages ( string queueName , long from , long to )
164+ {
165+ return Redis . ListRange ( queueName , from , to ) . ToStringArray ( ) . Select ( x => x . DeserializeFromJson < Message > ( ) ) . ToList ( ) ;
166+ }
141167 #endregion
142168 }
143169}
0 commit comments