Esempio n. 1
0
        protected void ResolveAttributes(Type type, Type modelType)
        {
            if (!SendAck)
            {
                AutoAckAttribute ackAttribute = type.GetCustomAttribute <AutoAckAttribute>();
                SendAck = ackAttribute != null;
            }

            if (!SendNack)
            {
                AutoNackAttribute nackAttribute = type.GetCustomAttribute <AutoNackAttribute>();
                SendNack   = nackAttribute != null;
                NackReason = nackAttribute != null ? nackAttribute.Reason : NackReason.None;
            }

            RetryAttribute retryAttr = type.GetCustomAttribute <RetryAttribute>();

            if (retryAttr != null)
            {
                Retry = retryAttr;
            }

            if (PushExceptions == null)
            {
                PushExceptions = new List <TransportExceptionDescriptor>();
            }

            IEnumerable <PushExceptionsAttribute> pushAttributes = type.GetCustomAttributes <PushExceptionsAttribute>(true);

            foreach (PushExceptionsAttribute attribute in pushAttributes)
            {
                if (attribute.ExceptionType == null)
                {
                    DefaultPushException = new TransportExceptionDescriptor(attribute.ModelType);
                }
                else
                {
                    PushExceptions.Add(new TransportExceptionDescriptor(attribute.ModelType, attribute.ExceptionType));
                }
            }

            if (PublishExceptions == null)
            {
                PublishExceptions = new List <TransportExceptionDescriptor>();
            }

            IEnumerable <PublishExceptionsAttribute> publishAttributes = type.GetCustomAttributes <PublishExceptionsAttribute>(true);

            foreach (PublishExceptionsAttribute attribute in publishAttributes)
            {
                if (attribute.ExceptionType == null)
                {
                    DefaultPublishException = new TransportExceptionDescriptor(attribute.ModelType);
                }
                else
                {
                    PublishExceptions.Add(new TransportExceptionDescriptor(attribute.ModelType, attribute.ExceptionType));
                }
            }
        }
Esempio n. 2
0
        private async Task TransportToRouter(HorseClient client, TransportExceptionDescriptor item, Exception exception, HorseMessage consumingMessage)
        {
            ITransportableException transportable = (ITransportableException)Activator.CreateInstance(item.ModelType);

            if (transportable == null)
            {
                return;
            }

            transportable.Initialize(new ExceptionContext
            {
                Consumer         = this,
                Exception        = exception,
                ConsumingMessage = consumingMessage
            });

            await client.Routers.PublishJson(transportable);
        }
 /// <summary>
 /// Publish exceptions in specified types in consumers' consume operations to specified route
 /// </summary>
 public ModelTypeConfigurator PublishConsumerExceptions <TModel>(Type exceptionType)
     where TModel : ITransportableException, new()
 {
     PublishExceptions.Add(DefaultPublishException = new TransportExceptionDescriptor(typeof(TModel), exceptionType));
     return(this);
 }