public void MessageWorks()
 {
     var deserializedObject = new object();
     _deserializer.Setup(m => m.Deserialize("<body/>")).Returns(deserializedObject);
     var message = new Message() { Body = "<body/>"};
     target.ProcessEvent(this, message);
     _handlers.Verify(m => m.Handle(deserializedObject));
 }
        public void DeadLetteringStoresTheMessage()
        {
            var msg = new Message();
            var ex = new Exception();
            target.DeadLetter(msg, ex);

            _persistance.Verify(m => m.Deadletter(msg, ex));
        }
 public void ProcessEvent(object sender, Message message)
 {
     try
     {
         var mbody = _deserializer.Deserialize(message.Body);
         _handlers.Handle(mbody);
         MessageProcessed?.Invoke(this, message);
     }
     catch (Exception ex)
     {
         MessageFailed?.Invoke(this, new MessageFailedEventArgs { Message = message, Exception = ex });
     }
 }
        public void MessageFails()
        {
            var deserializedObject = new object();
            _deserializer.Setup(m => m.Deserialize("<body/>")).Returns(deserializedObject);

            var exception = new Exception();
            _handlers.Setup(m => m.Handle(deserializedObject)).Throws(exception);
            
            var message = new Message() { Body = "<body/>" };
            _messageFailedHandler.Setup(m => m(target, It.Is<MessageFailedEventArgs>(x => x.Exception == exception && x.Message == message)));

            target.ProcessEvent(this, message);

            _messageFailedHandler.Verify(m => m(target, It.Is<MessageFailedEventArgs>(x => x.Exception == exception && x.Message == message)));
        }
Ejemplo n.º 5
0
        public void AddToWorkingFeed(Message e)
        {
            using (var c = new SqlConnection(_connectionString))
            {
                var cmd = c.CreateCommand();
                cmd.CommandText = InsertEvent;
                cmd.Parameters.Add(new SqlParameter("@id", e.Id));
                cmd.Parameters.Add(new SqlParameter("@createdAt", e.CreatedAt));
                cmd.Parameters.Add(new SqlParameter("@body", e.Body));
                cmd.Parameters.Add(new SqlParameter("@feedUri", e.FeedUri));

                c.Open();
                cmd.ExecuteNonQuery();
            }
        }
Ejemplo n.º 6
0
        public void Deadletter(Message message, Exception exception)
        {
            using (var c = new SqlConnection(_connectionString))
            {
                var cmd = c.CreateCommand();
                cmd.CommandText = InsertOrUpdateIntoDeadLetter;

                cmd.Parameters.Add(new SqlParameter("@Id", message.Id));
                cmd.Parameters.Add(new SqlParameter("@Body", message.Body));
                cmd.Parameters.Add(new SqlParameter("@CreatedAt", message.CreatedAt));
                cmd.Parameters.Add(new SqlParameter("@LastAttemptedProcessingAt", DateTime.Now));
                cmd.Parameters.Add(new SqlParameter("@FeedUrl", message.FeedUri));
                cmd.Parameters.Add(new SqlParameter("@Exception", exception.Message));
                cmd.Parameters.Add(new SqlParameter("@ExceptionStack", exception.StackTrace));

                c.Open();
                cmd.ExecuteNonQuery();
            }
        }
Ejemplo n.º 7
0
        public void ClearFailure(Message message)
        {
            using (var c = new SqlConnection(_connectionString))
            {
                var cmd = c.CreateCommand();
                cmd.CommandText = DeleteFromDeadLetter;

                cmd.Parameters.Add(new SqlParameter("@Id", message.Id));
                
                c.Open();
                cmd.ExecuteNonQuery();
            }
        }
 protected virtual void OnEventReceived(Message e)
 {
     EventReceived?.Invoke(this, e);
 }
Ejemplo n.º 9
0
 public void ClearFailure(Message message)
 {
     _persistance.ClearFailure(message);
 }
Ejemplo n.º 10
0
 protected virtual void OnMessageReadyForRetry(Message e)
 {
     MessageReadyForRetry?.Invoke(this, e);
 }
Ejemplo n.º 11
0
 public void DeadLetter(Message message, Exception exception)
 {
     _persistance.Deadletter(message, exception);
 }