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 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(); } } }
private IRabbitListenerContainerFactory ResolveContainerFactory(RabbitListenerAttribute rabbitListener, object factoryTarget, string name) { IRabbitListenerContainerFactory factory = null; var containerFactoryBeanName = Resolve(rabbitListener.ContainerFactory); if (!string.IsNullOrEmpty(containerFactoryBeanName)) { if (ApplicationContext == null) { throw new InvalidOperationException("IApplicationContext must be set to resolve container factory by name"); } factory = ApplicationContext.GetService <IRabbitListenerContainerFactory>(containerFactoryBeanName); if (factory == null) { throw new InvalidOperationException("Could not register rabbit listener endpoint on [" + factoryTarget + "], no IRabbitListenerContainerFactory with id '" + containerFactoryBeanName + "' was found"); } } return(factory); }
public void RegisterListenerContainer(IRabbitListenerEndpoint endpoint, IRabbitListenerContainerFactory factory) { RegisterListenerContainer(endpoint, factory, false); }
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 RabbitListenerEndpointDescriptor(IRabbitListenerEndpoint endpoint, IRabbitListenerContainerFactory containerFactory) { Endpoint = endpoint; ContainerFactory = containerFactory; }