Example usage for org.springframework.kafka.config KafkaListenerContainerFactory createListenerContainer

List of usage examples for org.springframework.kafka.config KafkaListenerContainerFactory createListenerContainer

Introduction

In this page you can find the example usage for org.springframework.kafka.config KafkaListenerContainerFactory createListenerContainer.

Prototype

C createListenerContainer(KafkaListenerEndpoint endpoint);

Source Link

Document

Create a MessageListenerContainer for the given KafkaListenerEndpoint .

Usage

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

/**
 * Create and start a new {@link MessageListenerContainer} using the specified factory.
 * @param endpoint the endpoint to create a {@link MessageListenerContainer}.
 * @param factory the {@link KafkaListenerContainerFactory} to use.
 * @return the {@link MessageListenerContainer}.
 *//*from ww  w.  j av  a2  s  . c  o  m*/
protected MessageListenerContainer createListenerContainer(KafkaListenerEndpoint endpoint,
        KafkaListenerContainerFactory<?> factory) {

    MessageListenerContainer listenerContainer = factory.createListenerContainer(endpoint);

    if (listenerContainer instanceof InitializingBean) {
        try {
            ((InitializingBean) listenerContainer).afterPropertiesSet();
        } catch (Exception ex) {
            throw new BeanInitializationException("Failed to initialize message listener container", ex);
        }
    }

    int containerPhase = listenerContainer.getPhase();
    if (containerPhase < Integer.MAX_VALUE) { // a custom phase value
        if (this.phase < Integer.MAX_VALUE && this.phase != containerPhase) {
            throw new IllegalStateException("Encountered phase mismatch between container factory definitions: "
                    + this.phase + " vs " + containerPhase);
        }
        this.phase = listenerContainer.getPhase();
    }

    return listenerContainer;
}