Hi Team,
I writed custom Interceptor of Camunda 8 Self-Managed Zeebe Gateway version 8.5.5.
After build fat jar and add interceptor to Zeebe Gateway, it throw exception:
2024-09-05 18:16:16 at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:774) [spring-boot-3.2.5.jar:3.2.5]
2024-09-05 18:16:16 at org.springframework.boot.SpringApplication.run(SpringApplication.java:341) [spring-boot-3.2.5.jar:3.2.5]
2024-09-05 18:16:16 at io.camunda.zeebe.gateway.StandaloneGateway.main(StandaloneGateway.java:88) [camunda-zeebe-8.5.5.jar:8.5.5]
2024-09-05 18:16:16 Caused by: java.util.concurrent.ExecutionException: io.camunda.zeebe.gateway.interceptors.impl.InterceptorLoadException: Cannot load interceptor [CustomTenancyInterceptor]: specified class does not implement ServerInterceptor
2024-09-05 18:16:16 at io.camunda.zeebe.scheduler.future.CompletableActorFuture.get(CompletableActorFuture.java:147) ~[zeebe-scheduler-8.5.5.jar:8.5.5]
2024-09-05 18:16:16 at io.camunda.zeebe.scheduler.FutureUtil.join(FutureUtil.java:32) ~[zeebe-scheduler-8.5.5.jar:8.5.5]
2024-09-05 18:16:16 at io.camunda.zeebe.scheduler.future.CompletableActorFuture.join(CompletableActorFuture.java:208) ~[zeebe-scheduler-8.5.5.jar:8.5.5]
2024-09-05 18:16:16 at io.camunda.zeebe.gateway.StandaloneGateway.run(StandaloneGateway.java:121) ~[camunda-zeebe-8.5.5.jar:8.5.5]
2024-09-05 18:16:16 at org.springframework.boot.SpringApplication.lambda$callRunner$5(SpringApplication.java:790) ~[spring-boot-3.2.5.jar:3.2.5]
2024-09-05 18:16:16 at org.springframework.util.function.ThrowingConsumer$1.acceptWithException(ThrowingConsumer.java:83) ~[spring-core-6.1.10.jar:6.1.10]
2024-09-05 18:16:16 at org.springframework.util.function.ThrowingConsumer.accept(ThrowingConsumer.java:60) ~[spring-core-6.1.10.jar:6.1.10]
2024-09-05 18:16:16 ... 15 more
2024-09-05 18:16:16 Caused by: java.util.concurrent.CompletionException: io.camunda.zeebe.gateway.interceptors.impl.InterceptorLoadException: Cannot load interceptor [CustomTenancyInterceptor]: specified class does not implement ServerInterceptor
2024-09-05 18:16:16 at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(Unknown Source) ~[?:?]
2024-09-05 18:16:16 at java.base/java.util.concurrent.CompletableFuture.completeThrowable(Unknown Source) ~[?:?]
2024-09-05 18:16:16 at java.base/java.util.concurrent.CompletableFuture.biApply(Unknown Source) ~[?:?]
2024-09-05 18:16:16 at java.base/java.util.concurrent.CompletableFuture$BiApply.tryFire(Unknown Source) ~[?:?]
2024-09-05 18:16:16 at java.base/java.util.concurrent.CompletableFuture.postComplete(Unknown Source) ~[?:?]
2024-09-05 18:16:16 at java.base/java.util.concurrent.CompletableFuture.complete(Unknown Source) ~[?:?]
2024-09-05 18:16:16 at io.camunda.zeebe.gateway.Gateway.lambda$startClientStreamAdapter$1(Gateway.java:170) ~[zeebe-gateway-8.5.5.jar:8.5.5]
2024-09-05 18:16:16 at io.camunda.zeebe.scheduler.future.CompletableActorFuture.lambda$onComplete$1(CompletableActorFuture.java:248) ~[zeebe-scheduler-8.5.5.jar:8.5.5]
2024-09-05 18:16:16 at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(Unknown Source) ~[?:?]
2024-09-05 18:16:16 at java.base/java.util.concurrent.ForkJoinTask.doExec(Unknown Source) ~[?:?]
2024-09-05 18:16:16 at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(Unknown Source) ~[?:?]
2024-09-05 18:16:16 at java.base/java.util.concurrent.ForkJoinPool.scan(Unknown Source) ~[?:?]
2024-09-05 18:16:16 at java.base/java.util.concurrent.ForkJoinPool.runWorker(Unknown Source) ~[?:?]
2024-09-05 18:16:16 at java.base/java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source) ~[?:?]
2024-09-05 18:16:16 Caused by: io.camunda.zeebe.gateway.interceptors.impl.InterceptorLoadException: Cannot load interceptor [CustomTenancyInterceptor]: specified class does not implement ServerInterceptor
This is my maven dependency
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.demo</groupId>
<artifactId>zeebe-gateway-interceptor</artifactId>
<version>1</version>
<name>zeebe-gateway-interceptor</name>
<description>zeebe-gateway-interceptor</description>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<version.java>21</version.java>
<version.zeebe>8.5.5</version.zeebe>
<version.slf4>1.7.32</version.slf4>
<version.grpc>1.62.2</version.grpc>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/io.grpc/grpc-protobuf-lite -->
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-core</artifactId>
<version>${version.grpc}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${version.slf4}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${version.slf4}</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>5.1.5</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.7.1</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>assemble-all</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Docker compose:
version: "2"
networks:
zeebe_network:
driver: bridge
services:
gateway:
restart: always
container_name: gateway
image: camunda/zeebe:8.5.5
environment:
- ZEEBE_LOG_LEVEL=debug
- ZEEBE_STANDALONE_GATEWAY=true
- ZEEBE_GATEWAY_NETWORK_HOST=0.0.0.0
- ZEEBE_GATEWAY_NETWORK_PORT=26500
- ZEEBE_GATEWAY_CLUSTER_CONTACTPOINT=node0:26502
- ZEEBE_GATEWAY_CLUSTER_PORT=26502
- ZEEBE_GATEWAY_CLUSTER_HOST=gateway
- ZEEBE_GATEWAY_MULTITENANCY_ENABLED=true
- ZEEBE_GATEWAY_INTERCEPTORS_0_ID=CustomTenancyInterceptor
- ZEEBE_GATEWAY_INTERCEPTORS_0_JARPATH=cutomInterceptor/interceptor.jar
- ZEEBE_GATEWAY_INTERCEPTORS_0_CLASSNAME=com.demo.zeebegatewayinterceptor.CustomTenancyInterceptor
- REDIS_HOST=localhost
- REDIS_PORT=6379
ports:
- "26500:26500"
networks:
- zeebe_network
volumes:
- ./target/zeebe-gateway-interceptor-1-jar-with-dependencies.jar:/usr/local/zeebe/cutomInterceptor/interceptor.jar
node0:
container_name: zeebe_broker_1
image: camunda/zeebe:8.5.5
environment:
- ZEEBE_LOG_LEVEL=debug
- ZEEBE_BROKER_CLUSTER_NODEID=0
- ZEEBE_BROKER_CLUSTER_PARTITIONSCOUNT=2
- ZEEBE_BROKER_CLUSTER_REPLICATIONFACTOR=3
- ZEEBE_BROKER_CLUSTER_CLUSTERSIZE=3
- ZEEBE_BROKER_CLUSTER_INITIALCONTACTPOINTS=node0:26502,node1:26502,node2:26502
networks:
- zeebe_network
node1:
container_name: zeebe_broker_2
image: camunda/zeebe:8.5.5
environment:
- ZEEBE_LOG_LEVEL=debug
- ZEEBE_BROKER_CLUSTER_NODEID=1
- ZEEBE_BROKER_CLUSTER_PARTITIONSCOUNT=2
- ZEEBE_BROKER_CLUSTER_REPLICATIONFACTOR=3
- ZEEBE_BROKER_CLUSTER_CLUSTERSIZE=3
- ZEEBE_BROKER_CLUSTER_INITIALCONTACTPOINTS=node0:26502,node1:26502,node2:26502
networks:
- zeebe_network
depends_on:
- node0
node2:
container_name: zeebe_broker_3
image: camunda/zeebe:8.5.5
environment:
- ZEEBE_LOG_LEVEL=debug
- ZEEBE_BROKER_CLUSTER_NODEID=2
- ZEEBE_BROKER_CLUSTER_PARTITIONSCOUNT=2
- ZEEBE_BROKER_CLUSTER_REPLICATIONFACTOR=3
- ZEEBE_BROKER_CLUSTER_CLUSTERSIZE=3
- ZEEBE_BROKER_CLUSTER_INITIALCONTACTPOINTS=node0:26502,node1:26502,node2:26502
networks:
- zeebe_network
depends_on:
- node1
Code in class Interceptor:
import io.grpc.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import redis.clients.jedis.Jedis;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
public final class CustomTenancyInterceptor implements ServerInterceptor {
private final static Logger LOGGER = LoggerFactory.getLogger("CustomTenancyInterceptor");
private static final Context.Key<List<String>> AUTHORIZED_TENANTS_KEY =
Context.key("io.camunda.zeebe:authorized_tenants");
private final Jedis jedis;
public static final String REDIS_CONFIG_HOST_ENV =
"REDIS_HOST";
public static final String REDIS_CONFIG_PORT_ENV =
"REDIS_PORT";
public CustomTenancyInterceptor() {
this(
System.getenv(REDIS_CONFIG_HOST_ENV),
System.getenv(REDIS_CONFIG_PORT_ENV)
);
}
private CustomTenancyInterceptor(String host, String port) {
LOGGER.info("redisConfigProp- host: {}, port:{}", host, port);
jedis = new Jedis(host, Integer.parseInt(port));
checkConnectRedis();
}
public void checkConnectRedis() {
LOGGER.info("jedis ping: {}", jedis.ping());
}
@Override
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next) {
Set<String> projectAlias = jedis.smembers("projects");
LOGGER.info("projectAlias: {}", projectAlias);
final Context currentContext = setAuthorizedTenants(new ArrayList<>(projectAlias));
return Contexts.interceptCall(currentContext, call, headers, next);
}
public static Context setAuthorizedTenants(final List<String> authorizedTenants) {
return Context.current().withValue(getAuthorizedTenantsKey(), authorizedTenants);
}
public static Context.Key<List<String>> getAuthorizedTenantsKey() {
return AUTHORIZED_TENANTS_KEY;
}
}
Any one know resolve this issues, thanks ?