You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by pk...@apache.org on 2026/10/05 20:00:47 UTC
(logging-flume-rpc) branch feat/rpc-client-provider created (now 055bd92)
This is an automated email from the ASF dual-hosted git repository.
ppkarwasz pushed a change to branch feat/rpc-client-provider
in repository https://gitbox.apache.org/repos/asf/logging-flume-rpc.git
at 055bd92 Register the Avro and Thrift clients as `RpcClientProvider`s
This branch includes the following new commits:
new 055bd92 Register the Avro and Thrift clients as `RpcClientProvider`s
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(logging-flume-rpc) 01/01: Register the Avro and Thrift clients as `RpcClientProvider`s
Posted by pk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ppkarwasz pushed a commit to branch feat/rpc-client-provider
in repository https://gitbox.apache.org/repos/asf/logging-flume-rpc.git
commit 055bd9200a4acc57f36189631827facd5fa9c1a4
Author: Piotr P. Karwasz <pi...@github.copernik.eu>
AuthorDate: Mon Oct 5 20:48:01 2026 +0200
Register the Avro and Thrift clients as `RpcClientProvider`s
The core no longer knows the class names of the transports: each client module registers a provider for its `client.type`. The Thrift provider chooses the Kerberos client when `kerberos` is enabled, so `ThriftSink` no longer needs to.
Assisted-By: Claude Opus 5.5 <no...@anthropic.com>
---
avro/client/pom.xml | 4 +++
.../flume/client/avro/NettyAvroRpcClient.java | 28 +++++++++++++++++--
thrift/client/pom.xml | 4 +++
.../flume/client/thrift/ThriftRpcClient.java | 32 +++++++++++++++++++---
.../org/apache/flume/sink/thrift/ThriftSink.java | 14 +++-------
5 files changed, 65 insertions(+), 17 deletions(-)
diff --git a/avro/client/pom.xml b/avro/client/pom.xml
index ca51fda..2e83021 100644
--- a/avro/client/pom.xml
+++ b/avro/client/pom.xml
@@ -42,6 +42,10 @@
<groupId>org.apache.flume</groupId>
<artifactId>flume-client</artifactId>
</dependency>
+ <dependency>
+ <groupId>biz.aQute.bnd</groupId>
+ <artifactId>biz.aQute.bnd.annotation</artifactId>
+ </dependency>
<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro</artifactId>
diff --git a/avro/client/src/main/java/org/apache/flume/client/avro/NettyAvroRpcClient.java b/avro/client/src/main/java/org/apache/flume/client/avro/NettyAvroRpcClient.java
index 74b2428..c0ba8ed 100644
--- a/avro/client/src/main/java/org/apache/flume/client/avro/NettyAvroRpcClient.java
+++ b/avro/client/src/main/java/org/apache/flume/client/avro/NettyAvroRpcClient.java
@@ -16,6 +16,8 @@
*/
package org.apache.flume.client.avro;
+import aQute.bnd.annotation.Resolution;
+import aQute.bnd.annotation.spi.ServiceProvider;
import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.compression.JZlibDecoder;
import io.netty.handler.codec.compression.JZlibEncoder;
@@ -59,10 +61,12 @@ import org.apache.avro.ipc.Transceiver;
import org.apache.avro.ipc.netty.NettyTransceiver;
import org.apache.avro.ipc.specific.SpecificRequestor;
import org.apache.commons.lang3.StringUtils;
-import org.apache.flume.api.AbstractRpcClient;
+import org.apache.flume.api.RpcClient;
import org.apache.flume.api.RpcClientConfigurationConstants;
import org.apache.flume.api.RpcDeliveryException;
-import org.apache.flume.api.SSLContextAwareAbstractRpcClient;
+import org.apache.flume.client.spi.AbstractRpcClient;
+import org.apache.flume.client.spi.RpcClientProvider;
+import org.apache.flume.client.spi.SSLContextAwareAbstractRpcClient;
import org.apache.flume.event.Event;
import org.apache.flume.source.avro.AvroFlumeEvent;
import org.apache.flume.source.avro.AvroSourceProtocol;
@@ -427,7 +431,6 @@ public class NettyAvroRpcClient extends SSLContextAwareAbstractRpcClient {
* @param properties The properties to instantiate the client with.
* @return
*/
- @Override
public synchronized void configure(Properties properties) throws IOException {
stateLock.lock();
try {
@@ -639,4 +642,23 @@ public class NettyAvroRpcClient extends SSLContextAwareAbstractRpcClient {
return new X509Certificate[0];
}
}
+
+ /**
+ * Provides the {@value RpcClientConfigurationConstants#AVRO_CLIENT_TYPE} client type.
+ */
+ @ServiceProvider(value = RpcClientProvider.class, resolution = Resolution.OPTIONAL)
+ public static final class Provider implements RpcClientProvider {
+
+ @Override
+ public String getName() {
+ return RpcClientConfigurationConstants.AVRO_CLIENT_TYPE;
+ }
+
+ @Override
+ public RpcClient create(Properties properties) throws IOException {
+ NettyAvroRpcClient client = new NettyAvroRpcClient();
+ client.configure(properties);
+ return client;
+ }
+ }
}
diff --git a/thrift/client/pom.xml b/thrift/client/pom.xml
index 7050ebe..9b50136 100644
--- a/thrift/client/pom.xml
+++ b/thrift/client/pom.xml
@@ -44,6 +44,10 @@
<groupId>org.apache.flume</groupId>
<artifactId>flume-client</artifactId>
</dependency>
+ <dependency>
+ <groupId>biz.aQute.bnd</groupId>
+ <artifactId>biz.aQute.bnd.annotation</artifactId>
+ </dependency>
<dependency>
<groupId>org.apache.flume</groupId>
<artifactId>flume-auth</artifactId>
diff --git a/thrift/client/src/main/java/org/apache/flume/client/thrift/ThriftRpcClient.java b/thrift/client/src/main/java/org/apache/flume/client/thrift/ThriftRpcClient.java
index 07647a0..2e386e6 100644
--- a/thrift/client/src/main/java/org/apache/flume/client/thrift/ThriftRpcClient.java
+++ b/thrift/client/src/main/java/org/apache/flume/client/thrift/ThriftRpcClient.java
@@ -16,6 +16,8 @@
*/
package org.apache.flume.client.thrift;
+import aQute.bnd.annotation.Resolution;
+import aQute.bnd.annotation.spi.ServiceProvider;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
@@ -45,11 +47,13 @@ import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManagerFactory;
-import org.apache.flume.api.AbstractRpcClient;
-import org.apache.flume.api.HostInfo;
+import org.apache.flume.api.RpcClient;
import org.apache.flume.api.RpcClientConfigurationConstants;
import org.apache.flume.api.RpcDeliveryException;
-import org.apache.flume.api.SSLContextAwareAbstractRpcClient;
+import org.apache.flume.client.spi.AbstractRpcClient;
+import org.apache.flume.client.spi.HostInfo;
+import org.apache.flume.client.spi.RpcClientProvider;
+import org.apache.flume.client.spi.SSLContextAwareAbstractRpcClient;
import org.apache.flume.event.Event;
import org.apache.flume.thrift.Status;
import org.apache.flume.thrift.ThriftFlumeEvent;
@@ -263,7 +267,6 @@ public class ThriftRpcClient extends SSLContextAwareAbstractRpcClient {
}
}
- @Override
public void configure(Properties properties) throws IOException {
if (isActive()) {
throw new IllegalStateException("Attempting to re-configured an already " + "configured client!");
@@ -545,4 +548,25 @@ public class ThriftRpcClient extends SSLContextAwareAbstractRpcClient {
throw new IOException("Could not connect to " + host + " on port " + port, e);
}
}
+
+ /**
+ * Provides the {@value RpcClientConfigurationConstants#THRIFT_CLIENT_TYPE} client type.
+ */
+ @ServiceProvider(value = RpcClientProvider.class, resolution = Resolution.OPTIONAL)
+ public static final class Provider implements RpcClientProvider {
+
+ @Override
+ public String getName() {
+ return RpcClientConfigurationConstants.THRIFT_CLIENT_TYPE;
+ }
+
+ @Override
+ public RpcClient create(Properties properties) throws IOException {
+ boolean kerberos =
+ Boolean.parseBoolean(properties.getProperty(RpcClientConfigurationConstants.KERBEROS_KEY, "false"));
+ ThriftRpcClient client = kerberos ? new SecureThriftRpcClient() : new ThriftRpcClient();
+ client.configure(properties);
+ return client;
+ }
+ }
}
diff --git a/thrift/sink/src/main/java/org/apache/flume/sink/thrift/ThriftSink.java b/thrift/sink/src/main/java/org/apache/flume/sink/thrift/ThriftSink.java
index daadab7..ef24ef8 100644
--- a/thrift/sink/src/main/java/org/apache/flume/sink/thrift/ThriftSink.java
+++ b/thrift/sink/src/main/java/org/apache/flume/sink/thrift/ThriftSink.java
@@ -21,7 +21,6 @@ import java.util.Properties;
import org.apache.flume.api.RpcClient;
import org.apache.flume.api.RpcClientConfigurationConstants;
import org.apache.flume.api.RpcClientFactory;
-import org.apache.flume.client.thrift.SecureRpcClientFactory;
import org.apache.flume.sink.AbstractRpcSink;
/**
@@ -106,14 +105,9 @@ public class ThriftSink extends AbstractRpcSink {
// Only one thread is enough, since only one sink thread processes
// transactions at any given time. Each sink owns its own Rpc client.
props.setProperty(RpcClientConfigurationConstants.CONFIG_CONNECTION_POOL_SIZE, String.valueOf(1));
- boolean enableKerberos =
- Boolean.parseBoolean(props.getProperty(RpcClientConfigurationConstants.KERBEROS_KEY, "false"));
- if (enableKerberos) {
- return SecureRpcClientFactory.getThriftInstance(props);
- } else {
- props.setProperty(
- RpcClientConfigurationConstants.CONFIG_CLIENT_TYPE, RpcClientFactory.ClientType.THRIFT.name());
- return RpcClientFactory.getInstance(props);
- }
+ // The Thrift client provider chooses the secure client if Kerberos is enabled.
+ props.setProperty(
+ RpcClientConfigurationConstants.CONFIG_CLIENT_TYPE, RpcClientConfigurationConstants.THRIFT_CLIENT_TYPE);
+ return RpcClientFactory.getInstance(props);
}
}