Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Micronaut 4 snapshot #617

Merged
merged 13 commits into from
Nov 17, 2022
4 changes: 2 additions & 2 deletions .github/workflows/central-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ jobs:
- name: Set up JDK
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '11'
distribution: 'adopt'
graemerocher marked this conversation as resolved.
Show resolved Hide resolved
java-version: '17'
- name: Publish to Sonatype OSSRH
env:
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/graalvm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
java: ['11', '17']
java: ['17']
graalvm: ['latest', 'dev']
steps:
# https://github.com/actions/virtual-environments/issues/709
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
java: ['8', '11', '17']
java: ['17']
steps:
# https://github.com/actions/virtual-environments/issues/709
- name: Free disk space
Expand Down Expand Up @@ -72,7 +72,7 @@ jobs:
name: binary-compatibility-reports
path: "**/build/reports/binary-compatibility-*.html"
- name: Publish to Sonatype Snapshots
if: success() && github.event_name == 'push' && matrix.java == '11'
if: success() && github.event_name == 'push' && matrix.java == '17'
env:
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
Expand All @@ -88,7 +88,7 @@ jobs:
if_true: "micronaut-projects/micronaut-docs"
if_false: ${{ github.repository }}
- name: Publish to Github Pages
if: success() && github.event_name == 'push' && matrix.java == '11'
if: success() && github.event_name == 'push' && matrix.java == '17'
uses: micronaut-projects/github-pages-deploy-action@master
env:
TARGET_REPOSITORY: ${{ steps.docs_target.outputs.value }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish-snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ jobs:
- name: Set up JDK
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '11'
distribution: 'adopt'
graemerocher marked this conversation as resolved.
Show resolved Hide resolved
java-version: '17'
- name: Publish to Sonatype Snapshots
if: success()
env:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ jobs:
- name: Set up JDK
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '11'
distribution: 'adopt'
graemerocher marked this conversation as resolved.
Show resolved Hide resolved
java-version: '17'
- name: Set the current release version
id: release_version
run: echo ::set-output name=release_version::${GITHUB_REF:11}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/sonarqube.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ jobs:
- name: Set up JDK
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 11
distribution: 'adopt'
graemerocher marked this conversation as resolved.
Show resolved Hide resolved
java-version: 17
- name: Optional setup step
env:
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
Expand Down
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
plugins {
id 'io.micronaut.build.internal.docs'
id 'io.micronaut.build.internal.dependency-updates'
id 'io.micronaut.build.internal.quality-reporting'
}

repositories {
mavenCentral()
maven { url "https://s01.oss.sonatype.org/content/repositories/snapshots/" }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
repositories {
mavenCentral()
maven { url "https://s01.oss.sonatype.org/content/repositories/snapshots/" }
}

configurations.all {
resolutionStrategy.dependencySubstitution {
substitute(module("org.codehaus.groovy:groovy"))
.using(module("org.apache.groovy:groovy:4.0.6"))
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
plugins {
id 'io.micronaut.build.internal.module'
id 'io.micronaut.build.internal.kafka-base'
}

dependencies {
api mn.micronaut.messaging
api mn.micronaut.json.core

compileOnly mn.micronaut.management

Expand All @@ -19,6 +21,7 @@ dependencies {
testRuntimeOnly mn.micronaut.reactor
testRuntimeOnly mn.micronaut.http.server.netty
testRuntimeOnly mn.micronaut.management
testRuntimeOnly mn.snakeyaml
}

configurations.all {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins {
id 'io.micronaut.build.internal.kafka-base'
}
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
projectVersion=4.5.1-SNAPSHOT
projectVersion=5.0.0-SNAPSHOT
projectGroup=io.micronaut.kafka

title=Micronaut Kafka
Expand All @@ -7,7 +7,7 @@ projectUrl=https://micronaut.io
githubSlug=micronaut-projects/micronaut-kafka
developers=Graeme Rocher

githubCoreBranch=3.8.x
githubCoreBranch=4.0.x
bomProperty=micronautKafkaVersion

testskafka=kafka/src/test/groovy/io/micronaut/configuration/kafka/docs
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[versions]
micronaut = "3.7.3"
micronaut = "4.0.0-SNAPSHOT"
micronaut-docs = "2.0.0"

# Required to keep catalog compatibility with 3.4.x. Can be removed for 4.0.0
managed-kafka-compat = "2.8.2"
managed-kafka = '2.8.2'

groovy = "3.0.11"
groovy = "4.0.6"

opentracing-kafka-client = '0.1.15'
opentracing-mock = '0.33.0'
Expand Down
1 change: 1 addition & 0 deletions kafka-streams/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ dependencies {
api libs.managed.kafka.streams
compileOnly mn.micronaut.micrometer.core
testImplementation mn.micronaut.http.client
testImplementation mn.micronaut.serde.jackson
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@

import io.micronaut.configuration.kafka.streams.event.AfterKafkaStreamsStart;
import io.micronaut.configuration.kafka.streams.event.BeforeKafkaStreamStart;
import io.micronaut.context.annotation.*;
import io.micronaut.context.annotation.Context;
import io.micronaut.context.annotation.EachBean;
import io.micronaut.context.annotation.Factory;
import io.micronaut.context.annotation.Parameter;
import io.micronaut.context.annotation.Secondary;
import io.micronaut.context.event.ApplicationEventPublisher;
import jakarta.annotation.PreDestroy;
import jakarta.inject.Singleton;
import org.apache.kafka.streams.KafkaClientSupplier;
import org.apache.kafka.streams.KafkaStreams;
import org.apache.kafka.streams.Topology;
Expand All @@ -27,8 +33,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.PreDestroy;
import jakarta.inject.Singleton;
import java.io.Closeable;
import java.time.Duration;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
package io.micronaut.configuration.kafka.streams.metrics;

import io.micronaut.configuration.kafka.metrics.AbstractKafkaMetricsReporter;
import jakarta.annotation.PreDestroy;

import javax.annotation.PreDestroy;

/**
* Kafka streams specific metrics reporter which prefixes all metrics with kafka-streams.
Expand Down
1 change: 1 addition & 0 deletions kafka/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ dependencies {
compileOnly mn.micronaut.graal
compileOnly mn.graal

testImplementation mn.micronaut.serde.jackson
testImplementation mn.micronaut.rxjava2
testImplementation mn.micronaut.http.client
testImplementation libs.opentracing.mock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,29 @@
public class KafkaHeaders implements MessageHeaders {

private final Headers headers;
private final ConversionService conversionService;

/**
* Constructs a new instance for the given headers.
*
* @param headers The kafka headers
*/
@Deprecated
public KafkaHeaders(Headers headers) {
this(headers, ConversionService.SHARED);
}

/**
* Constructs a new instance for the given headers.
*
* @param headers The kafka headers
* @param conversionService The conversion service
*/
public KafkaHeaders(Headers headers, ConversionService conversionService) {
Objects.requireNonNull(headers, "Argument [headers] cannot be null");
Objects.requireNonNull(conversionService, "Argument [conversionService] cannot be null");
this.headers = headers;
this.conversionService = conversionService;
}

@Override
Expand Down Expand Up @@ -87,7 +101,7 @@ public Collection<List<String>> values() {
public <T> Optional<T> get(CharSequence name, ArgumentConversionContext<T> conversionContext) {
String v = get(name);
if (v != null) {
return ConversionService.SHARED.convert(v, conversionContext);
return conversionService.convert(v, conversionContext);
}
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,6 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;

import javax.annotation.PreDestroy;

import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.common.serialization.Serializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.micronaut.configuration.kafka.annotation.KafkaClient;
import io.micronaut.configuration.kafka.config.AbstractKafkaProducerConfiguration;
import io.micronaut.configuration.kafka.config.DefaultKafkaProducerConfiguration;
Expand All @@ -53,6 +43,14 @@
import io.micronaut.inject.FieldInjectionPoint;
import io.micronaut.inject.InjectionPoint;
import io.micronaut.inject.qualifiers.Qualifiers;
import jakarta.annotation.PreDestroy;
import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.common.serialization.Serializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* A registry class for Kafka {@link org.apache.kafka.clients.producer.Producer} instances.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import io.micronaut.aop.Introduction;
import io.micronaut.context.annotation.AliasFor;
import io.micronaut.context.annotation.Property;
import io.micronaut.retry.annotation.Recoverable;
import jakarta.inject.Singleton;

import java.lang.annotation.Documented;
Expand All @@ -37,7 +36,6 @@
@Documented
@Retention(RUNTIME)
@Introduction
@Recoverable
@Singleton
public @interface KafkaClient {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@
import io.micronaut.core.bind.ArgumentBinder;
import io.micronaut.core.bind.ArgumentBinderRegistry;
import io.micronaut.core.bind.annotation.Bindable;
import io.micronaut.core.convert.ConversionService;
import io.micronaut.core.type.Argument;
import io.micronaut.core.util.ArrayUtils;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import org.apache.kafka.clients.consumer.ConsumerRecord;

import java.lang.annotation.Annotation;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;

/**
Expand All @@ -45,8 +48,21 @@ public class ConsumerRecordBinderRegistry implements ArgumentBinderRegistry<Cons
* Creates the registry for the given binders.
*
* @param binders The binders
* @deprecated Use conversion service constructor instead.
*/
@Deprecated
public ConsumerRecordBinderRegistry(ConsumerRecordBinder<?>... binders) {
this(ConversionService.SHARED, binders);
}

/**
* Creates the registry for the given binders.
*
* @param conversionService The conversion service
* @param binders The binders
*/
@Inject
public ConsumerRecordBinderRegistry(ConversionService conversionService, ConsumerRecordBinder<?>... binders) {
if (ArrayUtils.isNotEmpty(binders)) {
for (ConsumerRecordBinder<?> binder : binders) {
if (binder instanceof AnnotatedConsumerRecordBinder) {
Expand Down Expand Up @@ -77,11 +93,7 @@ public ConsumerRecordBinderRegistry(ConsumerRecordBinder<?>... binders) {
} else {
@SuppressWarnings("unchecked")
ConsumerRecordBinder<T> binder = (ConsumerRecordBinder<T>) byType.get(argument.typeHashCode());
if (binder != null) {
return Optional.of(binder);
} else {
return Optional.of(new KafkaDefaultBinder<>());
}
return Optional.of(Objects.requireNonNullElseGet(binder, KafkaDefaultBinder::new));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import io.micronaut.configuration.kafka.KafkaHeaders;
import io.micronaut.core.convert.ArgumentConversionContext;
import io.micronaut.core.convert.ConversionService;
import io.micronaut.core.type.Argument;
import io.micronaut.messaging.MessageHeaders;
import jakarta.inject.Singleton;
Expand All @@ -35,15 +36,20 @@ public class KafkaHeadersBinder implements TypedConsumerRecordBinder<MessageHead

public static final Argument<MessageHeaders> TYPE = Argument.of(MessageHeaders.class);

private final ConversionService conversionService;

public KafkaHeadersBinder(ConversionService conversionService) {
this.conversionService = conversionService;
}

@Override
public Argument<MessageHeaders> argumentType() {
return TYPE;
}

@Override
public BindingResult<MessageHeaders> bind(ArgumentConversionContext<MessageHeaders> context, ConsumerRecord<?, ?> source) {

KafkaHeaders kafkaHeaders = new KafkaHeaders(source.headers());
KafkaHeaders kafkaHeaders = new KafkaHeaders(source.headers(), conversionService);
return () -> Optional.of(kafkaHeaders);
}
}
Loading