/** * Create a message listener container for the given {@link RabbitListenerEndpoint}. * <p>This create the necessary infrastructure to honor that endpoint * with regards to its configuration. * @param endpoint the endpoint to add * @param factory the listener factory to use * @see #registerListenerContainer(RabbitListenerEndpoint, RabbitListenerContainerFactory, boolean) */ public void registerListenerContainer(RabbitListenerEndpoint endpoint, RabbitListenerContainerFactory<?> factory) { registerListenerContainer(endpoint, factory, false); }
/** * Create a message listener container for the given {@link RabbitListenerEndpoint}. * <p>This create the necessary infrastructure to honor that endpoint * with regards to its configuration. * @param endpoint the endpoint to add * @param factory the listener factory to use * @see #registerListenerContainer(RabbitListenerEndpoint, RabbitListenerContainerFactory, boolean) */ public void registerListenerContainer(RabbitListenerEndpoint endpoint, RabbitListenerContainerFactory<?> factory) { registerListenerContainer(endpoint, factory, false); }
protected void registerAllEndpoints() { Assert.state(this.endpointRegistry != null, "No registry available"); synchronized (this.endpointDescriptors) { for (AmqpListenerEndpointDescriptor descriptor : this.endpointDescriptors) { this.endpointRegistry.registerListenerContainer(// NOSONAR never null descriptor.endpoint, resolveContainerFactory(descriptor)); } this.startImmediately = true; // trigger immediate startup } }
protected void registerAllEndpoints() { Assert.state(this.endpointRegistry != null, "No registry available"); synchronized (this.endpointDescriptors) { for (AmqpListenerEndpointDescriptor descriptor : this.endpointDescriptors) { this.endpointRegistry.registerListenerContainer(// NOSONAR never null descriptor.endpoint, resolveContainerFactory(descriptor)); } this.startImmediately = true; // trigger immediate startup } }
/** * Register a new {@link RabbitListenerEndpoint} alongside the * {@link RabbitListenerContainerFactory} to use to create the underlying container. * <p>The {@code factory} may be {@code null} if the default factory has to be * used for that endpoint. * @param endpoint the {@link RabbitListenerEndpoint} instance to register. * @param factory the {@link RabbitListenerContainerFactory} to use. */ public void registerEndpoint(RabbitListenerEndpoint endpoint, @Nullable RabbitListenerContainerFactory<?> factory) { Assert.notNull(endpoint, "Endpoint must be set"); Assert.hasText(endpoint.getId(), "Endpoint id must be set"); Assert.state(!this.startImmediately || this.endpointRegistry != null, "No registry available"); // Factory may be null, we defer the resolution right before actually creating the container AmqpListenerEndpointDescriptor descriptor = new AmqpListenerEndpointDescriptor(endpoint, factory); synchronized (this.endpointDescriptors) { if (this.startImmediately) { // Register and start immediately this.endpointRegistry.registerListenerContainer(descriptor.endpoint, // NOSONAR never null resolveContainerFactory(descriptor), true); } else { this.endpointDescriptors.add(descriptor); } } }
/** * Register a new {@link RabbitListenerEndpoint} alongside the * {@link RabbitListenerContainerFactory} to use to create the underlying container. * <p>The {@code factory} may be {@code null} if the default factory has to be * used for that endpoint. * @param endpoint the {@link RabbitListenerEndpoint} instance to register. * @param factory the {@link RabbitListenerContainerFactory} to use. */ public void registerEndpoint(RabbitListenerEndpoint endpoint, @Nullable RabbitListenerContainerFactory<?> factory) { Assert.notNull(endpoint, "Endpoint must be set"); Assert.hasText(endpoint.getId(), "Endpoint id must be set"); Assert.state(!this.startImmediately || this.endpointRegistry != null, "No registry available"); // Factory may be null, we defer the resolution right before actually creating the container AmqpListenerEndpointDescriptor descriptor = new AmqpListenerEndpointDescriptor(endpoint, factory); synchronized (this.endpointDescriptors) { if (this.startImmediately) { // Register and start immediately this.endpointRegistry.registerListenerContainer(descriptor.endpoint, // NOSONAR never null resolveContainerFactory(descriptor), true); } else { this.endpointDescriptors.add(descriptor); } } }
@Test public void createWithDuplicateEndpointId() { registry.registerListenerContainer(createEndpoint("test", "queue"), containerFactory); thrown.expect(IllegalStateException.class); registry.registerListenerContainer(createEndpoint("test", "queue"), containerFactory); }
@Test public void createWithNullEndpoint() { thrown.expect(IllegalArgumentException.class); registry.registerListenerContainer(null, containerFactory); }
@Test public void createWithNullEndpointId() { thrown.expect(IllegalArgumentException.class); registry.registerListenerContainer(new SimpleRabbitListenerEndpoint(), containerFactory); }
@Test public void createWithNullContainerFactory() { thrown.expect(IllegalArgumentException.class); registry.registerListenerContainer(createEndpoint("foo", "myDestination"), null); }