Search in sources :

Example 1 with Singleton

use of jakarta.inject.Singleton in project micronaut-elasticsearch by micronaut-projects.

the class DefaultElasticsearchClientFactory method elasticsearchTransport.

/**
 * @param elasticsearchConfiguration The {@link DefaultElasticsearchConfigurationProperties} object.
 * @param objectMapper The {@link ObjectMapper} object.
 * @return The {@link ElasticsearchTransport}.
 * @since 4.2.0
 */
@Singleton
@Bean(preDestroy = "close")
ElasticsearchTransport elasticsearchTransport(DefaultElasticsearchConfigurationProperties elasticsearchConfiguration, ObjectMapper objectMapper) {
    RestClient restClient = restClientBuilder(elasticsearchConfiguration).build();
    ElasticsearchTransport transport = new RestClientTransport(restClient, new JacksonJsonpMapper(objectMapper));
    return transport;
}
Also used : ElasticsearchTransport(co.elastic.clients.transport.ElasticsearchTransport) RestClientTransport(co.elastic.clients.transport.rest_client.RestClientTransport) RestClient(org.elasticsearch.client.RestClient) JacksonJsonpMapper(co.elastic.clients.json.jackson.JacksonJsonpMapper) Singleton(jakarta.inject.Singleton) Bean(io.micronaut.context.annotation.Bean)

Example 2 with Singleton

use of jakarta.inject.Singleton in project core by weld.

the class WeldSEBeanRegistrant method registerWeldSEContexts.

public void registerWeldSEContexts(@Observes AfterBeanDiscovery event, BeanManager manager) {
    if (ignoreEvent(event)) {
        return;
    }
    final String contextId = BeanManagerProxy.unwrap(manager).getContextId();
    this.threadContext = new ThreadContext(contextId);
    event.addContext(threadContext);
    // Register WeldContainer as a singleton
    event.addBean().addType(WeldContainer.class).addQualifier(Default.Literal.INSTANCE).scope(Singleton.class).produceWith((i) -> WeldContainer.instance(contextId));
}
Also used : Singleton(jakarta.inject.Singleton) ThreadContext(org.jboss.weld.environment.se.contexts.ThreadContext)

Example 3 with Singleton

use of jakarta.inject.Singleton in project micronaut-kafka by micronaut-projects.

the class OptimizationStream method optimizationOff.

@Singleton
@Named(STREAM_OPTIMIZATION_OFF)
KStream<String, String> optimizationOff(@Named(STREAM_OPTIMIZATION_OFF) ConfiguredStreamBuilder builder) {
    // set default serdes
    Properties props = builder.getConfiguration();
    props.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass().getName());
    props.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.String().getClass().getName());
    props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
    KTable<String, String> table = builder.table(OPTIMIZATION_OFF_INPUT, Materialized.as(OPTIMIZATION_OFF_STORE));
    return table.toStream();
}
Also used : Properties(java.util.Properties) Named(jakarta.inject.Named) Singleton(jakarta.inject.Singleton)

Example 4 with Singleton

use of jakarta.inject.Singleton in project micronaut-kafka by micronaut-projects.

the class WordCountStream method myStream.

@Singleton
@Named(MY_STREAM)
KStream<String, String> myStream(@Named(MY_STREAM) ConfiguredStreamBuilder builder) {
    // end::namedStream[]
    // set default serdes
    Properties props = builder.getConfiguration();
    props.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass().getName());
    props.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.String().getClass().getName());
    props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
    KStream<String, String> source = builder.stream(NAMED_WORD_COUNT_INPUT);
    KTable<String, Long> counts = source.flatMapValues(value -> Arrays.asList(value.toLowerCase(Locale.getDefault()).split(" "))).groupBy((key, value) -> value).count();
    // need to override value serde to Long type
    counts.toStream().to(NAMED_WORD_COUNT_OUTPUT, Produced.with(Serdes.String(), Serdes.Long()));
    return source;
}
Also used : StreamsConfig(org.apache.kafka.streams.StreamsConfig) KTable(org.apache.kafka.streams.kstream.KTable) Arrays(java.util.Arrays) Properties(java.util.Properties) Produced(org.apache.kafka.streams.kstream.Produced) Singleton(jakarta.inject.Singleton) ConsumerConfig(org.apache.kafka.clients.consumer.ConsumerConfig) KStream(org.apache.kafka.streams.kstream.KStream) Grouped(org.apache.kafka.streams.kstream.Grouped) ConfiguredStreamBuilder(io.micronaut.configuration.kafka.streams.ConfiguredStreamBuilder) Factory(io.micronaut.context.annotation.Factory) Locale(java.util.Locale) Materialized(org.apache.kafka.streams.kstream.Materialized) Serdes(org.apache.kafka.common.serialization.Serdes) Named(jakarta.inject.Named) Properties(java.util.Properties) Named(jakarta.inject.Named) Singleton(jakarta.inject.Singleton)

Example 5 with Singleton

use of jakarta.inject.Singleton in project micronaut-kafka by micronaut-projects.

the class WordCountStream method wordCountStream.

// end::clazz[]
// tag::wordCountStream[]
@Singleton
@Named(STREAM_WORD_COUNT)
KStream<String, String> wordCountStream(ConfiguredStreamBuilder builder) {
    // <3>
    // set default serdes
    Properties props = builder.getConfiguration();
    props.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass().getName());
    props.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.String().getClass().getName());
    props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
    KStream<String, String> source = builder.stream(INPUT);
    KTable<String, Long> groupedByWord = source.flatMapValues(value -> Arrays.asList(value.toLowerCase().split("\\W+"))).groupBy((key, word) -> word, Grouped.with(Serdes.String(), Serdes.String())).count(// <4>
    Materialized.as(WORD_COUNT_STORE));
    groupedByWord.toStream().to(OUTPUT, Produced.with(Serdes.String(), Serdes.Long()));
    return source;
}
Also used : StreamsConfig(org.apache.kafka.streams.StreamsConfig) KTable(org.apache.kafka.streams.kstream.KTable) Arrays(java.util.Arrays) Properties(java.util.Properties) Produced(org.apache.kafka.streams.kstream.Produced) Singleton(jakarta.inject.Singleton) ConsumerConfig(org.apache.kafka.clients.consumer.ConsumerConfig) KStream(org.apache.kafka.streams.kstream.KStream) Grouped(org.apache.kafka.streams.kstream.Grouped) ConfiguredStreamBuilder(io.micronaut.configuration.kafka.streams.ConfiguredStreamBuilder) Factory(io.micronaut.context.annotation.Factory) Locale(java.util.Locale) Materialized(org.apache.kafka.streams.kstream.Materialized) Serdes(org.apache.kafka.common.serialization.Serdes) Named(jakarta.inject.Named) Properties(java.util.Properties) Named(jakarta.inject.Named) Singleton(jakarta.inject.Singleton)

Aggregations

Singleton (jakarta.inject.Singleton)26 Bean (io.micronaut.context.annotation.Bean)7 Factory (io.micronaut.context.annotation.Factory)6 Properties (java.util.Properties)6 GraphQLSchema (graphql.schema.GraphQLSchema)5 BufferedReader (java.io.BufferedReader)5 InputStreamReader (java.io.InputStreamReader)5 GraphQL (graphql.GraphQL)4 RuntimeWiring (graphql.schema.idl.RuntimeWiring)4 SchemaGenerator (graphql.schema.idl.SchemaGenerator)4 SchemaParser (graphql.schema.idl.SchemaParser)4 TypeDefinitionRegistry (graphql.schema.idl.TypeDefinitionRegistry)4 ResourceResolver (io.micronaut.core.io.ResourceResolver)4 Named (jakarta.inject.Named)4 Test (org.junit.Test)3 ConfiguredStreamBuilder (io.micronaut.configuration.kafka.streams.ConfiguredStreamBuilder)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Arrays (java.util.Arrays)2 Locale (java.util.Locale)2 ConsumerConfig (org.apache.kafka.clients.consumer.ConsumerConfig)2