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

Restore context decorator #2007

Merged
merged 4 commits into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ updates:
- "3.0"
- dependency-name: org.slf4j:slf4j-log4j12
versions:
- "<1.8.0"
- "> 1.8.0"
- dependency-name: org.slf4j:simple
versions:
- "<1.8.0"
- "> 1.8.0"
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
<jandex-maven-plugin.version>1.2.3</jandex-maven-plugin.version>

<nats-embedded.version>2.1.0</nats-embedded.version>
<slf4j-log4j12.version>2.0.5</slf4j-log4j12.version>
<slf4j-log4j12.version>1.7.36</slf4j-log4j12.version>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should ban slf4j 2 for now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've fixed the dependabot config (I think)

<opencsv.version>5.7.1</opencsv.version>
<strimzi-test-container.version>0.102.0</strimzi-test-container.version>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
import io.smallrye.reactive.messaging.health.HealthReport;
import io.smallrye.reactive.messaging.health.HealthReporter;
import io.smallrye.reactive.messaging.providers.connectors.ExecutionHolder;
import io.smallrye.reactive.messaging.providers.locals.ContextOperator;
import io.vertx.amqp.AmqpClientOptions;
import io.vertx.amqp.AmqpReceiverOptions;
import io.vertx.amqp.AmqpSenderOptions;
Expand Down Expand Up @@ -254,7 +253,7 @@ public PublisherBuilder<? extends Message<?>> getPublisherBuilder(Config config)
multi = multi.broadcast().toAllSubscribers();
}

return ReactiveStreams.fromPublisher(multi.plug(ContextOperator::apply));
return ReactiveStreams.fromPublisher(multi);
}

@Override
Expand Down
15 changes: 13 additions & 2 deletions smallrye-reactive-messaging-kafka/revapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,18 @@
"criticality" : "highlight",
"minSeverity" : "POTENTIALLY_BREAKING",
"minCriticality" : "documented",
"differences" : [ ]
"differences" : [
{
"code": "java.method.removed",
"old": "method org.eclipse.microprofile.reactive.streams.operators.PublisherBuilder<? extends org.eclipse.microprofile.reactive.messaging.Message<?>> io.smallrye.reactive.messaging.kafka.KafkaConnector::getPublisherBuilder(org.eclipse.microprofile.config.Config)",
"justification": "KafkaConnector moved to InboundConnector API"
},
{
"code": "java.method.removed",
"old": "method org.eclipse.microprofile.reactive.streams.operators.SubscriberBuilder<? extends org.eclipse.microprofile.reactive.messaging.Message<?>, java.lang.Void> io.smallrye.reactive.messaging.kafka.KafkaConnector::getSubscriberBuilder(org.eclipse.microprofile.config.Config)",
"justification": "KafkaConnector moved to OutboundConnector API"
}
]
}
}, {
"extension" : "revapi.reporter.json",
Expand All @@ -43,4 +54,4 @@
"minCriticality" : "documented",
"output" : "out"
}
} ]
} ]
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,16 @@
import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.reactive.messaging.Message;
import org.eclipse.microprofile.reactive.messaging.spi.Connector;
import org.eclipse.microprofile.reactive.messaging.spi.IncomingConnectorFactory;
import org.eclipse.microprofile.reactive.messaging.spi.OutgoingConnectorFactory;
import org.eclipse.microprofile.reactive.streams.operators.PublisherBuilder;
import org.eclipse.microprofile.reactive.streams.operators.ReactiveStreams;
import org.eclipse.microprofile.reactive.streams.operators.SubscriberBuilder;
import org.reactivestreams.Publisher;
import org.reactivestreams.Subscriber;

import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.trace.Tracer;
import io.smallrye.mutiny.Multi;
import io.smallrye.reactive.messaging.annotations.ConnectorAttribute;
import io.smallrye.reactive.messaging.annotations.ConnectorAttribute.Direction;
import io.smallrye.reactive.messaging.connector.InboundConnector;
import io.smallrye.reactive.messaging.connector.OutboundConnector;
import io.smallrye.reactive.messaging.health.HealthReport;
import io.smallrye.reactive.messaging.health.HealthReporter;
import io.smallrye.reactive.messaging.kafka.commit.KafkaCommitHandler;
Expand Down Expand Up @@ -116,7 +114,7 @@
@ConnectorAttribute(name = "propagate-headers", direction = Direction.OUTGOING, description = "A comma-separating list of incoming record headers to be propagated to the outgoing record", type = "string", defaultValue = "")
@ConnectorAttribute(name = "key-serialization-failure-handler", type = "string", direction = Direction.OUTGOING, description = "The name set in `@Identifier` of a bean that implements `io.smallrye.reactive.messaging.kafka.SerializationFailureHandler`. If set, serialization failure happening when serializing keys are delegated to this handler which may provide a fallback value.")
@ConnectorAttribute(name = "value-serialization-failure-handler", type = "string", direction = Direction.OUTGOING, description = "The name set in `@Identifier` of a bean that implements `io.smallrye.reactive.messaging.kafka.SerializationFailureHandler`. If set, serialization failure happening when serializing values are delegated to this handler which may provide a fallback value.")
public class KafkaConnector implements IncomingConnectorFactory, OutgoingConnectorFactory, HealthReporter {
public class KafkaConnector implements InboundConnector, OutboundConnector, HealthReporter {

public static final String CONNECTOR_NAME = "smallrye-kafka";

Expand Down Expand Up @@ -171,7 +169,7 @@ void init() {
}

@Override
public PublisherBuilder<? extends Message<?>> getPublisherBuilder(Config config) {
public Publisher<? extends Message<?>> getPublisher(Config config) {
Config channelConfiguration = ConfigHelper.retrieveChannelConfiguration(configurations, config);

KafkaConnectorIncomingConfiguration ic = new KafkaConnectorIncomingConfiguration(channelConfiguration);
Expand Down Expand Up @@ -207,9 +205,9 @@ public PublisherBuilder<? extends Message<?>> getPublisherBuilder(Config config)
stream = source.getBatchStream();
}
if (broadcast) {
return ReactiveStreams.fromPublisher(stream.broadcast().toAllSubscribers());
return stream.broadcast().toAllSubscribers();
} else {
return ReactiveStreams.fromPublisher(stream);
return stream;
}
}

Expand All @@ -235,14 +233,14 @@ public PublisherBuilder<? extends Message<?>> getPublisherBuilder(Config config)
.streams(streams.toArray(new Publisher[0]));
boolean broadcast = ic.getBroadcast();
if (broadcast) {
return ReactiveStreams.fromPublisher(multi.broadcast().toAllSubscribers());
return multi.broadcast().toAllSubscribers();
} else {
return ReactiveStreams.fromPublisher(multi);
return multi;
}
}

@Override
public SubscriberBuilder<? extends Message<?>, Void> getSubscriberBuilder(Config config) {
public Subscriber<? extends Message<?>> getSubscriber(Config config) {
Config channelConfiguration = ConfigHelper.retrieveChannelConfiguration(configurations, config);

KafkaConnectorOutgoingConfiguration oc = new KafkaConnectorOutgoingConfiguration(channelConfiguration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
import org.apache.kafka.common.header.Headers;
import org.apache.kafka.common.serialization.StringSerializer;
import org.eclipse.microprofile.reactive.messaging.Message;
import org.eclipse.microprofile.reactive.streams.operators.ReactiveStreams;
import org.eclipse.microprofile.reactive.streams.operators.SubscriberBuilder;
import org.reactivestreams.Subscriber;

import io.smallrye.mutiny.Uni;
import io.smallrye.reactive.messaging.OutgoingMessageMetadata;
Expand All @@ -44,6 +43,7 @@
import io.smallrye.reactive.messaging.kafka.api.OutgoingKafkaRecordMetadata;
import io.smallrye.reactive.messaging.kafka.health.KafkaSinkHealth;
import io.smallrye.reactive.messaging.kafka.impl.ce.KafkaCloudEventHelper;
import io.smallrye.reactive.messaging.providers.helpers.MultiUtils;

@SuppressWarnings("jol")
public class KafkaSink {
Expand All @@ -52,7 +52,7 @@ public class KafkaSink {
private final int partition;
private final String topic;
private final String key;
private final SubscriberBuilder<? extends Message<?>, Void> subscriber;
private final Subscriber<? extends Message<?>> subscriber;

private final long retries;
private final int deliveryTimeoutMs;
Expand Down Expand Up @@ -118,13 +118,10 @@ public KafkaSink(KafkaConnectorOutgoingConfiguration config, KafkaCDIEvents kafk
}
this.processor = new KafkaSenderProcessor(requests, waitForWriteCompletion,
writeMessageToKafka());
this.subscriber = ReactiveStreams.<Message<?>> builder()
.via(processor)
.onError(f -> {
log.unableToDispatch(f);
reportFailure(f);
})
.ignore();
this.subscriber = MultiUtils.via(processor, m -> m.onFailure().invoke(f -> {
log.unableToDispatch(f);
reportFailure(f);
}));

}

Expand Down Expand Up @@ -310,7 +307,7 @@ private Object getKey(Message<?> message,
return key;
}

public SubscriberBuilder<? extends Message<?>, Void> getSink() {
public Subscriber<? extends Message<?>> getSink() {
return subscriber;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import io.smallrye.reactive.messaging.kafka.commit.*;
import io.smallrye.reactive.messaging.kafka.fault.KafkaFailureHandler;
import io.smallrye.reactive.messaging.kafka.health.KafkaSourceHealth;
import io.smallrye.reactive.messaging.providers.locals.ContextOperator;
import io.vertx.core.impl.EventLoopContext;
import io.vertx.core.impl.VertxInternal;
import io.vertx.mutiny.core.Vertx;
Expand Down Expand Up @@ -157,8 +156,7 @@ public KafkaSource(Vertx vertx,
incomingMulti = incomingMulti.onItem().invoke(record -> incomingTrace(record, false));
}
this.stream = incomingMulti
.onFailure().invoke(t -> reportFailure(t, false))
.plug(ContextOperator::apply);
.onFailure().invoke(t -> reportFailure(t, false));
this.batchStream = null;
} else {
Multi<ConsumerRecords<K, V>> multi;
Expand Down Expand Up @@ -188,8 +186,7 @@ public KafkaSource(Vertx vertx,
incomingMulti = incomingMulti.onItem().invoke(this::incomingTrace);
}
this.batchStream = incomingMulti
.onFailure().invoke(t -> reportFailure(t, false))
.plug(ContextOperator::apply);
.onFailure().invoke(t -> reportFailure(t, false));
this.stream = null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void testSinkUsingInteger() {
KafkaConnectorOutgoingConfiguration oc = new KafkaConnectorOutgoingConfiguration(config);
sink = new KafkaSink(oc, CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance());

Subscriber<? extends Message<?>> subscriber = sink.getSink().build();
Subscriber<? extends Message<?>> subscriber = sink.getSink();
Multi.createFrom().range(0, 10)
.map(Message::of)
.subscribe((Subscriber<? super Message<Integer>>) subscriber);
Expand All @@ -78,7 +78,7 @@ public void testSinkUsingIntegerAndChannelName() {
KafkaConnectorOutgoingConfiguration oc = new KafkaConnectorOutgoingConfiguration(config);
sink = new KafkaSink(oc, CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance());

Subscriber<? extends Message<?>> subscriber = sink.getSink().build();
Subscriber<? extends Message<?>> subscriber = sink.getSink();
Multi.createFrom().range(0, 10)
.map(Message::of)
.subscribe((Subscriber<? super Message<Integer>>) subscriber);
Expand All @@ -99,7 +99,7 @@ public void testSinkUsingString() {
KafkaConnectorOutgoingConfiguration oc = new KafkaConnectorOutgoingConfiguration(config);
sink = new KafkaSink(oc, CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance());

Subscriber<? extends Message<?>> subscriber = sink.getSink().build();
Subscriber<? extends Message<?>> subscriber = sink.getSink();
Multi.createFrom().range(0, 10)
.map(i -> Integer.toString(i))
.map(Message::of)
Expand Down Expand Up @@ -238,7 +238,7 @@ public void testInvalidPayloadType() {

List<Object> acked = new CopyOnWriteArrayList<>();
List<Object> nacked = new CopyOnWriteArrayList<>();
Subscriber subscriber = sink.getSink().build();
Subscriber subscriber = sink.getSink();
Multi.createFrom().range(0, 6)
.map(i -> {
if (i == 3 || i == 5) {
Expand Down Expand Up @@ -279,7 +279,7 @@ public void testInvalidTypeWithDefaultInflightMessages() {
KafkaConnectorOutgoingConfiguration oc = new KafkaConnectorOutgoingConfiguration(config);
sink = new KafkaSink(oc, CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance());

Subscriber subscriber = sink.getSink().build();
Subscriber subscriber = sink.getSink();
Multi.createFrom().range(0, 5)
.map(i -> {
if (i == 3 || i == 5) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void testSinkUsingInteger() {
KafkaConnectorOutgoingConfiguration oc = new KafkaConnectorOutgoingConfiguration(config);
sink = new KafkaSink(oc, CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance());

Subscriber<? extends Message<?>> subscriber = sink.getSink().build();
Subscriber<? extends Message<?>> subscriber = sink.getSink();
Multi.createFrom().range(0, 10)
.map(Message::of)
.subscribe((Subscriber<? super Message<Integer>>) subscriber);
Expand All @@ -83,7 +83,7 @@ public void testSinkUsingIntegerAndChannelName() {
KafkaConnectorOutgoingConfiguration oc = new KafkaConnectorOutgoingConfiguration(config);
sink = new KafkaSink(oc, CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance());

Subscriber<? extends Message<?>> subscriber = sink.getSink().build();
Subscriber<? extends Message<?>> subscriber = sink.getSink();
Multi.createFrom().range(0, 10)
.map(Message::of)
.subscribe((Subscriber<? super Message<Integer>>) subscriber);
Expand All @@ -104,7 +104,7 @@ public void testSinkUsingString() {
KafkaConnectorOutgoingConfiguration oc = new KafkaConnectorOutgoingConfiguration(config);
sink = new KafkaSink(oc, CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance());

Subscriber<? extends Message<?>> subscriber = sink.getSink().build();
Subscriber<? extends Message<?>> subscriber = sink.getSink();
Multi.createFrom().range(0, 10)
.map(i -> Integer.toString(i))
.map(Message::of)
Expand Down Expand Up @@ -244,7 +244,7 @@ public void testInvalidPayloadType() {

List<Object> acked = new CopyOnWriteArrayList<>();
List<Object> nacked = new CopyOnWriteArrayList<>();
Subscriber subscriber = sink.getSink().build();
Subscriber subscriber = sink.getSink();
Multi.createFrom().range(0, 6)
.map(i -> {
if (i == 3 || i == 5) {
Expand Down Expand Up @@ -285,7 +285,7 @@ public void testInvalidTypeWithDefaultInflightMessages() {
KafkaConnectorOutgoingConfiguration oc = new KafkaConnectorOutgoingConfiguration(config);
sink = new KafkaSink(oc, CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance());

Subscriber subscriber = sink.getSink().build();
Subscriber subscriber = sink.getSink();
Multi.createFrom().range(0, 5)
.map(i -> {
if (i == 3 || i == 5) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.apache.kafka.common.serialization.IntegerDeserializer;
import org.eclipse.microprofile.reactive.messaging.Channel;
import org.eclipse.microprofile.reactive.messaging.Message;
import org.eclipse.microprofile.reactive.streams.operators.PublisherBuilder;
import org.jboss.weld.exceptions.DeploymentException;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Tag;
Expand Down Expand Up @@ -149,13 +148,12 @@ public void testBroadcast() {
connector.failureHandlerFactories = new SingletonInstance<>("fail", new KafkaFailStop.Factory());
connector.init();

PublisherBuilder<? extends KafkaRecord> builder = (PublisherBuilder<? extends KafkaRecord>) connector
.getPublisherBuilder(config);
Multi<? extends KafkaRecord> multi = (Multi<? extends KafkaRecord>) connector.getPublisher(config);

List<KafkaRecord> messages1 = new ArrayList<>();
List<KafkaRecord> messages2 = new ArrayList<>();
builder.forEach(messages1::add).run();
builder.forEach(messages2::add).run();
multi.subscribe().with(messages1::add);
multi.subscribe().with(messages2::add);

companion.produceIntegers().usingGenerator(i -> new ProducerRecord<>(topic, i), 10);

Expand Down Expand Up @@ -190,13 +188,12 @@ public void testBroadcastWithPartitions() {
connector.failureHandlerFactories = new SingletonInstance<>("fail", new KafkaFailStop.Factory());
connector.init();

PublisherBuilder<? extends KafkaRecord> builder = (PublisherBuilder<? extends KafkaRecord>) connector
.getPublisherBuilder(config);
Multi<? extends KafkaRecord> multi = (Multi<? extends KafkaRecord>) connector.getPublisher(config);

List<KafkaRecord> messages1 = new ArrayList<>();
List<KafkaRecord> messages2 = new ArrayList<>();
builder.forEach(messages1::add).run();
builder.forEach(messages2::add).run();
multi.subscribe().with(messages1::add);
multi.subscribe().with(messages2::add);

companion.produceIntegers().usingGenerator(i -> new ProducerRecord<>(topic, i), 10);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.apache.kafka.common.serialization.IntegerDeserializer;
import org.eclipse.microprofile.reactive.messaging.Channel;
import org.eclipse.microprofile.reactive.messaging.Message;
import org.eclipse.microprofile.reactive.streams.operators.PublisherBuilder;
import org.jboss.weld.exceptions.DeploymentException;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Tag;
Expand Down Expand Up @@ -154,13 +153,12 @@ public void testBroadcast() {
connector.kafkaCDIEvents = testEvents;
connector.init();

PublisherBuilder<? extends KafkaRecord> builder = (PublisherBuilder<? extends KafkaRecord>) connector
.getPublisherBuilder(config);
Multi<? extends KafkaRecord> multi = (Multi<? extends KafkaRecord>) connector.getPublisher(config);

List<KafkaRecord> messages1 = new ArrayList<>();
List<KafkaRecord> messages2 = new ArrayList<>();
builder.forEach(messages1::add).run();
builder.forEach(messages2::add).run();
multi.subscribe().with(messages1::add);
multi.subscribe().with(messages2::add);

companion.produceIntegers().usingGenerator(i -> new ProducerRecord<>(topic, i), 10);

Expand Down Expand Up @@ -195,13 +193,12 @@ public void testBroadcastWithPartitions() {
connector.failureHandlerFactories = new SingletonInstance<>("fail", new KafkaFailStop.Factory());
connector.init();

PublisherBuilder<? extends KafkaRecord> builder = (PublisherBuilder<? extends KafkaRecord>) connector
.getPublisherBuilder(config);
Multi<? extends KafkaRecord> multi = (Multi<? extends KafkaRecord>) connector.getPublisher(config);

List<KafkaRecord> messages1 = new ArrayList<>();
List<KafkaRecord> messages2 = new ArrayList<>();
builder.forEach(messages1::add).run();
builder.forEach(messages2::add).run();
multi.subscribe().with(messages1::add);
multi.subscribe().with(messages2::add);

companion.produceIntegers().usingGenerator(i -> new ProducerRecord<>(topic, i), 10);

Expand Down
Loading