Example usage for org.springframework.kafka.config KafkaListenerEndpoint getGroup

List of usage examples for org.springframework.kafka.config KafkaListenerEndpoint getGroup

Introduction

In this page you can find the example usage for org.springframework.kafka.config KafkaListenerEndpoint getGroup.

Prototype

String getGroup();

Source Link

Document

Return the group of this endpoint or null if not in a group.

Usage

From source file:org.springframework.kafka.config.KafkaListenerEndpointRegistry.java

/**
 * Create a message listener container for the given {@link KafkaListenerEndpoint}.
 * <p>This create the necessary infrastructure to honor that endpoint
 * with regards to its configuration.//  w  w w . ja  va2 s .c  om
 * <p>The {@code startImmediately} flag determines if the container should be
 * started immediately.
 * @param endpoint the endpoint to add.
 * @param factory the {@link KafkaListenerContainerFactory} to use.
 * @param startImmediately start the container immediately if necessary
 * @see #getListenerContainers()
 * @see #getListenerContainer(String)
 */
@SuppressWarnings("unchecked")
public void registerListenerContainer(KafkaListenerEndpoint endpoint, KafkaListenerContainerFactory<?> 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);
        }
    }
}