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); } } }
private IRabbitListenerContainerFactory ResolveContainerFactory(AmqpListenerEndpointDescriptor descriptor) { if (descriptor.ContainerFactory != null) { return(descriptor.ContainerFactory); } else if (ContainerFactory != null) { return(ContainerFactory); } else if (ContainerFactoryServiceName != null) { if (ApplicationContext == null) { throw new InvalidOperationException("BeanFactory must be set to obtain container factory by bean name"); } ContainerFactory = ApplicationContext.GetService <IRabbitListenerContainerFactory>(ContainerFactoryServiceName); return(ContainerFactory); } else { throw new InvalidOperationException("Could not resolve the IRabbitListenerContainerFactory to use for [" + descriptor.Endpoint + "] no factory was given and no default is set."); } }