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;
}
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));
}
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();
}
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;
}
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;
}
Aggregations