Search in sources :

Example 1 with Context

use of io.micronaut.context.annotation.Context in project micronaut-kafka by micronaut-projects.

the class KafkaStreamsFactory method kafkaStreams.

/**
 * Builds the default {@link KafkaStreams} bean from the configuration and the supplied {@link ConfiguredStreamBuilder}.
 *
 * @param name     The configuration name
 * @param builder  The builder
 * @param kStreams The KStream definitions
 * @return The {@link KafkaStreams} bean
 */
@EachBean(ConfiguredStreamBuilder.class)
@Context
KafkaStreams kafkaStreams(@Parameter String name, ConfiguredStreamBuilder builder, KStream<?, ?>... kStreams) {
    Topology topology = builder.build(builder.getConfiguration());
    KafkaStreams kafkaStreams = new KafkaStreams(topology, builder.getConfiguration());
    eventPublisher.publishEvent(new BeforeKafkaStreamStart(kafkaStreams, kStreams));
    streams.put(kafkaStreams, builder);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Initializing Application {} with topology:\n{}", name, topology.describe().toString());
    }
    kafkaStreams.start();
    eventPublisher.publishEvent(new AfterKafkaStreamsStart(kafkaStreams, kStreams));
    return kafkaStreams;
}
Also used : KafkaStreams(org.apache.kafka.streams.KafkaStreams) BeforeKafkaStreamStart(io.micronaut.configuration.kafka.streams.event.BeforeKafkaStreamStart) Topology(org.apache.kafka.streams.Topology) AfterKafkaStreamsStart(io.micronaut.configuration.kafka.streams.event.AfterKafkaStreamsStart) Context(io.micronaut.context.annotation.Context) EachBean(io.micronaut.context.annotation.EachBean)

Aggregations

AfterKafkaStreamsStart (io.micronaut.configuration.kafka.streams.event.AfterKafkaStreamsStart)1 BeforeKafkaStreamStart (io.micronaut.configuration.kafka.streams.event.BeforeKafkaStreamStart)1 Context (io.micronaut.context.annotation.Context)1 EachBean (io.micronaut.context.annotation.EachBean)1 KafkaStreams (org.apache.kafka.streams.KafkaStreams)1 Topology (org.apache.kafka.streams.Topology)1