Beispiel #1
0
        protected IMessageListenerContainer CreateListenerContainer(IRabbitListenerEndpoint endpoint, IRabbitListenerContainerFactory factory)
        {
            var listenerContainer = factory.CreateListenerContainer(endpoint);

            try
            {
                listenerContainer.Initialize();
            }
            catch (Exception ex)
            {
                throw new TypeInitializationException("Failed to initialize message listener container", ex);
            }

            var containerPhase = listenerContainer.Phase;

            if (containerPhase < int.MaxValue)
            {
                // a custom phase value
                if (Phase < int.MaxValue && Phase != containerPhase)
                {
                    throw new InvalidOperationException("Encountered phase mismatch between container factory definitions: " + Phase + " vs " + containerPhase);
                }

                Phase = listenerContainer.Phase;
            }

            return(listenerContainer);
        }
        public void RegisterEndpoint(IRabbitListenerEndpoint endpoint, IRabbitListenerContainerFactory factory)
        {
            if (endpoint == null)
            {
                throw new ArgumentNullException(nameof(endpoint));
            }

            if (string.IsNullOrEmpty(endpoint.Id))
            {
                throw new InvalidOperationException("Endpoint id must be set");
            }

            if (StartImmediately && EndpointRegistry == null)
            {
                throw new InvalidOperationException("No registry available");
            }

            // Factory may be null, we defer the resolution right before actually creating the container
            var descriptor = new AmqpListenerEndpointDescriptor(endpoint, factory);

            lock (_endpointDescriptors)
            {
                if (StartImmediately)
                { // Register and start immediately
                    EndpointRegistry.RegisterListenerContainer(descriptor.Endpoint, ResolveContainerFactory(descriptor), true);
                }
                else
                {
                    _endpointDescriptors.Add(descriptor);
                }
            }
        }
        public MessageListenerTestContainer CreateListenerContainer(IRabbitListenerEndpoint endpoint)
        {
            var container = new MessageListenerTestContainer(endpoint);

            if (endpoint.Id == null && endpoint is AbstractRabbitListenerEndpoint)
            {
                var id = Interlocked.Increment(ref counter);
                endpoint.Id = "endpoint#" + id;
            }

            Assert.NotNull(endpoint.Id);
            ListenerContainers.Add(endpoint.Id, container);
            return(container);
        }
        public void RegisterListenerContainer(IRabbitListenerEndpoint endpoint, IRabbitListenerContainerFactory factory, bool startImmediately)
        {
            if (endpoint == null)
            {
                throw new ArgumentNullException(nameof(endpoint));
            }

            if (factory == null)
            {
                throw new ArgumentNullException(nameof(factory));
            }

            var id = endpoint.Id;

            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentException("Endpoint id must not be empty");
            }

            lock (_listenerContainers)
            {
                if (_listenerContainers.ContainsKey(id))
                {
                    throw new InvalidOperationException("Another endpoint is already registered with id '" + id + "'");
                }

                var container = CreateListenerContainer(endpoint, factory);
                _listenerContainers.TryAdd(id, container);

                if (!string.IsNullOrEmpty(endpoint.Group) && ApplicationContext != null)
                {
                    var containerCollection =
                        ApplicationContext.GetService <IMessageListenerContainerCollection>(endpoint.Group) as MessageListenerContainerCollection;
                    if (containerCollection != null)
                    {
                        containerCollection.AddContainer(container);
                    }
                }

                // if (this.contextRefreshed)
                // {
                //    container.lazyLoad();
                // }
                if (startImmediately && container.IsAutoStartup)
                {
                    container.Start();
                }
            }
        }
Beispiel #5
0
 public void RegisterListenerContainer(IRabbitListenerEndpoint endpoint, IRabbitListenerContainerFactory factory)
 {
     RegisterListenerContainer(endpoint, factory, false);
 }
 public RabbitListenerEndpointDescriptor(IRabbitListenerEndpoint endpoint, IRabbitListenerContainerFactory containerFactory)
 {
     Endpoint         = endpoint;
     ContainerFactory = containerFactory;
 }
 public void RegisterEndpoint(IRabbitListenerEndpoint endpoint)
 {
     RegisterEndpoint(endpoint, null);
 }
Beispiel #8
0
 public MessageListenerTestContainer(IRabbitListenerEndpoint endpoint)
 {
     Endpoint = endpoint;
 }
 IMessageListenerContainer IRabbitListenerContainerFactory.CreateListenerContainer(IRabbitListenerEndpoint endpoint)
 {
     return(CreateListenerContainer(endpoint));
 }
        protected override void InitializeContainer(DirectMessageListenerContainer instance, IRabbitListenerEndpoint endpoint)
        {
            base.InitializeContainer(instance, endpoint);
            if (MonitorInterval.HasValue)
            {
                instance.MonitorInterval = MonitorInterval.Value;
            }

            if (MessagesPerAck.HasValue)
            {
                instance.MessagesPerAck = MessagesPerAck.Value;
            }

            if (AckTimeout.HasValue)
            {
                instance.AckTimeout = AckTimeout.Value;
            }

            if (endpoint != null && endpoint.Concurrency.HasValue)
            {
                instance.ConsumersPerQueue = endpoint.Concurrency.Value;
            }
            else if (ConsumersPerQueue.HasValue)
            {
                instance.ConsumersPerQueue = ConsumersPerQueue.Value;
            }
        }
 protected virtual void InitializeContainer(C instance, IRabbitListenerEndpoint endpoint)
 {
 }
        public C CreateListenerContainer(IRabbitListenerEndpoint endpoint)
        {
            var instance = CreateContainerInstance();

            instance.ConnectionFactory = ConnectionFactory;
            instance.ErrorHandler      = ErrorHandler;

            if (MessageConverter != null && endpoint != null)
            {
                endpoint.MessageConverter = MessageConverter;
            }

            if (AcknowledgeMode.HasValue)
            {
                instance.AcknowledgeMode = AcknowledgeMode.Value;
            }

            if (ChannelTransacted.HasValue)
            {
                instance.IsChannelTransacted = ChannelTransacted.Value;
            }

            if (ApplicationContext != null)
            {
                instance.ApplicationContext = ApplicationContext;
            }

            if (TransactionManager != null)
            {
                instance.TransactionManager = TransactionManager;
            }

            if (PrefetchCount.HasValue)
            {
                instance.PrefetchCount = PrefetchCount.Value;
            }

            if (DefaultRequeueRejected.HasValue)
            {
                instance.DefaultRequeueRejected = DefaultRequeueRejected.Value;
            }

            if (RecoveryBackOff != null)
            {
                instance.RecoveryBackOff = RecoveryBackOff;
            }

            if (MismatchedQueuesFatal.HasValue)
            {
                instance.MismatchedQueuesFatal = MismatchedQueuesFatal.Value;
            }

            if (MissingQueuesFatal.HasValue)
            {
                instance.MissingQueuesFatal = MissingQueuesFatal.Value;
            }

            if (ConsumerTagStrategy != null)
            {
                instance.ConsumerTagStrategy = ConsumerTagStrategy;
            }

            if (IdleEventInterval.HasValue)
            {
                instance.IdleEventInterval = IdleEventInterval.Value;
            }

            if (FailedDeclarationRetryInterval.HasValue)
            {
                instance.FailedDeclarationRetryInterval = FailedDeclarationRetryInterval.Value;
            }

            if (AutoStartup.HasValue)
            {
                instance.IsAutoStartup = AutoStartup.Value;
            }

            instance.Phase = Phase;
            if (AfterReceivePostProcessors != null)
            {
                instance.SetAfterReceivePostProcessors(AfterReceivePostProcessors.ToArray());
            }

            if (DeBatchingEnabled.HasValue)
            {
                instance.IsDeBatchingEnabled = DeBatchingEnabled.Value;
            }

            if (BatchListener && DeBatchingEnabled.HasValue)
            {
                // turn off container debatching by default for batch listeners
                instance.IsDeBatchingEnabled = false;
            }

            if (endpoint != null)
            {
                if (endpoint.AutoStartup.HasValue)
                {
                    instance.IsAutoStartup = endpoint.AutoStartup.Value;
                }

                if (endpoint.AckMode.HasValue)
                {
                    instance.AcknowledgeMode = endpoint.AckMode.Value;
                }

                if (endpoint.BatchingStrategy != null)
                {
                    instance.BatchingStrategy = endpoint.BatchingStrategy;
                }

                instance.ListenerId    = endpoint.Id;
                endpoint.BatchListener = BatchListener;
                endpoint.SetupListenerContainer(instance);
            }

            var adapterListener = instance.MessageListener as AbstractMessageListenerAdapter;

            if (adapterListener != null)
            {
                if (BeforeSendReplyPostProcessors != null)
                {
                    adapterListener.SetBeforeSendReplyPostProcessors(BeforeSendReplyPostProcessors.ToArray());
                }

                if (RetryTemplate != null)
                {
                    adapterListener.RetryTemplate = RetryTemplate;
                    if (ReplyRecoveryCallback != null)
                    {
                        adapterListener.RecoveryCallback = ReplyRecoveryCallback;
                    }
                }

                if (DefaultRequeueRejected.HasValue)
                {
                    adapterListener.DefaultRequeueRejected = DefaultRequeueRejected.Value;
                }

                if (endpoint != null && endpoint.ReplyPostProcessor != null)
                {
                    adapterListener.ReplyPostProcessor = endpoint.ReplyPostProcessor;
                }
            }

            InitializeContainer(instance, endpoint);

            ContainerCustomizer?.Invoke(instance);

            return(instance);
        }
 protected override void InitializeContainer(DirectMessageListenerContainer instance, IRabbitListenerEndpoint endpoint)
 {
     base.InitializeContainer(instance, endpoint);
 }