Example usage for org.springframework.amqp.rabbit.listener RabbitListenerEndpoint getGroup

List of usage examples for org.springframework.amqp.rabbit.listener RabbitListenerEndpoint getGroup

Introduction

In this page you can find the example usage for org.springframework.amqp.rabbit.listener RabbitListenerEndpoint getGroup.

Prototype

String getGroup();

Source Link

Usage

From source file:org.springframework.amqp.rabbit.listener.RabbitListenerEndpointRegistry.java

/**
 * 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./* w w  w  . ja v a  2 s. c o m*/
 * <p>The {@code startImmediately} flag determines if the container should be
 * started immediately.
 * @param endpoint the endpoint to add.
 * @param factory the {@link RabbitListenerContainerFactory} to use.
 * @param startImmediately start the container immediately if necessary
 * @see #getListenerContainers()
 * @see #getListenerContainer(String)
 */
@SuppressWarnings("unchecked")
public void registerListenerContainer(RabbitListenerEndpoint endpoint,
        RabbitListenerContainerFactory<?> factory, boolean startImmediately) {
    Assert.notNull(endpoint, "Endpoint must not be null");
    Assert.notNull(factory, "Factory must not be null");

    String id = endpoint.getId();
    Assert.hasText(id, "Endpoint id must not be empty");
    synchronized (this.listenerContainers) {
        Assert.state(!this.listenerContainers.containsKey(id),
                "Another endpoint is already registered with id '" + id + "'");
        MessageListenerContainer container = createListenerContainer(endpoint, factory);
        this.listenerContainers.put(id, container);
        if (StringUtils.hasText(endpoint.getGroup()) && this.applicationContext != null) {
            List<MessageListenerContainer> containerGroup;
            if (this.applicationContext.containsBean(endpoint.getGroup())) {
                containerGroup = this.applicationContext.getBean(endpoint.getGroup(), List.class);
            } else {
                containerGroup = new ArrayList<MessageListenerContainer>();
                this.applicationContext.getBeanFactory().registerSingleton(endpoint.getGroup(), containerGroup);
            }
            containerGroup.add(container);
        }
        if (startImmediately) {
            startIfNecessary(container);
        }
    }
}