From 60b5fbba9ff9cc1f52f8af17116352c9ae84910b Mon Sep 17 00:00:00 2001 From: Oleh Dokuka Date: Tue, 17 Dec 2019 21:05:07 +0200 Subject: [PATCH 1/9] provides updates to latest rsocket and rsocket-rpc --- build.gradle | 8 ++-- gradle.properties | 8 ++-- .../java/com/netifi/broker/BrokerClient.java | 16 +++++--- .../rsocket/NamedRSocketServiceWrapper.java | 17 ++------- .../BrokerClientIntegrationTest.java | 3 +- .../broker/influx/BrokerInfluxBridge.java | 1 + .../prometheus/BrokerPrometheusBridge.java | 1 + .../spring/boot/TestIdlServiceServer.java | 15 ++++++++ .../config/BrokerClientConfiguration.java | 38 ++++--------------- .../spring/core/TestIdlServiceServer.java | 15 ++++++++ .../tracing/BrokerZipkinHttpBridge.java | 1 + 11 files changed, 66 insertions(+), 57 deletions(-) diff --git a/build.gradle b/build.gradle index bb414fb2..6177da2a 100644 --- a/build.gradle +++ b/build.gradle @@ -44,9 +44,9 @@ if (details.branchName != null) { } allprojects { - dependencyLocking { - lockAllConfigurations() - } +// dependencyLocking { +// lockAllConfigurations() +// } project.version += versionSuffix ext { uniqueVersion = "${tmpUniqueVersion}" @@ -65,6 +65,8 @@ subprojects { targetCompatibility = 1.8 repositories { + + maven { url 'https://oss.jfrog.org/oss-snapshot-local' } maven { url 'https://nexus.netifi.com/repository/jcenter/' credentials { diff --git a/gradle.properties b/gradle.properties index 6f377eab..51b38aa5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ group=com.netifi -version=1.6.11 +version=1.6.11-prioritization netifiProtoExternalVersion=1.6.11-SNAPSHOT assertjVersion=3.12.1 @@ -26,10 +26,10 @@ nettyVersion=4.1.36.Final opentracingVersion=0.31.0 postgresqlVersion=42.2.5 protobufVersion=3.6.1 -reactorBomVersion=Californium-SR8 +reactorBomVersion=Dysprosium-RELEASE roaringbitmapVersion=0.7.42 -rsocketRpcVersion=0.2.18 -rsocketVersion=0.12.2-RC4 +rsocketRpcVersion=0.3.0-feature/prioritization-SNAPSHOT +rsocketVersion=1.0.0-RC6-bugfix/prioritization-SNAPSHOT rxjava2JdbcVersion=0.2.4 slf4jVersion=1.7.25 spectatorVersion=0.61.0 diff --git a/netifi-broker-client/src/main/java/com/netifi/broker/BrokerClient.java b/netifi-broker-client/src/main/java/com/netifi/broker/BrokerClient.java index 882b8b7c..d9c61920 100644 --- a/netifi-broker-client/src/main/java/com/netifi/broker/BrokerClient.java +++ b/netifi-broker-client/src/main/java/com/netifi/broker/BrokerClient.java @@ -20,7 +20,6 @@ import com.netifi.broker.info.Broker; import com.netifi.broker.rsocket.BrokerSocket; import com.netifi.broker.rsocket.NamedRSocketClientWrapper; -import com.netifi.broker.rsocket.NamedRSocketServiceWrapper; import com.netifi.broker.rsocket.transport.BrokerAddressSelectors; import com.netifi.common.tags.Tag; import com.netifi.common.tags.Tags; @@ -195,7 +194,8 @@ public BrokerClient addService(RSocketRpcService service) { public BrokerClient addNamedRSocket(String name, RSocket rSocket) { Objects.requireNonNull(name); Objects.requireNonNull(rSocket); - return addService(NamedRSocketServiceWrapper.wrap(name, rSocket)); + // return addService(NamedRSocketServiceWrapper.wrap(name, rSocket)); + return this; } @Deprecated @@ -605,7 +605,9 @@ public BrokerClient build() { clientTransportFactory = address -> { TcpClient client = - TcpClient.create().addressSupplier(() -> address).secure(sslContext); + TcpClient.create() + .addressSupplier(() -> address) + .secure(sslContextSpec -> sslContextSpec.sslContext(sslContext)); return WebsocketClientTransport.create(client); }; } catch (Exception sslException) { @@ -696,7 +698,9 @@ public BrokerClient build() { clientTransportFactory = address -> { TcpClient client = - TcpClient.create().addressSupplier(() -> address).secure(sslContext); + TcpClient.create() + .addressSupplier(() -> address) + .secure(sslContextSpec -> sslContextSpec.sslContext(sslContext)); return TcpClientTransport.create(client); }; } catch (Exception sslException) { @@ -1065,7 +1069,9 @@ public BrokerClient build() { clientTransportFactory = address -> { TcpClient client = - TcpClient.create().addressSupplier(() -> address).secure(sslContext); + TcpClient.create() + .addressSupplier(() -> address) + .secure(sslContextSpec -> sslContextSpec.sslContext(sslContext)); return TcpClientTransport.create(client); }; } catch (Exception sslException) { diff --git a/netifi-broker-client/src/main/java/com/netifi/broker/rsocket/NamedRSocketServiceWrapper.java b/netifi-broker-client/src/main/java/com/netifi/broker/rsocket/NamedRSocketServiceWrapper.java index 8b26083a..bbf05c15 100644 --- a/netifi-broker-client/src/main/java/com/netifi/broker/rsocket/NamedRSocketServiceWrapper.java +++ b/netifi-broker-client/src/main/java/com/netifi/broker/rsocket/NamedRSocketServiceWrapper.java @@ -27,7 +27,7 @@ import reactor.core.publisher.Flux; public class NamedRSocketServiceWrapper extends AbstractUnwrappingRSocket - implements RSocketRpcService { + implements ResponderRSocket { private final String name; private NamedRSocketServiceWrapper(String name, RSocket source) { @@ -60,23 +60,14 @@ protected Payload unwrap(Payload payload) { } @Override - public String getService() { - return name; - } - - @Override - public final Flux requestChannel(Payload payload, Flux publisher) { + public final Flux requestChannel(Payload payload, Publisher publisher) { if (source instanceof ResponderRSocket) { ResponderRSocket responderRSocket = (ResponderRSocket) source; - return responderRSocket.requestChannel(unwrap(payload), publisher.map(this::unwrap)); + return responderRSocket.requestChannel( + unwrap(payload), Flux.from(publisher).map(this::unwrap)); } return super.requestChannel(publisher); } - - @Override - public final Flux requestChannel(Payload payload, Publisher publisher) { - return requestChannel(payload, Flux.from(publisher)); - } } diff --git a/netifi-broker-client/src/test/java/com/netifi/broker/integration/BrokerClientIntegrationTest.java b/netifi-broker-client/src/test/java/com/netifi/broker/integration/BrokerClientIntegrationTest.java index 6bd52236..fb8ef979 100644 --- a/netifi-broker-client/src/test/java/com/netifi/broker/integration/BrokerClientIntegrationTest.java +++ b/netifi-broker-client/src/test/java/com/netifi/broker/integration/BrokerClientIntegrationTest.java @@ -77,7 +77,8 @@ public static void setup() { .build(); server.addService( - new SimpleServiceServer(new DefaultSimpleService(), Optional.empty(), Optional.empty())); + new SimpleServiceServer( + new DefaultSimpleService(), Optional.empty(), Optional.empty(), Optional.empty())); brokerSocket = brokerClient.groupServiceSocket("test.server", Tags.empty()); } diff --git a/netifi-metrics-influx/src/main/java/com/netifi/broker/influx/BrokerInfluxBridge.java b/netifi-metrics-influx/src/main/java/com/netifi/broker/influx/BrokerInfluxBridge.java index e4a026cf..92b4720f 100644 --- a/netifi-metrics-influx/src/main/java/com/netifi/broker/influx/BrokerInfluxBridge.java +++ b/netifi-metrics-influx/src/main/java/com/netifi/broker/influx/BrokerInfluxBridge.java @@ -130,6 +130,7 @@ public String retentionDuration() { return t; })), Optional.empty(), + Optional.empty(), Optional.empty())); brokerClient.onClose().block(); diff --git a/netifi-metrics-prometheus/src/main/java/com/netifi/broker/prometheus/BrokerPrometheusBridge.java b/netifi-metrics-prometheus/src/main/java/com/netifi/broker/prometheus/BrokerPrometheusBridge.java index 5a17e1f3..9437942d 100644 --- a/netifi-metrics-prometheus/src/main/java/com/netifi/broker/prometheus/BrokerPrometheusBridge.java +++ b/netifi-metrics-prometheus/src/main/java/com/netifi/broker/prometheus/BrokerPrometheusBridge.java @@ -105,6 +105,7 @@ public static void main(String... args) { Optional.ofNullable(bindPort), Optional.ofNullable(metricsUrl)), Optional.empty(), + Optional.empty(), Optional.empty())); brokerClient.onClose().block(); diff --git a/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/TestIdlServiceServer.java b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/TestIdlServiceServer.java index 0ab92b3a..d1ea8564 100644 --- a/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/TestIdlServiceServer.java +++ b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/TestIdlServiceServer.java @@ -15,7 +15,14 @@ */ package com.netifi.spring.boot; +import java.util.Map; + +import io.rsocket.Payload; +import io.rsocket.ipc.util.IPCChannelFunction; +import io.rsocket.ipc.util.IPCFunction; import io.rsocket.rpc.AbstractRSocketService; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; @javax.annotation.Generated( value = "by RSocket RPC proto compiler (version 0.2.2)", @@ -30,4 +37,12 @@ public class TestIdlServiceServer extends AbstractRSocketService { public Class getServiceClass() { return TestIdl.class; } + + @Override + public void selfRegister(Map>> fireAndForgetRegistry, + Map>> requestResponseRegistry, + Map>> requestStreamRegistry, + Map requestChannelRegistry) { + + } } diff --git a/netifi-spring-core/src/main/java/com/netifi/spring/core/config/BrokerClientConfiguration.java b/netifi-spring-core/src/main/java/com/netifi/spring/core/config/BrokerClientConfiguration.java index b33cd145..66ad79be 100644 --- a/netifi-spring-core/src/main/java/com/netifi/spring/core/config/BrokerClientConfiguration.java +++ b/netifi-spring-core/src/main/java/com/netifi/spring/core/config/BrokerClientConfiguration.java @@ -16,9 +16,6 @@ package com.netifi.spring.core.config; import com.netifi.broker.BrokerClient; -import com.netifi.broker.info.BlockingBrokerInfoService; -import com.netifi.broker.info.BlockingBrokerInfoServiceClient; -import com.netifi.broker.info.BlockingBrokerInfoServiceServer; import com.netifi.broker.info.BrokerInfoService; import com.netifi.broker.info.BrokerInfoServiceClient; import com.netifi.broker.info.BrokerInfoServiceServer; @@ -26,9 +23,7 @@ import com.netifi.spring.core.annotation.BrokerClientBeanDefinitionRegistryPostProcessor; import io.micrometer.core.instrument.MeterRegistry; import io.opentracing.Tracer; -import io.rsocket.rpc.metrics.om.BlockingMetricsSnapshotHandler; -import io.rsocket.rpc.metrics.om.BlockingMetricsSnapshotHandlerClient; -import io.rsocket.rpc.metrics.om.BlockingMetricsSnapshotHandlerServer; +import io.rsocket.ipc.MetadataDecoder; import io.rsocket.rpc.metrics.om.MetricsSnapshotHandler; import io.rsocket.rpc.metrics.om.MetricsSnapshotHandlerClient; import io.rsocket.rpc.metrics.om.MetricsSnapshotHandlerServer; @@ -40,7 +35,6 @@ import org.springframework.context.annotation.AnnotatedBeanDefinitionReader; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import reactor.core.scheduler.Scheduler; @Configuration public class BrokerClientConfiguration implements ApplicationContextAware { @@ -60,34 +54,20 @@ public BrokerClientApplicationEventListener brokerClientApplicationEventListener @Bean public BrokerInfoServiceServer brokerInfoServiceServer( BrokerInfoService brokerInfoService, + Optional metadataDecoder, Optional registry, Optional tracer) { - return new BrokerInfoServiceServer(brokerInfoService, registry, tracer); - } - - @Bean - public BlockingBrokerInfoServiceServer blockingBrokerInfoServiceServer( - BlockingBrokerInfoService blockingBrokerInfoService, - Optional scheduler, - Optional registry) { - return new BlockingBrokerInfoServiceServer(blockingBrokerInfoService, scheduler, registry); + return new BrokerInfoServiceServer(brokerInfoService, metadataDecoder, registry, tracer); } @Bean public MetricsSnapshotHandlerServer metricsSnapshotHandlerServer( MetricsSnapshotHandler metricsSnapshotHandler, + Optional metadataDecoder, Optional registry, Optional tracer) { - return new MetricsSnapshotHandlerServer(metricsSnapshotHandler, registry, tracer); - } - - @Bean - public BlockingMetricsSnapshotHandlerServer blockingMetricsSnapshotHandlerServer( - BlockingMetricsSnapshotHandler blockingMetricsSnapshotHandler, - Optional scheduler, - Optional registry) { - return new BlockingMetricsSnapshotHandlerServer( - blockingMetricsSnapshotHandler, scheduler, registry); + return new MetricsSnapshotHandlerServer( + metricsSnapshotHandler, metadataDecoder, registry, tracer); } @Override @@ -96,10 +76,6 @@ public void setApplicationContext(ApplicationContext applicationContext) throws (DefaultListableBeanFactory) applicationContext.getAutowireCapableBeanFactory(); AnnotatedBeanDefinitionReader reader = new AnnotatedBeanDefinitionReader(factory); - reader.register( - BlockingMetricsSnapshotHandlerClient.class, - MetricsSnapshotHandlerClient.class, - BlockingBrokerInfoServiceClient.class, - BrokerInfoServiceClient.class); + reader.register(MetricsSnapshotHandlerClient.class, BrokerInfoServiceClient.class); } } diff --git a/netifi-spring-core/src/test/java/com/netifi/spring/core/TestIdlServiceServer.java b/netifi-spring-core/src/test/java/com/netifi/spring/core/TestIdlServiceServer.java index 7f4945b7..b20f6344 100644 --- a/netifi-spring-core/src/test/java/com/netifi/spring/core/TestIdlServiceServer.java +++ b/netifi-spring-core/src/test/java/com/netifi/spring/core/TestIdlServiceServer.java @@ -15,7 +15,14 @@ */ package com.netifi.spring.core; +import java.util.Map; + +import io.rsocket.Payload; +import io.rsocket.ipc.util.IPCChannelFunction; +import io.rsocket.ipc.util.IPCFunction; import io.rsocket.rpc.AbstractRSocketService; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; @javax.annotation.Generated( value = "by RSocket RPC proto compiler (version 0.2.10)", @@ -30,4 +37,12 @@ public class TestIdlServiceServer extends AbstractRSocketService { public Class getServiceClass() { return TestIdl.class; } + + @Override + public void selfRegister(Map>> fireAndForgetRegistry, + Map>> requestResponseRegistry, + Map>> requestStreamRegistry, + Map requestChannelRegistry) { + + } } diff --git a/netifi-tracing-openzipkin/src/main/java/com/netifi/broker/tracing/BrokerZipkinHttpBridge.java b/netifi-tracing-openzipkin/src/main/java/com/netifi/broker/tracing/BrokerZipkinHttpBridge.java index edf18e94..afc38d8c 100644 --- a/netifi-tracing-openzipkin/src/main/java/com/netifi/broker/tracing/BrokerZipkinHttpBridge.java +++ b/netifi-tracing-openzipkin/src/main/java/com/netifi/broker/tracing/BrokerZipkinHttpBridge.java @@ -89,6 +89,7 @@ public static void main(String... args) { new BrokerTracingServiceServer( new BrokerZipkinHttpBridge(zipkinHost, zipkinPort, zipkinSpansUrl), Optional.empty(), + Optional.empty(), Optional.empty())); brokerClient.onClose().block(); From 21bec77ad1a34f40555f3de5fc5fb8208b5507d8 Mon Sep 17 00:00:00 2001 From: Oleh Dokuka Date: Fri, 20 Dec 2019 17:40:05 +0200 Subject: [PATCH 2/9] Merge remote-tracking branch 'rebranded/develop' into develop # Conflicts: # netifi-broker-client/src/main/java/com/netifi/broker/DefaultBuilderConfig.java # netifi-spring-core/src/main/java/com/netifi/spring/core/DestinationAwareClientFactory.java # netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClientStaticFactory.java --- build.gradle | 7 ++++--- dependency-management.gradle | 10 ++-------- gradle.properties | 6 +++--- settings.gradle | 22 +++++++++++----------- 4 files changed, 20 insertions(+), 25 deletions(-) diff --git a/build.gradle b/build.gradle index 6177da2a..4dac4377 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ buildscript { - configurations.classpath { - resolutionStrategy.activateDependencyLocking() - } +// configurations.classpath { +// resolutionStrategy.activateDependencyLocking() +// } } plugins { @@ -66,6 +66,7 @@ subprojects { repositories { + mavenCentral() maven { url 'https://oss.jfrog.org/oss-snapshot-local' } maven { url 'https://nexus.netifi.com/repository/jcenter/' diff --git a/dependency-management.gradle b/dependency-management.gradle index 0229ab87..1d044d40 100644 --- a/dependency-management.gradle +++ b/dependency-management.gradle @@ -9,6 +9,8 @@ dependencyManagement { mavenBom "org.apache.logging.log4j:log4j-bom:${log4j2Version}" mavenBom "org.junit:junit-bom:${junitJupiterVersion}" mavenBom "software.amazon.awssdk:bom:${awssdkVersion}" + mavenBom "io.rsocket:rsocket-bom:${rsocketVersion}" + mavenBom "com.google.protobuf:protobuf-bom:${protobufVersion}" } dependencies { @@ -16,8 +18,6 @@ dependencyManagement { dependency "com.github.davidmoten:rxjava2-jdbc:${rxjava2JdbcVersion}" dependency "com.google.guava:guava:${guavaVersion}" - dependency "com.google.protobuf:protobuf-java-util:${protobufVersion}" - dependency "com.google.protobuf:protobuf-java:${protobufVersion}" dependency "com.google.protobuf:protoc:${protobufVersion}" dependency "com.hubspot.jackson:jackson-datatype-protobuf:${jacksonProtobufVersion}" dependency "com.netflix.spectator:spectator-api:${spectatorVersion}" @@ -59,12 +59,6 @@ dependencyManagement { dependency "io.rsocket.rpc:rsocket-rpc-metrics-idl:${rsocketRpcVersion}" dependency "io.rsocket.rpc:rsocket-rpc-protobuf-idl:${rsocketRpcVersion}" dependency "io.rsocket.rpc:rsocket-rpc-protobuf:${rsocketRpcVersion}" - dependency "io.rsocket:rsocket-core:${rsocketVersion}" - dependency "io.rsocket:rsocket-load-balancer:${rsocketVersion}" - dependency "io.rsocket:rsocket-micrometer:${rsocketVersion}" - dependency "io.rsocket:rsocket-test:${rsocketVersion}" - dependency "io.rsocket:rsocket-transport-local:${rsocketVersion}" - dependency "io.rsocket:rsocket-transport-netty:${rsocketVersion}" dependency "io.zipkin.reporter2:zipkin-sender-okhttp3:${zipkinSenderVersion}" dependency "javax.annotation:javax.annotation-api:${javaxAnnotationVersion}" dependency "javax.inject:javax.inject:${javaxInjectVersion}" diff --git a/gradle.properties b/gradle.properties index 51b38aa5..d8fd036f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -25,11 +25,11 @@ nettyTcnativeVersion=2.0.25.Final nettyVersion=4.1.36.Final opentracingVersion=0.31.0 postgresqlVersion=42.2.5 -protobufVersion=3.6.1 +protobufVersion=3.7.1 reactorBomVersion=Dysprosium-RELEASE roaringbitmapVersion=0.7.42 -rsocketRpcVersion=0.3.0-feature/prioritization-SNAPSHOT -rsocketVersion=1.0.0-RC6-bugfix/prioritization-SNAPSHOT +rsocketRpcVersion=0.3.0-feature-prioritization-SNAPSHOT +rsocketVersion=1.0.0-RC6-bugfix-prioritization-SNAPSHOT rxjava2JdbcVersion=0.2.4 slf4jVersion=1.7.25 spectatorVersion=0.61.0 diff --git a/settings.gradle b/settings.gradle index abcfa576..dafa7718 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,14 +1,14 @@ -pluginManagement { - repositories { - maven { - url 'https://nexus.netifi.com/repository/maven-plugin-group/' - credentials { - username = "${netifiReadOnlyUsername}" - password = "${netifiReadOnlyPassword}" - } - } - } -} +//pluginManagement { +// repositories { +// maven { +// url 'https://nexus.netifi.com/repository/maven-plugin-group/' +// credentials { +// username = "${netifiReadOnlyUsername}" +// password = "${netifiReadOnlyPassword}" +// } +// } +// } +//} rootProject.name = 'netifi-java' From 0a9fbdef1025516dd09066bfa91d74f3bde5bbb9 Mon Sep 17 00:00:00 2001 From: Oleh Dokuka Date: Thu, 10 Oct 2019 17:41:11 +0300 Subject: [PATCH 3/9] updates to the lates RSocket version --- dependency-management.gradle | 2 +- gradle.properties | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- .../testCompileClasspath.lockfile | 15 ++++++++------- .../testRuntimeClasspath.lockfile | 15 ++++++++------- .../testCompileClasspath.lockfile | 15 ++++++++------- .../testRuntimeClasspath.lockfile | 15 ++++++++------- .../gradle/dependency-locks/compile.lockfile | 11 ++++++----- .../dependency-locks/compileClasspath.lockfile | 11 ++++++----- .../dependency-locks/testCompile.lockfile | 17 +++++++++-------- .../testCompileClasspath.lockfile | 17 +++++++++-------- .../testRuntimeClasspath.lockfile | 17 +++++++++-------- .../dependency-locks/compileClasspath.lockfile | 6 +++--- .../testCompileClasspath.lockfile | 15 ++++++++------- .../testRuntimeClasspath.lockfile | 15 ++++++++------- .../testCompileClasspath.lockfile | 15 ++++++++------- .../testRuntimeClasspath.lockfile | 15 ++++++++------- .../dependency-locks/compileClasspath.lockfile | 4 ++-- .../testCompileClasspath.lockfile | 15 ++++++++------- .../testRuntimeClasspath.lockfile | 15 ++++++++------- .../dependency-locks/compileClasspath.lockfile | 4 ++-- .../testCompileClasspath.lockfile | 15 ++++++++------- .../testRuntimeClasspath.lockfile | 15 ++++++++------- .../dependency-locks/compileClasspath.lockfile | 4 ++-- .../testCompileClasspath.lockfile | 15 ++++++++------- .../testRuntimeClasspath.lockfile | 15 ++++++++------- .../gradle/dependency-locks/compile.lockfile | 11 ++++++----- .../dependency-locks/compileClasspath.lockfile | 11 ++++++----- .../dependency-locks/testCompile.lockfile | 11 ++++++----- .../testCompileClasspath.lockfile | 11 ++++++----- .../gradle/dependency-locks/compile.lockfile | 11 ++++++----- .../dependency-locks/compileClasspath.lockfile | 11 ++++++----- .../dependency-locks/testCompile.lockfile | 15 ++++++++------- .../testCompileClasspath.lockfile | 15 ++++++++------- .../gradle/dependency-locks/compile.lockfile | 11 ++++++----- .../dependency-locks/compileClasspath.lockfile | 11 ++++++----- .../dependency-locks/testCompile.lockfile | 15 ++++++++------- .../testCompileClasspath.lockfile | 15 ++++++++------- .../dependency-locks/compileClasspath.lockfile | 4 ++-- .../testCompileClasspath.lockfile | 4 ++-- .../testRuntimeClasspath.lockfile | 4 ++-- .../dependency-locks/compileClasspath.lockfile | 4 ++-- .../testCompileClasspath.lockfile | 4 ++-- .../testRuntimeClasspath.lockfile | 4 ++-- .../gradle/dependency-locks/compile.lockfile | 13 +++++++------ .../dependency-locks/compileClasspath.lockfile | 13 +++++++------ .../dependency-locks/testCompile.lockfile | 17 +++++++++-------- .../testCompileClasspath.lockfile | 17 +++++++++-------- .../testRuntimeClasspath.lockfile | 17 +++++++++-------- 49 files changed, 296 insertions(+), 260 deletions(-) diff --git a/dependency-management.gradle b/dependency-management.gradle index 1d044d40..cafe615c 100644 --- a/dependency-management.gradle +++ b/dependency-management.gradle @@ -2,7 +2,7 @@ apply plugin: 'io.spring.dependency-management' dependencyManagement { imports { - + mavenBom "io.rsocket:rsocket-bom:${rsocketVersion}" mavenBom "com.fasterxml.jackson:jackson-bom:${jacksonVersion}" mavenBom "io.netty:netty-bom:${nettyVersion}" mavenBom "io.projectreactor:reactor-bom:${reactorBomVersion}" diff --git a/gradle.properties b/gradle.properties index d8fd036f..eea56849 100644 --- a/gradle.properties +++ b/gradle.properties @@ -35,4 +35,4 @@ slf4jVersion=1.7.25 spectatorVersion=0.61.0 typesafeConfigVersion=1.3.3 zipkinSenderVersion=2.7.6 -springBootDependenciesVersion=2.1.5.RELEASE +springBootDependenciesVersion=2.2.2.RELEASE diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index f4d7b2bf..ef9a9e05 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/netifi-broker-auth-jwt/gradle/dependency-locks/testCompileClasspath.lockfile b/netifi-broker-auth-jwt/gradle/dependency-locks/testCompileClasspath.lockfile index 8924f903..1db2da96 100644 --- a/netifi-broker-auth-jwt/gradle/dependency-locks/testCompileClasspath.lockfile +++ b/netifi-broker-auth-jwt/gradle/dependency-locks/testCompileClasspath.lockfile @@ -15,12 +15,13 @@ io.netty:netty-resolver:4.1.36.Final io.netty:netty-transport-native-epoll:4.1.36.Final io.netty:netty-transport-native-unix-common:4.1.36.Final io.netty:netty-transport:4.1.36.Final -io.projectreactor.netty:reactor-netty:0.8.8.RELEASE -io.projectreactor:reactor-core:3.2.9.RELEASE -io.projectreactor:reactor-test:3.2.9.RELEASE -io.rsocket:rsocket-core:0.12.2-RC4 -io.rsocket:rsocket-transport-local:0.12.2-RC4 -io.rsocket:rsocket-transport-netty:0.12.2-RC4 +io.projectreactor.addons:reactor-pool:0.1.0.RELEASE +io.projectreactor.netty:reactor-netty:0.9.0.RELEASE +io.projectreactor:reactor-core:3.3.0.RELEASE +io.projectreactor:reactor-test:3.3.0.RELEASE +io.rsocket:rsocket-core:1.0.0-RC5 +io.rsocket:rsocket-transport-local:1.0.0-RC5 +io.rsocket:rsocket-transport-netty:1.0.0-RC5 javax.inject:javax.inject:1 junit:junit:4.12 net.bytebuddy:byte-buddy-agent:1.9.7 @@ -32,5 +33,5 @@ org.hamcrest:hamcrest-core:1.3 org.hdrhistogram:HdrHistogram:2.1.10 org.mockito:mockito-core:2.25.0 org.objenesis:objenesis:2.6 -org.reactivestreams:reactive-streams:1.0.2 +org.reactivestreams:reactive-streams:1.0.3 org.slf4j:slf4j-api:1.7.25 diff --git a/netifi-broker-auth-jwt/gradle/dependency-locks/testRuntimeClasspath.lockfile b/netifi-broker-auth-jwt/gradle/dependency-locks/testRuntimeClasspath.lockfile index 8924f903..1db2da96 100644 --- a/netifi-broker-auth-jwt/gradle/dependency-locks/testRuntimeClasspath.lockfile +++ b/netifi-broker-auth-jwt/gradle/dependency-locks/testRuntimeClasspath.lockfile @@ -15,12 +15,13 @@ io.netty:netty-resolver:4.1.36.Final io.netty:netty-transport-native-epoll:4.1.36.Final io.netty:netty-transport-native-unix-common:4.1.36.Final io.netty:netty-transport:4.1.36.Final -io.projectreactor.netty:reactor-netty:0.8.8.RELEASE -io.projectreactor:reactor-core:3.2.9.RELEASE -io.projectreactor:reactor-test:3.2.9.RELEASE -io.rsocket:rsocket-core:0.12.2-RC4 -io.rsocket:rsocket-transport-local:0.12.2-RC4 -io.rsocket:rsocket-transport-netty:0.12.2-RC4 +io.projectreactor.addons:reactor-pool:0.1.0.RELEASE +io.projectreactor.netty:reactor-netty:0.9.0.RELEASE +io.projectreactor:reactor-core:3.3.0.RELEASE +io.projectreactor:reactor-test:3.3.0.RELEASE +io.rsocket:rsocket-core:1.0.0-RC5 +io.rsocket:rsocket-transport-local:1.0.0-RC5 +io.rsocket:rsocket-transport-netty:1.0.0-RC5 javax.inject:javax.inject:1 junit:junit:4.12 net.bytebuddy:byte-buddy-agent:1.9.7 @@ -32,5 +33,5 @@ org.hamcrest:hamcrest-core:1.3 org.hdrhistogram:HdrHistogram:2.1.10 org.mockito:mockito-core:2.25.0 org.objenesis:objenesis:2.6 -org.reactivestreams:reactive-streams:1.0.2 +org.reactivestreams:reactive-streams:1.0.3 org.slf4j:slf4j-api:1.7.25 diff --git a/netifi-broker-auth/gradle/dependency-locks/testCompileClasspath.lockfile b/netifi-broker-auth/gradle/dependency-locks/testCompileClasspath.lockfile index 37f53984..45200e98 100644 --- a/netifi-broker-auth/gradle/dependency-locks/testCompileClasspath.lockfile +++ b/netifi-broker-auth/gradle/dependency-locks/testCompileClasspath.lockfile @@ -14,12 +14,13 @@ io.netty:netty-resolver:4.1.36.Final io.netty:netty-transport-native-epoll:4.1.36.Final io.netty:netty-transport-native-unix-common:4.1.36.Final io.netty:netty-transport:4.1.36.Final -io.projectreactor.netty:reactor-netty:0.8.8.RELEASE -io.projectreactor:reactor-core:3.2.9.RELEASE -io.projectreactor:reactor-test:3.2.9.RELEASE -io.rsocket:rsocket-core:0.12.2-RC4 -io.rsocket:rsocket-transport-local:0.12.2-RC4 -io.rsocket:rsocket-transport-netty:0.12.2-RC4 +io.projectreactor.addons:reactor-pool:0.1.0.RELEASE +io.projectreactor.netty:reactor-netty:0.9.0.RELEASE +io.projectreactor:reactor-core:3.3.0.RELEASE +io.projectreactor:reactor-test:3.3.0.RELEASE +io.rsocket:rsocket-core:1.0.0-RC5 +io.rsocket:rsocket-transport-local:1.0.0-RC5 +io.rsocket:rsocket-transport-netty:1.0.0-RC5 javax.inject:javax.inject:1 junit:junit:4.12 net.bytebuddy:byte-buddy-agent:1.9.7 @@ -31,5 +32,5 @@ org.hamcrest:hamcrest-core:1.3 org.hdrhistogram:HdrHistogram:2.1.10 org.mockito:mockito-core:2.25.0 org.objenesis:objenesis:2.6 -org.reactivestreams:reactive-streams:1.0.2 +org.reactivestreams:reactive-streams:1.0.3 org.slf4j:slf4j-api:1.7.25 diff --git a/netifi-broker-auth/gradle/dependency-locks/testRuntimeClasspath.lockfile b/netifi-broker-auth/gradle/dependency-locks/testRuntimeClasspath.lockfile index 37f53984..45200e98 100644 --- a/netifi-broker-auth/gradle/dependency-locks/testRuntimeClasspath.lockfile +++ b/netifi-broker-auth/gradle/dependency-locks/testRuntimeClasspath.lockfile @@ -14,12 +14,13 @@ io.netty:netty-resolver:4.1.36.Final io.netty:netty-transport-native-epoll:4.1.36.Final io.netty:netty-transport-native-unix-common:4.1.36.Final io.netty:netty-transport:4.1.36.Final -io.projectreactor.netty:reactor-netty:0.8.8.RELEASE -io.projectreactor:reactor-core:3.2.9.RELEASE -io.projectreactor:reactor-test:3.2.9.RELEASE -io.rsocket:rsocket-core:0.12.2-RC4 -io.rsocket:rsocket-transport-local:0.12.2-RC4 -io.rsocket:rsocket-transport-netty:0.12.2-RC4 +io.projectreactor.addons:reactor-pool:0.1.0.RELEASE +io.projectreactor.netty:reactor-netty:0.9.0.RELEASE +io.projectreactor:reactor-core:3.3.0.RELEASE +io.projectreactor:reactor-test:3.3.0.RELEASE +io.rsocket:rsocket-core:1.0.0-RC5 +io.rsocket:rsocket-transport-local:1.0.0-RC5 +io.rsocket:rsocket-transport-netty:1.0.0-RC5 javax.inject:javax.inject:1 junit:junit:4.12 net.bytebuddy:byte-buddy-agent:1.9.7 @@ -31,5 +32,5 @@ org.hamcrest:hamcrest-core:1.3 org.hdrhistogram:HdrHistogram:2.1.10 org.mockito:mockito-core:2.25.0 org.objenesis:objenesis:2.6 -org.reactivestreams:reactive-streams:1.0.2 +org.reactivestreams:reactive-streams:1.0.3 org.slf4j:slf4j-api:1.7.25 diff --git a/netifi-broker-client/gradle/dependency-locks/compile.lockfile b/netifi-broker-client/gradle/dependency-locks/compile.lockfile index 706d7b26..41a08efc 100644 --- a/netifi-broker-client/gradle/dependency-locks/compile.lockfile +++ b/netifi-broker-client/gradle/dependency-locks/compile.lockfile @@ -18,14 +18,15 @@ io.netty:netty-transport-native-epoll:4.1.36.Final io.netty:netty-transport-native-unix-common:4.1.36.Final io.netty:netty-transport:4.1.36.Final io.opentracing:opentracing-api:0.31.0 -io.projectreactor.netty:reactor-netty:0.8.8.RELEASE -io.projectreactor:reactor-core:3.2.9.RELEASE +io.projectreactor.addons:reactor-pool:0.1.0.RELEASE +io.projectreactor.netty:reactor-netty:0.9.0.RELEASE +io.projectreactor:reactor-core:3.3.0.RELEASE io.rsocket.rpc:rsocket-rpc-core:0.2.18 -io.rsocket:rsocket-core:0.12.2-RC4 -io.rsocket:rsocket-transport-netty:0.12.2-RC4 +io.rsocket:rsocket-core:1.0.0-RC5 +io.rsocket:rsocket-transport-netty:1.0.0-RC5 javax.annotation:javax.annotation-api:1.3.2 javax.inject:javax.inject:1 org.hdrhistogram:HdrHistogram:2.1.10 org.latencyutils:LatencyUtils:2.0.3 -org.reactivestreams:reactive-streams:1.0.2 +org.reactivestreams:reactive-streams:1.0.3 org.slf4j:slf4j-api:1.7.25 diff --git a/netifi-broker-client/gradle/dependency-locks/compileClasspath.lockfile b/netifi-broker-client/gradle/dependency-locks/compileClasspath.lockfile index 706d7b26..41a08efc 100644 --- a/netifi-broker-client/gradle/dependency-locks/compileClasspath.lockfile +++ b/netifi-broker-client/gradle/dependency-locks/compileClasspath.lockfile @@ -18,14 +18,15 @@ io.netty:netty-transport-native-epoll:4.1.36.Final io.netty:netty-transport-native-unix-common:4.1.36.Final io.netty:netty-transport:4.1.36.Final io.opentracing:opentracing-api:0.31.0 -io.projectreactor.netty:reactor-netty:0.8.8.RELEASE -io.projectreactor:reactor-core:3.2.9.RELEASE +io.projectreactor.addons:reactor-pool:0.1.0.RELEASE +io.projectreactor.netty:reactor-netty:0.9.0.RELEASE +io.projectreactor:reactor-core:3.3.0.RELEASE io.rsocket.rpc:rsocket-rpc-core:0.2.18 -io.rsocket:rsocket-core:0.12.2-RC4 -io.rsocket:rsocket-transport-netty:0.12.2-RC4 +io.rsocket:rsocket-core:1.0.0-RC5 +io.rsocket:rsocket-transport-netty:1.0.0-RC5 javax.annotation:javax.annotation-api:1.3.2 javax.inject:javax.inject:1 org.hdrhistogram:HdrHistogram:2.1.10 org.latencyutils:LatencyUtils:2.0.3 -org.reactivestreams:reactive-streams:1.0.2 +org.reactivestreams:reactive-streams:1.0.3 org.slf4j:slf4j-api:1.7.25 diff --git a/netifi-broker-client/gradle/dependency-locks/testCompile.lockfile b/netifi-broker-client/gradle/dependency-locks/testCompile.lockfile index 3a2106ad..6a12558e 100644 --- a/netifi-broker-client/gradle/dependency-locks/testCompile.lockfile +++ b/netifi-broker-client/gradle/dependency-locks/testCompile.lockfile @@ -37,15 +37,16 @@ io.netty:netty-transport-native-unix-common:4.1.36.Final io.netty:netty-transport:4.1.36.Final io.opentracing.brave:brave-opentracing:0.33.10 io.opentracing:opentracing-api:0.31.0 -io.projectreactor.addons:reactor-adapter:3.2.3.RELEASE -io.projectreactor.netty:reactor-netty:0.8.8.RELEASE -io.projectreactor:reactor-core:3.2.9.RELEASE -io.projectreactor:reactor-test:3.2.9.RELEASE +io.projectreactor.addons:reactor-adapter:3.3.0.RELEASE +io.projectreactor.addons:reactor-pool:0.1.0.RELEASE +io.projectreactor.netty:reactor-netty:0.9.0.RELEASE +io.projectreactor:reactor-core:3.3.0.RELEASE +io.projectreactor:reactor-test:3.3.0.RELEASE io.rsocket.rpc:rsocket-rpc-core:0.2.18 io.rsocket.rpc:rsocket-rpc-protobuf:0.2.18 -io.rsocket:rsocket-core:0.12.2-RC4 -io.rsocket:rsocket-transport-local:0.12.2-RC4 -io.rsocket:rsocket-transport-netty:0.12.2-RC4 +io.rsocket:rsocket-core:1.0.0-RC5 +io.rsocket:rsocket-transport-local:1.0.0-RC5 +io.rsocket:rsocket-transport-netty:1.0.0-RC5 io.zipkin.brave:brave:5.6.1 io.zipkin.reporter2:zipkin-reporter:2.7.14 io.zipkin.zipkin2:zipkin:2.12.0 @@ -64,5 +65,5 @@ org.hdrhistogram:HdrHistogram:2.1.10 org.latencyutils:LatencyUtils:2.0.3 org.mockito:mockito-core:2.25.0 org.objenesis:objenesis:2.6 -org.reactivestreams:reactive-streams:1.0.2 +org.reactivestreams:reactive-streams:1.0.3 org.slf4j:slf4j-api:1.7.25 diff --git a/netifi-broker-client/gradle/dependency-locks/testCompileClasspath.lockfile b/netifi-broker-client/gradle/dependency-locks/testCompileClasspath.lockfile index 3a2106ad..6a12558e 100644 --- a/netifi-broker-client/gradle/dependency-locks/testCompileClasspath.lockfile +++ b/netifi-broker-client/gradle/dependency-locks/testCompileClasspath.lockfile @@ -37,15 +37,16 @@ io.netty:netty-transport-native-unix-common:4.1.36.Final io.netty:netty-transport:4.1.36.Final io.opentracing.brave:brave-opentracing:0.33.10 io.opentracing:opentracing-api:0.31.0 -io.projectreactor.addons:reactor-adapter:3.2.3.RELEASE -io.projectreactor.netty:reactor-netty:0.8.8.RELEASE -io.projectreactor:reactor-core:3.2.9.RELEASE -io.projectreactor:reactor-test:3.2.9.RELEASE +io.projectreactor.addons:reactor-adapter:3.3.0.RELEASE +io.projectreactor.addons:reactor-pool:0.1.0.RELEASE +io.projectreactor.netty:reactor-netty:0.9.0.RELEASE +io.projectreactor:reactor-core:3.3.0.RELEASE +io.projectreactor:reactor-test:3.3.0.RELEASE io.rsocket.rpc:rsocket-rpc-core:0.2.18 io.rsocket.rpc:rsocket-rpc-protobuf:0.2.18 -io.rsocket:rsocket-core:0.12.2-RC4 -io.rsocket:rsocket-transport-local:0.12.2-RC4 -io.rsocket:rsocket-transport-netty:0.12.2-RC4 +io.rsocket:rsocket-core:1.0.0-RC5 +io.rsocket:rsocket-transport-local:1.0.0-RC5 +io.rsocket:rsocket-transport-netty:1.0.0-RC5 io.zipkin.brave:brave:5.6.1 io.zipkin.reporter2:zipkin-reporter:2.7.14 io.zipkin.zipkin2:zipkin:2.12.0 @@ -64,5 +65,5 @@ org.hdrhistogram:HdrHistogram:2.1.10 org.latencyutils:LatencyUtils:2.0.3 org.mockito:mockito-core:2.25.0 org.objenesis:objenesis:2.6 -org.reactivestreams:reactive-streams:1.0.2 +org.reactivestreams:reactive-streams:1.0.3 org.slf4j:slf4j-api:1.7.25 diff --git a/netifi-broker-client/gradle/dependency-locks/testRuntimeClasspath.lockfile b/netifi-broker-client/gradle/dependency-locks/testRuntimeClasspath.lockfile index 3a2106ad..6a12558e 100644 --- a/netifi-broker-client/gradle/dependency-locks/testRuntimeClasspath.lockfile +++ b/netifi-broker-client/gradle/dependency-locks/testRuntimeClasspath.lockfile @@ -37,15 +37,16 @@ io.netty:netty-transport-native-unix-common:4.1.36.Final io.netty:netty-transport:4.1.36.Final io.opentracing.brave:brave-opentracing:0.33.10 io.opentracing:opentracing-api:0.31.0 -io.projectreactor.addons:reactor-adapter:3.2.3.RELEASE -io.projectreactor.netty:reactor-netty:0.8.8.RELEASE -io.projectreactor:reactor-core:3.2.9.RELEASE -io.projectreactor:reactor-test:3.2.9.RELEASE +io.projectreactor.addons:reactor-adapter:3.3.0.RELEASE +io.projectreactor.addons:reactor-pool:0.1.0.RELEASE +io.projectreactor.netty:reactor-netty:0.9.0.RELEASE +io.projectreactor:reactor-core:3.3.0.RELEASE +io.projectreactor:reactor-test:3.3.0.RELEASE io.rsocket.rpc:rsocket-rpc-core:0.2.18 io.rsocket.rpc:rsocket-rpc-protobuf:0.2.18 -io.rsocket:rsocket-core:0.12.2-RC4 -io.rsocket:rsocket-transport-local:0.12.2-RC4 -io.rsocket:rsocket-transport-netty:0.12.2-RC4 +io.rsocket:rsocket-core:1.0.0-RC5 +io.rsocket:rsocket-transport-local:1.0.0-RC5 +io.rsocket:rsocket-transport-netty:1.0.0-RC5 io.zipkin.brave:brave:5.6.1 io.zipkin.reporter2:zipkin-reporter:2.7.14 io.zipkin.zipkin2:zipkin:2.12.0 @@ -64,5 +65,5 @@ org.hdrhistogram:HdrHistogram:2.1.10 org.latencyutils:LatencyUtils:2.0.3 org.mockito:mockito-core:2.25.0 org.objenesis:objenesis:2.6 -org.reactivestreams:reactive-streams:1.0.2 +org.reactivestreams:reactive-streams:1.0.3 org.slf4j:slf4j-api:1.7.25 diff --git a/netifi-broker-frames/gradle/dependency-locks/compileClasspath.lockfile b/netifi-broker-frames/gradle/dependency-locks/compileClasspath.lockfile index cc1a24fb..8a110f20 100644 --- a/netifi-broker-frames/gradle/dependency-locks/compileClasspath.lockfile +++ b/netifi-broker-frames/gradle/dependency-locks/compileClasspath.lockfile @@ -3,7 +3,7 @@ # This file is expected to be part of source control. io.netty:netty-buffer:4.1.36.Final io.netty:netty-common:4.1.36.Final -io.projectreactor:reactor-core:3.2.9.RELEASE -io.rsocket:rsocket-core:0.12.2-RC4 +io.projectreactor:reactor-core:3.3.0.RELEASE +io.rsocket:rsocket-core:1.0.0-RC5 javax.inject:javax.inject:1 -org.reactivestreams:reactive-streams:1.0.2 +org.reactivestreams:reactive-streams:1.0.3 diff --git a/netifi-broker-frames/gradle/dependency-locks/testCompileClasspath.lockfile b/netifi-broker-frames/gradle/dependency-locks/testCompileClasspath.lockfile index 37f53984..45200e98 100644 --- a/netifi-broker-frames/gradle/dependency-locks/testCompileClasspath.lockfile +++ b/netifi-broker-frames/gradle/dependency-locks/testCompileClasspath.lockfile @@ -14,12 +14,13 @@ io.netty:netty-resolver:4.1.36.Final io.netty:netty-transport-native-epoll:4.1.36.Final io.netty:netty-transport-native-unix-common:4.1.36.Final io.netty:netty-transport:4.1.36.Final -io.projectreactor.netty:reactor-netty:0.8.8.RELEASE -io.projectreactor:reactor-core:3.2.9.RELEASE -io.projectreactor:reactor-test:3.2.9.RELEASE -io.rsocket:rsocket-core:0.12.2-RC4 -io.rsocket:rsocket-transport-local:0.12.2-RC4 -io.rsocket:rsocket-transport-netty:0.12.2-RC4 +io.projectreactor.addons:reactor-pool:0.1.0.RELEASE +io.projectreactor.netty:reactor-netty:0.9.0.RELEASE +io.projectreactor:reactor-core:3.3.0.RELEASE +io.projectreactor:reactor-test:3.3.0.RELEASE +io.rsocket:rsocket-core:1.0.0-RC5 +io.rsocket:rsocket-transport-local:1.0.0-RC5 +io.rsocket:rsocket-transport-netty:1.0.0-RC5 javax.inject:javax.inject:1 junit:junit:4.12 net.bytebuddy:byte-buddy-agent:1.9.7 @@ -31,5 +32,5 @@ org.hamcrest:hamcrest-core:1.3 org.hdrhistogram:HdrHistogram:2.1.10 org.mockito:mockito-core:2.25.0 org.objenesis:objenesis:2.6 -org.reactivestreams:reactive-streams:1.0.2 +org.reactivestreams:reactive-streams:1.0.3 org.slf4j:slf4j-api:1.7.25 diff --git a/netifi-broker-frames/gradle/dependency-locks/testRuntimeClasspath.lockfile b/netifi-broker-frames/gradle/dependency-locks/testRuntimeClasspath.lockfile index 37f53984..45200e98 100644 --- a/netifi-broker-frames/gradle/dependency-locks/testRuntimeClasspath.lockfile +++ b/netifi-broker-frames/gradle/dependency-locks/testRuntimeClasspath.lockfile @@ -14,12 +14,13 @@ io.netty:netty-resolver:4.1.36.Final io.netty:netty-transport-native-epoll:4.1.36.Final io.netty:netty-transport-native-unix-common:4.1.36.Final io.netty:netty-transport:4.1.36.Final -io.projectreactor.netty:reactor-netty:0.8.8.RELEASE -io.projectreactor:reactor-core:3.2.9.RELEASE -io.projectreactor:reactor-test:3.2.9.RELEASE -io.rsocket:rsocket-core:0.12.2-RC4 -io.rsocket:rsocket-transport-local:0.12.2-RC4 -io.rsocket:rsocket-transport-netty:0.12.2-RC4 +io.projectreactor.addons:reactor-pool:0.1.0.RELEASE +io.projectreactor.netty:reactor-netty:0.9.0.RELEASE +io.projectreactor:reactor-core:3.3.0.RELEASE +io.projectreactor:reactor-test:3.3.0.RELEASE +io.rsocket:rsocket-core:1.0.0-RC5 +io.rsocket:rsocket-transport-local:1.0.0-RC5 +io.rsocket:rsocket-transport-netty:1.0.0-RC5 javax.inject:javax.inject:1 junit:junit:4.12 net.bytebuddy:byte-buddy-agent:1.9.7 @@ -31,5 +32,5 @@ org.hamcrest:hamcrest-core:1.3 org.hdrhistogram:HdrHistogram:2.1.10 org.mockito:mockito-core:2.25.0 org.objenesis:objenesis:2.6 -org.reactivestreams:reactive-streams:1.0.2 +org.reactivestreams:reactive-streams:1.0.3 org.slf4j:slf4j-api:1.7.25 diff --git a/netifi-common/gradle/dependency-locks/testCompileClasspath.lockfile b/netifi-common/gradle/dependency-locks/testCompileClasspath.lockfile index 37f53984..45200e98 100644 --- a/netifi-common/gradle/dependency-locks/testCompileClasspath.lockfile +++ b/netifi-common/gradle/dependency-locks/testCompileClasspath.lockfile @@ -14,12 +14,13 @@ io.netty:netty-resolver:4.1.36.Final io.netty:netty-transport-native-epoll:4.1.36.Final io.netty:netty-transport-native-unix-common:4.1.36.Final io.netty:netty-transport:4.1.36.Final -io.projectreactor.netty:reactor-netty:0.8.8.RELEASE -io.projectreactor:reactor-core:3.2.9.RELEASE -io.projectreactor:reactor-test:3.2.9.RELEASE -io.rsocket:rsocket-core:0.12.2-RC4 -io.rsocket:rsocket-transport-local:0.12.2-RC4 -io.rsocket:rsocket-transport-netty:0.12.2-RC4 +io.projectreactor.addons:reactor-pool:0.1.0.RELEASE +io.projectreactor.netty:reactor-netty:0.9.0.RELEASE +io.projectreactor:reactor-core:3.3.0.RELEASE +io.projectreactor:reactor-test:3.3.0.RELEASE +io.rsocket:rsocket-core:1.0.0-RC5 +io.rsocket:rsocket-transport-local:1.0.0-RC5 +io.rsocket:rsocket-transport-netty:1.0.0-RC5 javax.inject:javax.inject:1 junit:junit:4.12 net.bytebuddy:byte-buddy-agent:1.9.7 @@ -31,5 +32,5 @@ org.hamcrest:hamcrest-core:1.3 org.hdrhistogram:HdrHistogram:2.1.10 org.mockito:mockito-core:2.25.0 org.objenesis:objenesis:2.6 -org.reactivestreams:reactive-streams:1.0.2 +org.reactivestreams:reactive-streams:1.0.3 org.slf4j:slf4j-api:1.7.25 diff --git a/netifi-common/gradle/dependency-locks/testRuntimeClasspath.lockfile b/netifi-common/gradle/dependency-locks/testRuntimeClasspath.lockfile index 37f53984..45200e98 100644 --- a/netifi-common/gradle/dependency-locks/testRuntimeClasspath.lockfile +++ b/netifi-common/gradle/dependency-locks/testRuntimeClasspath.lockfile @@ -14,12 +14,13 @@ io.netty:netty-resolver:4.1.36.Final io.netty:netty-transport-native-epoll:4.1.36.Final io.netty:netty-transport-native-unix-common:4.1.36.Final io.netty:netty-transport:4.1.36.Final -io.projectreactor.netty:reactor-netty:0.8.8.RELEASE -io.projectreactor:reactor-core:3.2.9.RELEASE -io.projectreactor:reactor-test:3.2.9.RELEASE -io.rsocket:rsocket-core:0.12.2-RC4 -io.rsocket:rsocket-transport-local:0.12.2-RC4 -io.rsocket:rsocket-transport-netty:0.12.2-RC4 +io.projectreactor.addons:reactor-pool:0.1.0.RELEASE +io.projectreactor.netty:reactor-netty:0.9.0.RELEASE +io.projectreactor:reactor-core:3.3.0.RELEASE +io.projectreactor:reactor-test:3.3.0.RELEASE +io.rsocket:rsocket-core:1.0.0-RC5 +io.rsocket:rsocket-transport-local:1.0.0-RC5 +io.rsocket:rsocket-transport-netty:1.0.0-RC5 javax.inject:javax.inject:1 junit:junit:4.12 net.bytebuddy:byte-buddy-agent:1.9.7 @@ -31,5 +32,5 @@ org.hamcrest:hamcrest-core:1.3 org.hdrhistogram:HdrHistogram:2.1.10 org.mockito:mockito-core:2.25.0 org.objenesis:objenesis:2.6 -org.reactivestreams:reactive-streams:1.0.2 +org.reactivestreams:reactive-streams:1.0.3 org.slf4j:slf4j-api:1.7.25 diff --git a/netifi-discovery-aws/gradle/dependency-locks/compileClasspath.lockfile b/netifi-discovery-aws/gradle/dependency-locks/compileClasspath.lockfile index 4151004e..04c3cd61 100644 --- a/netifi-discovery-aws/gradle/dependency-locks/compileClasspath.lockfile +++ b/netifi-discovery-aws/gradle/dependency-locks/compileClasspath.lockfile @@ -4,9 +4,9 @@ com.fasterxml.jackson.core:jackson-annotations:2.9.0 com.fasterxml.jackson.core:jackson-core:2.9.8 com.fasterxml.jackson.core:jackson-databind:2.9.8 -io.projectreactor:reactor-core:3.2.9.RELEASE +io.projectreactor:reactor-core:3.3.0.RELEASE javax.inject:javax.inject:1 -org.reactivestreams:reactive-streams:1.0.2 +org.reactivestreams:reactive-streams:1.0.3 org.slf4j:slf4j-api:1.7.25 software.amazon.awssdk:annotations:2.4.13 software.amazon.awssdk:auth:2.4.13 diff --git a/netifi-discovery-aws/gradle/dependency-locks/testCompileClasspath.lockfile b/netifi-discovery-aws/gradle/dependency-locks/testCompileClasspath.lockfile index eaa72396..ac589400 100644 --- a/netifi-discovery-aws/gradle/dependency-locks/testCompileClasspath.lockfile +++ b/netifi-discovery-aws/gradle/dependency-locks/testCompileClasspath.lockfile @@ -17,12 +17,13 @@ io.netty:netty-resolver:4.1.36.Final io.netty:netty-transport-native-epoll:4.1.36.Final io.netty:netty-transport-native-unix-common:4.1.36.Final io.netty:netty-transport:4.1.36.Final -io.projectreactor.netty:reactor-netty:0.8.8.RELEASE -io.projectreactor:reactor-core:3.2.9.RELEASE -io.projectreactor:reactor-test:3.2.9.RELEASE -io.rsocket:rsocket-core:0.12.2-RC4 -io.rsocket:rsocket-transport-local:0.12.2-RC4 -io.rsocket:rsocket-transport-netty:0.12.2-RC4 +io.projectreactor.addons:reactor-pool:0.1.0.RELEASE +io.projectreactor.netty:reactor-netty:0.9.0.RELEASE +io.projectreactor:reactor-core:3.3.0.RELEASE +io.projectreactor:reactor-test:3.3.0.RELEASE +io.rsocket:rsocket-core:1.0.0-RC5 +io.rsocket:rsocket-transport-local:1.0.0-RC5 +io.rsocket:rsocket-transport-netty:1.0.0-RC5 javax.inject:javax.inject:1 junit:junit:4.12 net.bytebuddy:byte-buddy-agent:1.9.7 @@ -34,7 +35,7 @@ org.hamcrest:hamcrest-core:1.3 org.hdrhistogram:HdrHistogram:2.1.10 org.mockito:mockito-core:2.25.0 org.objenesis:objenesis:2.6 -org.reactivestreams:reactive-streams:1.0.2 +org.reactivestreams:reactive-streams:1.0.3 org.slf4j:slf4j-api:1.7.25 software.amazon.awssdk:annotations:2.4.13 software.amazon.awssdk:auth:2.4.13 diff --git a/netifi-discovery-aws/gradle/dependency-locks/testRuntimeClasspath.lockfile b/netifi-discovery-aws/gradle/dependency-locks/testRuntimeClasspath.lockfile index 46b4d3e6..a27cb970 100644 --- a/netifi-discovery-aws/gradle/dependency-locks/testRuntimeClasspath.lockfile +++ b/netifi-discovery-aws/gradle/dependency-locks/testRuntimeClasspath.lockfile @@ -21,12 +21,13 @@ io.netty:netty-resolver:4.1.36.Final io.netty:netty-transport-native-epoll:4.1.36.Final io.netty:netty-transport-native-unix-common:4.1.36.Final io.netty:netty-transport:4.1.36.Final -io.projectreactor.netty:reactor-netty:0.8.8.RELEASE -io.projectreactor:reactor-core:3.2.9.RELEASE -io.projectreactor:reactor-test:3.2.9.RELEASE -io.rsocket:rsocket-core:0.12.2-RC4 -io.rsocket:rsocket-transport-local:0.12.2-RC4 -io.rsocket:rsocket-transport-netty:0.12.2-RC4 +io.projectreactor.addons:reactor-pool:0.1.0.RELEASE +io.projectreactor.netty:reactor-netty:0.9.0.RELEASE +io.projectreactor:reactor-core:3.3.0.RELEASE +io.projectreactor:reactor-test:3.3.0.RELEASE +io.rsocket:rsocket-core:1.0.0-RC5 +io.rsocket:rsocket-transport-local:1.0.0-RC5 +io.rsocket:rsocket-transport-netty:1.0.0-RC5 javax.inject:javax.inject:1 junit:junit:4.12 net.bytebuddy:byte-buddy-agent:1.9.7 @@ -40,7 +41,7 @@ org.hamcrest:hamcrest-core:1.3 org.hdrhistogram:HdrHistogram:2.1.10 org.mockito:mockito-core:2.25.0 org.objenesis:objenesis:2.6 -org.reactivestreams:reactive-streams:1.0.2 +org.reactivestreams:reactive-streams:1.0.3 org.slf4j:slf4j-api:1.7.25 software.amazon.awssdk:annotations:2.4.13 software.amazon.awssdk:apache-client:2.4.13 diff --git a/netifi-discovery-consul/gradle/dependency-locks/compileClasspath.lockfile b/netifi-discovery-consul/gradle/dependency-locks/compileClasspath.lockfile index d054024f..d0a35d68 100644 --- a/netifi-discovery-consul/gradle/dependency-locks/compileClasspath.lockfile +++ b/netifi-discovery-consul/gradle/dependency-locks/compileClasspath.lockfile @@ -17,10 +17,10 @@ com.squareup.okhttp3:okhttp:3.9.0 com.squareup.okio:okio:1.13.0 com.squareup.retrofit2:converter-jackson:2.3.0 com.squareup.retrofit2:retrofit:2.3.0 -io.projectreactor:reactor-core:3.2.9.RELEASE +io.projectreactor:reactor-core:3.3.0.RELEASE javax.inject:javax.inject:1 org.apache.commons:commons-lang3:3.4 org.checkerframework:checker-qual:2.5.2 org.codehaus.mojo:animal-sniffer-annotations:1.17 -org.reactivestreams:reactive-streams:1.0.2 +org.reactivestreams:reactive-streams:1.0.3 org.slf4j:slf4j-api:1.7.25 diff --git a/netifi-discovery-consul/gradle/dependency-locks/testCompileClasspath.lockfile b/netifi-discovery-consul/gradle/dependency-locks/testCompileClasspath.lockfile index 8b20f8ad..af9db406 100644 --- a/netifi-discovery-consul/gradle/dependency-locks/testCompileClasspath.lockfile +++ b/netifi-discovery-consul/gradle/dependency-locks/testCompileClasspath.lockfile @@ -30,12 +30,13 @@ io.netty:netty-resolver:4.1.36.Final io.netty:netty-transport-native-epoll:4.1.36.Final io.netty:netty-transport-native-unix-common:4.1.36.Final io.netty:netty-transport:4.1.36.Final -io.projectreactor.netty:reactor-netty:0.8.8.RELEASE -io.projectreactor:reactor-core:3.2.9.RELEASE -io.projectreactor:reactor-test:3.2.9.RELEASE -io.rsocket:rsocket-core:0.12.2-RC4 -io.rsocket:rsocket-transport-local:0.12.2-RC4 -io.rsocket:rsocket-transport-netty:0.12.2-RC4 +io.projectreactor.addons:reactor-pool:0.1.0.RELEASE +io.projectreactor.netty:reactor-netty:0.9.0.RELEASE +io.projectreactor:reactor-core:3.3.0.RELEASE +io.projectreactor:reactor-test:3.3.0.RELEASE +io.rsocket:rsocket-core:1.0.0-RC5 +io.rsocket:rsocket-transport-local:1.0.0-RC5 +io.rsocket:rsocket-transport-netty:1.0.0-RC5 javax.inject:javax.inject:1 junit:junit:4.12 net.bytebuddy:byte-buddy-agent:1.9.7 @@ -50,5 +51,5 @@ org.hamcrest:hamcrest-core:1.3 org.hdrhistogram:HdrHistogram:2.1.10 org.mockito:mockito-core:2.25.0 org.objenesis:objenesis:2.6 -org.reactivestreams:reactive-streams:1.0.2 +org.reactivestreams:reactive-streams:1.0.3 org.slf4j:slf4j-api:1.7.25 diff --git a/netifi-discovery-consul/gradle/dependency-locks/testRuntimeClasspath.lockfile b/netifi-discovery-consul/gradle/dependency-locks/testRuntimeClasspath.lockfile index 8b20f8ad..af9db406 100644 --- a/netifi-discovery-consul/gradle/dependency-locks/testRuntimeClasspath.lockfile +++ b/netifi-discovery-consul/gradle/dependency-locks/testRuntimeClasspath.lockfile @@ -30,12 +30,13 @@ io.netty:netty-resolver:4.1.36.Final io.netty:netty-transport-native-epoll:4.1.36.Final io.netty:netty-transport-native-unix-common:4.1.36.Final io.netty:netty-transport:4.1.36.Final -io.projectreactor.netty:reactor-netty:0.8.8.RELEASE -io.projectreactor:reactor-core:3.2.9.RELEASE -io.projectreactor:reactor-test:3.2.9.RELEASE -io.rsocket:rsocket-core:0.12.2-RC4 -io.rsocket:rsocket-transport-local:0.12.2-RC4 -io.rsocket:rsocket-transport-netty:0.12.2-RC4 +io.projectreactor.addons:reactor-pool:0.1.0.RELEASE +io.projectreactor.netty:reactor-netty:0.9.0.RELEASE +io.projectreactor:reactor-core:3.3.0.RELEASE +io.projectreactor:reactor-test:3.3.0.RELEASE +io.rsocket:rsocket-core:1.0.0-RC5 +io.rsocket:rsocket-transport-local:1.0.0-RC5 +io.rsocket:rsocket-transport-netty:1.0.0-RC5 javax.inject:javax.inject:1 junit:junit:4.12 net.bytebuddy:byte-buddy-agent:1.9.7 @@ -50,5 +51,5 @@ org.hamcrest:hamcrest-core:1.3 org.hdrhistogram:HdrHistogram:2.1.10 org.mockito:mockito-core:2.25.0 org.objenesis:objenesis:2.6 -org.reactivestreams:reactive-streams:1.0.2 +org.reactivestreams:reactive-streams:1.0.3 org.slf4j:slf4j-api:1.7.25 diff --git a/netifi-discovery/gradle/dependency-locks/compileClasspath.lockfile b/netifi-discovery/gradle/dependency-locks/compileClasspath.lockfile index 8e7b6368..7b8cabf6 100644 --- a/netifi-discovery/gradle/dependency-locks/compileClasspath.lockfile +++ b/netifi-discovery/gradle/dependency-locks/compileClasspath.lockfile @@ -1,7 +1,7 @@ # This is a Gradle generated file for dependency locking. # Manual edits can break the build and are not advised. # This file is expected to be part of source control. -io.projectreactor:reactor-core:3.2.9.RELEASE +io.projectreactor:reactor-core:3.3.0.RELEASE javax.inject:javax.inject:1 -org.reactivestreams:reactive-streams:1.0.2 +org.reactivestreams:reactive-streams:1.0.3 org.slf4j:slf4j-api:1.7.25 diff --git a/netifi-discovery/gradle/dependency-locks/testCompileClasspath.lockfile b/netifi-discovery/gradle/dependency-locks/testCompileClasspath.lockfile index 37f53984..45200e98 100644 --- a/netifi-discovery/gradle/dependency-locks/testCompileClasspath.lockfile +++ b/netifi-discovery/gradle/dependency-locks/testCompileClasspath.lockfile @@ -14,12 +14,13 @@ io.netty:netty-resolver:4.1.36.Final io.netty:netty-transport-native-epoll:4.1.36.Final io.netty:netty-transport-native-unix-common:4.1.36.Final io.netty:netty-transport:4.1.36.Final -io.projectreactor.netty:reactor-netty:0.8.8.RELEASE -io.projectreactor:reactor-core:3.2.9.RELEASE -io.projectreactor:reactor-test:3.2.9.RELEASE -io.rsocket:rsocket-core:0.12.2-RC4 -io.rsocket:rsocket-transport-local:0.12.2-RC4 -io.rsocket:rsocket-transport-netty:0.12.2-RC4 +io.projectreactor.addons:reactor-pool:0.1.0.RELEASE +io.projectreactor.netty:reactor-netty:0.9.0.RELEASE +io.projectreactor:reactor-core:3.3.0.RELEASE +io.projectreactor:reactor-test:3.3.0.RELEASE +io.rsocket:rsocket-core:1.0.0-RC5 +io.rsocket:rsocket-transport-local:1.0.0-RC5 +io.rsocket:rsocket-transport-netty:1.0.0-RC5 javax.inject:javax.inject:1 junit:junit:4.12 net.bytebuddy:byte-buddy-agent:1.9.7 @@ -31,5 +32,5 @@ org.hamcrest:hamcrest-core:1.3 org.hdrhistogram:HdrHistogram:2.1.10 org.mockito:mockito-core:2.25.0 org.objenesis:objenesis:2.6 -org.reactivestreams:reactive-streams:1.0.2 +org.reactivestreams:reactive-streams:1.0.3 org.slf4j:slf4j-api:1.7.25 diff --git a/netifi-discovery/gradle/dependency-locks/testRuntimeClasspath.lockfile b/netifi-discovery/gradle/dependency-locks/testRuntimeClasspath.lockfile index 37f53984..45200e98 100644 --- a/netifi-discovery/gradle/dependency-locks/testRuntimeClasspath.lockfile +++ b/netifi-discovery/gradle/dependency-locks/testRuntimeClasspath.lockfile @@ -14,12 +14,13 @@ io.netty:netty-resolver:4.1.36.Final io.netty:netty-transport-native-epoll:4.1.36.Final io.netty:netty-transport-native-unix-common:4.1.36.Final io.netty:netty-transport:4.1.36.Final -io.projectreactor.netty:reactor-netty:0.8.8.RELEASE -io.projectreactor:reactor-core:3.2.9.RELEASE -io.projectreactor:reactor-test:3.2.9.RELEASE -io.rsocket:rsocket-core:0.12.2-RC4 -io.rsocket:rsocket-transport-local:0.12.2-RC4 -io.rsocket:rsocket-transport-netty:0.12.2-RC4 +io.projectreactor.addons:reactor-pool:0.1.0.RELEASE +io.projectreactor.netty:reactor-netty:0.9.0.RELEASE +io.projectreactor:reactor-core:3.3.0.RELEASE +io.projectreactor:reactor-test:3.3.0.RELEASE +io.rsocket:rsocket-core:1.0.0-RC5 +io.rsocket:rsocket-transport-local:1.0.0-RC5 +io.rsocket:rsocket-transport-netty:1.0.0-RC5 javax.inject:javax.inject:1 junit:junit:4.12 net.bytebuddy:byte-buddy-agent:1.9.7 @@ -31,5 +32,5 @@ org.hamcrest:hamcrest-core:1.3 org.hdrhistogram:HdrHistogram:2.1.10 org.mockito:mockito-core:2.25.0 org.objenesis:objenesis:2.6 -org.reactivestreams:reactive-streams:1.0.2 +org.reactivestreams:reactive-streams:1.0.3 org.slf4j:slf4j-api:1.7.25 diff --git a/netifi-metrics-influx/gradle/dependency-locks/compile.lockfile b/netifi-metrics-influx/gradle/dependency-locks/compile.lockfile index 69734bab..f7e4b796 100644 --- a/netifi-metrics-influx/gradle/dependency-locks/compile.lockfile +++ b/netifi-metrics-influx/gradle/dependency-locks/compile.lockfile @@ -25,17 +25,18 @@ io.netty:netty-transport-native-epoll:4.1.36.Final io.netty:netty-transport-native-unix-common:4.1.36.Final io.netty:netty-transport:4.1.36.Final io.opentracing:opentracing-api:0.31.0 -io.projectreactor.netty:reactor-netty:0.8.8.RELEASE -io.projectreactor:reactor-core:3.2.9.RELEASE +io.projectreactor.addons:reactor-pool:0.1.0.RELEASE +io.projectreactor.netty:reactor-netty:0.9.0.RELEASE +io.projectreactor:reactor-core:3.3.0.RELEASE io.rsocket.rpc:rsocket-rpc-core:0.2.18 io.rsocket.rpc:rsocket-rpc-protobuf:0.2.18 -io.rsocket:rsocket-core:0.12.2-RC4 -io.rsocket:rsocket-transport-netty:0.12.2-RC4 +io.rsocket:rsocket-core:1.0.0-RC5 +io.rsocket:rsocket-transport-netty:1.0.0-RC5 javax.annotation:javax.annotation-api:1.3.2 javax.inject:javax.inject:1 org.checkerframework:checker-qual:2.5.2 org.codehaus.mojo:animal-sniffer-annotations:1.17 org.hdrhistogram:HdrHistogram:2.1.10 org.latencyutils:LatencyUtils:2.0.3 -org.reactivestreams:reactive-streams:1.0.2 +org.reactivestreams:reactive-streams:1.0.3 org.slf4j:slf4j-api:1.7.25 diff --git a/netifi-metrics-influx/gradle/dependency-locks/compileClasspath.lockfile b/netifi-metrics-influx/gradle/dependency-locks/compileClasspath.lockfile index 69734bab..f7e4b796 100644 --- a/netifi-metrics-influx/gradle/dependency-locks/compileClasspath.lockfile +++ b/netifi-metrics-influx/gradle/dependency-locks/compileClasspath.lockfile @@ -25,17 +25,18 @@ io.netty:netty-transport-native-epoll:4.1.36.Final io.netty:netty-transport-native-unix-common:4.1.36.Final io.netty:netty-transport:4.1.36.Final io.opentracing:opentracing-api:0.31.0 -io.projectreactor.netty:reactor-netty:0.8.8.RELEASE -io.projectreactor:reactor-core:3.2.9.RELEASE +io.projectreactor.addons:reactor-pool:0.1.0.RELEASE +io.projectreactor.netty:reactor-netty:0.9.0.RELEASE +io.projectreactor:reactor-core:3.3.0.RELEASE io.rsocket.rpc:rsocket-rpc-core:0.2.18 io.rsocket.rpc:rsocket-rpc-protobuf:0.2.18 -io.rsocket:rsocket-core:0.12.2-RC4 -io.rsocket:rsocket-transport-netty:0.12.2-RC4 +io.rsocket:rsocket-core:1.0.0-RC5 +io.rsocket:rsocket-transport-netty:1.0.0-RC5 javax.annotation:javax.annotation-api:1.3.2 javax.inject:javax.inject:1 org.checkerframework:checker-qual:2.5.2 org.codehaus.mojo:animal-sniffer-annotations:1.17 org.hdrhistogram:HdrHistogram:2.1.10 org.latencyutils:LatencyUtils:2.0.3 -org.reactivestreams:reactive-streams:1.0.2 +org.reactivestreams:reactive-streams:1.0.3 org.slf4j:slf4j-api:1.7.25 diff --git a/netifi-metrics-influx/gradle/dependency-locks/testCompile.lockfile b/netifi-metrics-influx/gradle/dependency-locks/testCompile.lockfile index 6123bd2f..17be2a5a 100644 --- a/netifi-metrics-influx/gradle/dependency-locks/testCompile.lockfile +++ b/netifi-metrics-influx/gradle/dependency-locks/testCompile.lockfile @@ -25,12 +25,13 @@ io.netty:netty-transport-native-epoll:4.1.36.Final io.netty:netty-transport-native-unix-common:4.1.36.Final io.netty:netty-transport:4.1.36.Final io.opentracing:opentracing-api:0.31.0 -io.projectreactor.netty:reactor-netty:0.8.8.RELEASE -io.projectreactor:reactor-core:3.2.9.RELEASE +io.projectreactor.addons:reactor-pool:0.1.0.RELEASE +io.projectreactor.netty:reactor-netty:0.9.0.RELEASE +io.projectreactor:reactor-core:3.3.0.RELEASE io.rsocket.rpc:rsocket-rpc-core:0.2.18 io.rsocket.rpc:rsocket-rpc-protobuf:0.2.18 -io.rsocket:rsocket-core:0.12.2-RC4 -io.rsocket:rsocket-transport-netty:0.12.2-RC4 +io.rsocket:rsocket-core:1.0.0-RC5 +io.rsocket:rsocket-transport-netty:1.0.0-RC5 javax.annotation:javax.annotation-api:1.3.2 javax.inject:javax.inject:1 org.apache.logging.log4j:log4j-api:2.11.2 @@ -40,5 +41,5 @@ org.checkerframework:checker-qual:2.5.2 org.codehaus.mojo:animal-sniffer-annotations:1.17 org.hdrhistogram:HdrHistogram:2.1.10 org.latencyutils:LatencyUtils:2.0.3 -org.reactivestreams:reactive-streams:1.0.2 +org.reactivestreams:reactive-streams:1.0.3 org.slf4j:slf4j-api:1.7.25 diff --git a/netifi-metrics-influx/gradle/dependency-locks/testCompileClasspath.lockfile b/netifi-metrics-influx/gradle/dependency-locks/testCompileClasspath.lockfile index 6123bd2f..17be2a5a 100644 --- a/netifi-metrics-influx/gradle/dependency-locks/testCompileClasspath.lockfile +++ b/netifi-metrics-influx/gradle/dependency-locks/testCompileClasspath.lockfile @@ -25,12 +25,13 @@ io.netty:netty-transport-native-epoll:4.1.36.Final io.netty:netty-transport-native-unix-common:4.1.36.Final io.netty:netty-transport:4.1.36.Final io.opentracing:opentracing-api:0.31.0 -io.projectreactor.netty:reactor-netty:0.8.8.RELEASE -io.projectreactor:reactor-core:3.2.9.RELEASE +io.projectreactor.addons:reactor-pool:0.1.0.RELEASE +io.projectreactor.netty:reactor-netty:0.9.0.RELEASE +io.projectreactor:reactor-core:3.3.0.RELEASE io.rsocket.rpc:rsocket-rpc-core:0.2.18 io.rsocket.rpc:rsocket-rpc-protobuf:0.2.18 -io.rsocket:rsocket-core:0.12.2-RC4 -io.rsocket:rsocket-transport-netty:0.12.2-RC4 +io.rsocket:rsocket-core:1.0.0-RC5 +io.rsocket:rsocket-transport-netty:1.0.0-RC5 javax.annotation:javax.annotation-api:1.3.2 javax.inject:javax.inject:1 org.apache.logging.log4j:log4j-api:2.11.2 @@ -40,5 +41,5 @@ org.checkerframework:checker-qual:2.5.2 org.codehaus.mojo:animal-sniffer-annotations:1.17 org.hdrhistogram:HdrHistogram:2.1.10 org.latencyutils:LatencyUtils:2.0.3 -org.reactivestreams:reactive-streams:1.0.2 +org.reactivestreams:reactive-streams:1.0.3 org.slf4j:slf4j-api:1.7.25 diff --git a/netifi-metrics-micrometer/gradle/dependency-locks/compile.lockfile b/netifi-metrics-micrometer/gradle/dependency-locks/compile.lockfile index 63a1ac25..78619d3d 100644 --- a/netifi-metrics-micrometer/gradle/dependency-locks/compile.lockfile +++ b/netifi-metrics-micrometer/gradle/dependency-locks/compile.lockfile @@ -26,15 +26,16 @@ io.netty:netty-transport-native-epoll:4.1.36.Final io.netty:netty-transport-native-unix-common:4.1.36.Final io.netty:netty-transport:4.1.36.Final io.opentracing:opentracing-api:0.31.0 -io.projectreactor.netty:reactor-netty:0.8.8.RELEASE -io.projectreactor:reactor-core:3.2.9.RELEASE +io.projectreactor.addons:reactor-pool:0.1.0.RELEASE +io.projectreactor.netty:reactor-netty:0.9.0.RELEASE +io.projectreactor:reactor-core:3.3.0.RELEASE io.rsocket.rpc:rsocket-rpc-core:0.2.18 io.rsocket.rpc:rsocket-rpc-protobuf:0.2.18 -io.rsocket:rsocket-core:0.12.2-RC4 -io.rsocket:rsocket-transport-netty:0.12.2-RC4 +io.rsocket:rsocket-core:1.0.0-RC5 +io.rsocket:rsocket-transport-netty:1.0.0-RC5 javax.annotation:javax.annotation-api:1.3.2 javax.inject:javax.inject:1 org.hdrhistogram:HdrHistogram:2.1.10 org.latencyutils:LatencyUtils:2.0.3 -org.reactivestreams:reactive-streams:1.0.2 +org.reactivestreams:reactive-streams:1.0.3 org.slf4j:slf4j-api:1.7.25 diff --git a/netifi-metrics-micrometer/gradle/dependency-locks/compileClasspath.lockfile b/netifi-metrics-micrometer/gradle/dependency-locks/compileClasspath.lockfile index 63a1ac25..78619d3d 100644 --- a/netifi-metrics-micrometer/gradle/dependency-locks/compileClasspath.lockfile +++ b/netifi-metrics-micrometer/gradle/dependency-locks/compileClasspath.lockfile @@ -26,15 +26,16 @@ io.netty:netty-transport-native-epoll:4.1.36.Final io.netty:netty-transport-native-unix-common:4.1.36.Final io.netty:netty-transport:4.1.36.Final io.opentracing:opentracing-api:0.31.0 -io.projectreactor.netty:reactor-netty:0.8.8.RELEASE -io.projectreactor:reactor-core:3.2.9.RELEASE +io.projectreactor.addons:reactor-pool:0.1.0.RELEASE +io.projectreactor.netty:reactor-netty:0.9.0.RELEASE +io.projectreactor:reactor-core:3.3.0.RELEASE io.rsocket.rpc:rsocket-rpc-core:0.2.18 io.rsocket.rpc:rsocket-rpc-protobuf:0.2.18 -io.rsocket:rsocket-core:0.12.2-RC4 -io.rsocket:rsocket-transport-netty:0.12.2-RC4 +io.rsocket:rsocket-core:1.0.0-RC5 +io.rsocket:rsocket-transport-netty:1.0.0-RC5 javax.annotation:javax.annotation-api:1.3.2 javax.inject:javax.inject:1 org.hdrhistogram:HdrHistogram:2.1.10 org.latencyutils:LatencyUtils:2.0.3 -org.reactivestreams:reactive-streams:1.0.2 +org.reactivestreams:reactive-streams:1.0.3 org.slf4j:slf4j-api:1.7.25 diff --git a/netifi-metrics-micrometer/gradle/dependency-locks/testCompile.lockfile b/netifi-metrics-micrometer/gradle/dependency-locks/testCompile.lockfile index c51fce4e..8db41681 100644 --- a/netifi-metrics-micrometer/gradle/dependency-locks/testCompile.lockfile +++ b/netifi-metrics-micrometer/gradle/dependency-locks/testCompile.lockfile @@ -26,14 +26,15 @@ io.netty:netty-transport-native-epoll:4.1.36.Final io.netty:netty-transport-native-unix-common:4.1.36.Final io.netty:netty-transport:4.1.36.Final io.opentracing:opentracing-api:0.31.0 -io.projectreactor.netty:reactor-netty:0.8.8.RELEASE -io.projectreactor:reactor-core:3.2.9.RELEASE -io.projectreactor:reactor-test:3.2.9.RELEASE +io.projectreactor.addons:reactor-pool:0.1.0.RELEASE +io.projectreactor.netty:reactor-netty:0.9.0.RELEASE +io.projectreactor:reactor-core:3.3.0.RELEASE +io.projectreactor:reactor-test:3.3.0.RELEASE io.rsocket.rpc:rsocket-rpc-core:0.2.18 io.rsocket.rpc:rsocket-rpc-protobuf:0.2.18 -io.rsocket:rsocket-core:0.12.2-RC4 -io.rsocket:rsocket-transport-local:0.12.2-RC4 -io.rsocket:rsocket-transport-netty:0.12.2-RC4 +io.rsocket:rsocket-core:1.0.0-RC5 +io.rsocket:rsocket-transport-local:1.0.0-RC5 +io.rsocket:rsocket-transport-netty:1.0.0-RC5 javax.annotation:javax.annotation-api:1.3.2 javax.inject:javax.inject:1 junit:junit:4.12 @@ -47,5 +48,5 @@ org.hdrhistogram:HdrHistogram:2.1.10 org.latencyutils:LatencyUtils:2.0.3 org.mockito:mockito-core:2.25.0 org.objenesis:objenesis:2.6 -org.reactivestreams:reactive-streams:1.0.2 +org.reactivestreams:reactive-streams:1.0.3 org.slf4j:slf4j-api:1.7.25 diff --git a/netifi-metrics-micrometer/gradle/dependency-locks/testCompileClasspath.lockfile b/netifi-metrics-micrometer/gradle/dependency-locks/testCompileClasspath.lockfile index c51fce4e..8db41681 100644 --- a/netifi-metrics-micrometer/gradle/dependency-locks/testCompileClasspath.lockfile +++ b/netifi-metrics-micrometer/gradle/dependency-locks/testCompileClasspath.lockfile @@ -26,14 +26,15 @@ io.netty:netty-transport-native-epoll:4.1.36.Final io.netty:netty-transport-native-unix-common:4.1.36.Final io.netty:netty-transport:4.1.36.Final io.opentracing:opentracing-api:0.31.0 -io.projectreactor.netty:reactor-netty:0.8.8.RELEASE -io.projectreactor:reactor-core:3.2.9.RELEASE -io.projectreactor:reactor-test:3.2.9.RELEASE +io.projectreactor.addons:reactor-pool:0.1.0.RELEASE +io.projectreactor.netty:reactor-netty:0.9.0.RELEASE +io.projectreactor:reactor-core:3.3.0.RELEASE +io.projectreactor:reactor-test:3.3.0.RELEASE io.rsocket.rpc:rsocket-rpc-core:0.2.18 io.rsocket.rpc:rsocket-rpc-protobuf:0.2.18 -io.rsocket:rsocket-core:0.12.2-RC4 -io.rsocket:rsocket-transport-local:0.12.2-RC4 -io.rsocket:rsocket-transport-netty:0.12.2-RC4 +io.rsocket:rsocket-core:1.0.0-RC5 +io.rsocket:rsocket-transport-local:1.0.0-RC5 +io.rsocket:rsocket-transport-netty:1.0.0-RC5 javax.annotation:javax.annotation-api:1.3.2 javax.inject:javax.inject:1 junit:junit:4.12 @@ -47,5 +48,5 @@ org.hdrhistogram:HdrHistogram:2.1.10 org.latencyutils:LatencyUtils:2.0.3 org.mockito:mockito-core:2.25.0 org.objenesis:objenesis:2.6 -org.reactivestreams:reactive-streams:1.0.2 +org.reactivestreams:reactive-streams:1.0.3 org.slf4j:slf4j-api:1.7.25 diff --git a/netifi-metrics-prometheus/gradle/dependency-locks/compile.lockfile b/netifi-metrics-prometheus/gradle/dependency-locks/compile.lockfile index e57463d3..c9b1f5af 100644 --- a/netifi-metrics-prometheus/gradle/dependency-locks/compile.lockfile +++ b/netifi-metrics-prometheus/gradle/dependency-locks/compile.lockfile @@ -19,17 +19,18 @@ io.netty:netty-transport-native-epoll:4.1.36.Final io.netty:netty-transport-native-unix-common:4.1.36.Final io.netty:netty-transport:4.1.36.Final io.opentracing:opentracing-api:0.31.0 -io.projectreactor.netty:reactor-netty:0.8.8.RELEASE -io.projectreactor:reactor-core:3.2.9.RELEASE +io.projectreactor.addons:reactor-pool:0.1.0.RELEASE +io.projectreactor.netty:reactor-netty:0.9.0.RELEASE +io.projectreactor:reactor-core:3.3.0.RELEASE io.prometheus:simpleclient:0.4.0 io.prometheus:simpleclient_common:0.4.0 io.rsocket.rpc:rsocket-rpc-core:0.2.18 io.rsocket.rpc:rsocket-rpc-protobuf:0.2.18 -io.rsocket:rsocket-core:0.12.2-RC4 -io.rsocket:rsocket-transport-netty:0.12.2-RC4 +io.rsocket:rsocket-core:1.0.0-RC5 +io.rsocket:rsocket-transport-netty:1.0.0-RC5 javax.annotation:javax.annotation-api:1.3.2 javax.inject:javax.inject:1 org.hdrhistogram:HdrHistogram:2.1.10 org.latencyutils:LatencyUtils:2.0.3 -org.reactivestreams:reactive-streams:1.0.2 +org.reactivestreams:reactive-streams:1.0.3 org.slf4j:slf4j-api:1.7.25 diff --git a/netifi-metrics-prometheus/gradle/dependency-locks/compileClasspath.lockfile b/netifi-metrics-prometheus/gradle/dependency-locks/compileClasspath.lockfile index e57463d3..c9b1f5af 100644 --- a/netifi-metrics-prometheus/gradle/dependency-locks/compileClasspath.lockfile +++ b/netifi-metrics-prometheus/gradle/dependency-locks/compileClasspath.lockfile @@ -19,17 +19,18 @@ io.netty:netty-transport-native-epoll:4.1.36.Final io.netty:netty-transport-native-unix-common:4.1.36.Final io.netty:netty-transport:4.1.36.Final io.opentracing:opentracing-api:0.31.0 -io.projectreactor.netty:reactor-netty:0.8.8.RELEASE -io.projectreactor:reactor-core:3.2.9.RELEASE +io.projectreactor.addons:reactor-pool:0.1.0.RELEASE +io.projectreactor.netty:reactor-netty:0.9.0.RELEASE +io.projectreactor:reactor-core:3.3.0.RELEASE io.prometheus:simpleclient:0.4.0 io.prometheus:simpleclient_common:0.4.0 io.rsocket.rpc:rsocket-rpc-core:0.2.18 io.rsocket.rpc:rsocket-rpc-protobuf:0.2.18 -io.rsocket:rsocket-core:0.12.2-RC4 -io.rsocket:rsocket-transport-netty:0.12.2-RC4 +io.rsocket:rsocket-core:1.0.0-RC5 +io.rsocket:rsocket-transport-netty:1.0.0-RC5 javax.annotation:javax.annotation-api:1.3.2 javax.inject:javax.inject:1 org.hdrhistogram:HdrHistogram:2.1.10 org.latencyutils:LatencyUtils:2.0.3 -org.reactivestreams:reactive-streams:1.0.2 +org.reactivestreams:reactive-streams:1.0.3 org.slf4j:slf4j-api:1.7.25 diff --git a/netifi-metrics-prometheus/gradle/dependency-locks/testCompile.lockfile b/netifi-metrics-prometheus/gradle/dependency-locks/testCompile.lockfile index 3f361be2..ad9c1009 100644 --- a/netifi-metrics-prometheus/gradle/dependency-locks/testCompile.lockfile +++ b/netifi-metrics-prometheus/gradle/dependency-locks/testCompile.lockfile @@ -19,16 +19,17 @@ io.netty:netty-transport-native-epoll:4.1.36.Final io.netty:netty-transport-native-unix-common:4.1.36.Final io.netty:netty-transport:4.1.36.Final io.opentracing:opentracing-api:0.31.0 -io.projectreactor.netty:reactor-netty:0.8.8.RELEASE -io.projectreactor:reactor-core:3.2.9.RELEASE -io.projectreactor:reactor-test:3.2.9.RELEASE +io.projectreactor.addons:reactor-pool:0.1.0.RELEASE +io.projectreactor.netty:reactor-netty:0.9.0.RELEASE +io.projectreactor:reactor-core:3.3.0.RELEASE +io.projectreactor:reactor-test:3.3.0.RELEASE io.prometheus:simpleclient:0.4.0 io.prometheus:simpleclient_common:0.4.0 io.rsocket.rpc:rsocket-rpc-core:0.2.18 io.rsocket.rpc:rsocket-rpc-protobuf:0.2.18 -io.rsocket:rsocket-core:0.12.2-RC4 -io.rsocket:rsocket-transport-local:0.12.2-RC4 -io.rsocket:rsocket-transport-netty:0.12.2-RC4 +io.rsocket:rsocket-core:1.0.0-RC5 +io.rsocket:rsocket-transport-local:1.0.0-RC5 +io.rsocket:rsocket-transport-netty:1.0.0-RC5 javax.annotation:javax.annotation-api:1.3.2 javax.inject:javax.inject:1 junit:junit:4.12 @@ -42,5 +43,5 @@ org.hdrhistogram:HdrHistogram:2.1.10 org.latencyutils:LatencyUtils:2.0.3 org.mockito:mockito-core:2.25.0 org.objenesis:objenesis:2.6 -org.reactivestreams:reactive-streams:1.0.2 +org.reactivestreams:reactive-streams:1.0.3 org.slf4j:slf4j-api:1.7.25 diff --git a/netifi-metrics-prometheus/gradle/dependency-locks/testCompileClasspath.lockfile b/netifi-metrics-prometheus/gradle/dependency-locks/testCompileClasspath.lockfile index 3f361be2..ad9c1009 100644 --- a/netifi-metrics-prometheus/gradle/dependency-locks/testCompileClasspath.lockfile +++ b/netifi-metrics-prometheus/gradle/dependency-locks/testCompileClasspath.lockfile @@ -19,16 +19,17 @@ io.netty:netty-transport-native-epoll:4.1.36.Final io.netty:netty-transport-native-unix-common:4.1.36.Final io.netty:netty-transport:4.1.36.Final io.opentracing:opentracing-api:0.31.0 -io.projectreactor.netty:reactor-netty:0.8.8.RELEASE -io.projectreactor:reactor-core:3.2.9.RELEASE -io.projectreactor:reactor-test:3.2.9.RELEASE +io.projectreactor.addons:reactor-pool:0.1.0.RELEASE +io.projectreactor.netty:reactor-netty:0.9.0.RELEASE +io.projectreactor:reactor-core:3.3.0.RELEASE +io.projectreactor:reactor-test:3.3.0.RELEASE io.prometheus:simpleclient:0.4.0 io.prometheus:simpleclient_common:0.4.0 io.rsocket.rpc:rsocket-rpc-core:0.2.18 io.rsocket.rpc:rsocket-rpc-protobuf:0.2.18 -io.rsocket:rsocket-core:0.12.2-RC4 -io.rsocket:rsocket-transport-local:0.12.2-RC4 -io.rsocket:rsocket-transport-netty:0.12.2-RC4 +io.rsocket:rsocket-core:1.0.0-RC5 +io.rsocket:rsocket-transport-local:1.0.0-RC5 +io.rsocket:rsocket-transport-netty:1.0.0-RC5 javax.annotation:javax.annotation-api:1.3.2 javax.inject:javax.inject:1 junit:junit:4.12 @@ -42,5 +43,5 @@ org.hdrhistogram:HdrHistogram:2.1.10 org.latencyutils:LatencyUtils:2.0.3 org.mockito:mockito-core:2.25.0 org.objenesis:objenesis:2.6 -org.reactivestreams:reactive-streams:1.0.2 +org.reactivestreams:reactive-streams:1.0.3 org.slf4j:slf4j-api:1.7.25 diff --git a/netifi-spring-boot-autoconfigure/gradle/dependency-locks/compileClasspath.lockfile b/netifi-spring-boot-autoconfigure/gradle/dependency-locks/compileClasspath.lockfile index 6acbd788..4492c676 100644 --- a/netifi-spring-boot-autoconfigure/gradle/dependency-locks/compileClasspath.lockfile +++ b/netifi-spring-boot-autoconfigure/gradle/dependency-locks/compileClasspath.lockfile @@ -45,8 +45,8 @@ io.projectreactor.netty:reactor-netty:0.8.8.RELEASE io.projectreactor:reactor-core:3.2.9.RELEASE io.rsocket.rpc:rsocket-rpc-core:0.2.18 io.rsocket.rpc:rsocket-rpc-protobuf:0.2.18 -io.rsocket:rsocket-core:0.12.2-RC4 -io.rsocket:rsocket-transport-netty:0.12.2-RC4 +io.rsocket:rsocket-core:1.0.0-RC5 +io.rsocket:rsocket-transport-netty:1.0.0-RC5 io.zipkin.brave:brave:5.6.1 io.zipkin.reporter2:zipkin-reporter:2.7.14 io.zipkin.zipkin2:zipkin:2.12.0 diff --git a/netifi-spring-boot-autoconfigure/gradle/dependency-locks/testCompileClasspath.lockfile b/netifi-spring-boot-autoconfigure/gradle/dependency-locks/testCompileClasspath.lockfile index 2cf14050..4983d08d 100644 --- a/netifi-spring-boot-autoconfigure/gradle/dependency-locks/testCompileClasspath.lockfile +++ b/netifi-spring-boot-autoconfigure/gradle/dependency-locks/testCompileClasspath.lockfile @@ -26,8 +26,8 @@ io.opentracing:opentracing-api:0.31.0 io.projectreactor.netty:reactor-netty:0.8.8.RELEASE io.projectreactor:reactor-core:3.2.9.RELEASE io.rsocket.rpc:rsocket-rpc-core:0.2.18 -io.rsocket:rsocket-core:0.12.2-RC4 -io.rsocket:rsocket-transport-netty:0.12.2-RC4 +io.rsocket:rsocket-core:1.0.0-RC5 +io.rsocket:rsocket-transport-netty:1.0.0-RC5 javax.annotation:javax.annotation-api:1.3.2 javax.inject:javax.inject:1 javax.validation:validation-api:2.0.1.Final diff --git a/netifi-spring-boot-autoconfigure/gradle/dependency-locks/testRuntimeClasspath.lockfile b/netifi-spring-boot-autoconfigure/gradle/dependency-locks/testRuntimeClasspath.lockfile index eca434d7..5669f335 100644 --- a/netifi-spring-boot-autoconfigure/gradle/dependency-locks/testRuntimeClasspath.lockfile +++ b/netifi-spring-boot-autoconfigure/gradle/dependency-locks/testRuntimeClasspath.lockfile @@ -26,8 +26,8 @@ io.opentracing:opentracing-api:0.31.0 io.projectreactor.netty:reactor-netty:0.8.8.RELEASE io.projectreactor:reactor-core:3.2.9.RELEASE io.rsocket.rpc:rsocket-rpc-core:0.2.18 -io.rsocket:rsocket-core:0.12.2-RC4 -io.rsocket:rsocket-transport-netty:0.12.2-RC4 +io.rsocket:rsocket-core:1.0.0-RC5 +io.rsocket:rsocket-transport-netty:1.0.0-RC5 javax.annotation:javax.annotation-api:1.3.2 javax.inject:javax.inject:1 javax.validation:validation-api:2.0.1.Final diff --git a/netifi-spring-core/gradle/dependency-locks/compileClasspath.lockfile b/netifi-spring-core/gradle/dependency-locks/compileClasspath.lockfile index ab1c2f03..73ea6494 100644 --- a/netifi-spring-core/gradle/dependency-locks/compileClasspath.lockfile +++ b/netifi-spring-core/gradle/dependency-locks/compileClasspath.lockfile @@ -21,8 +21,8 @@ io.opentracing:opentracing-api:0.31.0 io.projectreactor.netty:reactor-netty:0.8.8.RELEASE io.projectreactor:reactor-core:3.2.9.RELEASE io.rsocket.rpc:rsocket-rpc-core:0.2.18 -io.rsocket:rsocket-core:0.12.2-RC4 -io.rsocket:rsocket-transport-netty:0.12.2-RC4 +io.rsocket:rsocket-core:1.0.0-RC5 +io.rsocket:rsocket-transport-netty:1.0.0-RC5 javax.annotation:javax.annotation-api:1.3.2 javax.inject:javax.inject:1 javax.validation:validation-api:2.0.1.Final diff --git a/netifi-spring-core/gradle/dependency-locks/testCompileClasspath.lockfile b/netifi-spring-core/gradle/dependency-locks/testCompileClasspath.lockfile index a0c2fa77..fe5ce444 100644 --- a/netifi-spring-core/gradle/dependency-locks/testCompileClasspath.lockfile +++ b/netifi-spring-core/gradle/dependency-locks/testCompileClasspath.lockfile @@ -21,8 +21,8 @@ io.opentracing:opentracing-api:0.31.0 io.projectreactor.netty:reactor-netty:0.8.8.RELEASE io.projectreactor:reactor-core:3.2.9.RELEASE io.rsocket.rpc:rsocket-rpc-core:0.2.18 -io.rsocket:rsocket-core:0.12.2-RC4 -io.rsocket:rsocket-transport-netty:0.12.2-RC4 +io.rsocket:rsocket-core:1.0.0-RC5 +io.rsocket:rsocket-transport-netty:1.0.0-RC5 javax.annotation:javax.annotation-api:1.3.2 javax.inject:javax.inject:1 javax.validation:validation-api:2.0.1.Final diff --git a/netifi-spring-core/gradle/dependency-locks/testRuntimeClasspath.lockfile b/netifi-spring-core/gradle/dependency-locks/testRuntimeClasspath.lockfile index a0c2fa77..fe5ce444 100644 --- a/netifi-spring-core/gradle/dependency-locks/testRuntimeClasspath.lockfile +++ b/netifi-spring-core/gradle/dependency-locks/testRuntimeClasspath.lockfile @@ -21,8 +21,8 @@ io.opentracing:opentracing-api:0.31.0 io.projectreactor.netty:reactor-netty:0.8.8.RELEASE io.projectreactor:reactor-core:3.2.9.RELEASE io.rsocket.rpc:rsocket-rpc-core:0.2.18 -io.rsocket:rsocket-core:0.12.2-RC4 -io.rsocket:rsocket-transport-netty:0.12.2-RC4 +io.rsocket:rsocket-core:1.0.0-RC5 +io.rsocket:rsocket-transport-netty:1.0.0-RC5 javax.annotation:javax.annotation-api:1.3.2 javax.inject:javax.inject:1 javax.validation:validation-api:2.0.1.Final diff --git a/netifi-tracing-openzipkin/gradle/dependency-locks/compile.lockfile b/netifi-tracing-openzipkin/gradle/dependency-locks/compile.lockfile index 64a06b53..0b9476a1 100644 --- a/netifi-tracing-openzipkin/gradle/dependency-locks/compile.lockfile +++ b/netifi-tracing-openzipkin/gradle/dependency-locks/compile.lockfile @@ -32,13 +32,14 @@ io.netty:netty-transport-native-unix-common:4.1.36.Final io.netty:netty-transport:4.1.36.Final io.opentracing.brave:brave-opentracing:0.33.10 io.opentracing:opentracing-api:0.31.0 -io.projectreactor.addons:reactor-adapter:3.2.3.RELEASE -io.projectreactor.netty:reactor-netty:0.8.8.RELEASE -io.projectreactor:reactor-core:3.2.9.RELEASE +io.projectreactor.addons:reactor-adapter:3.3.0.RELEASE +io.projectreactor.addons:reactor-pool:0.1.0.RELEASE +io.projectreactor.netty:reactor-netty:0.9.0.RELEASE +io.projectreactor:reactor-core:3.3.0.RELEASE io.rsocket.rpc:rsocket-rpc-core:0.2.18 io.rsocket.rpc:rsocket-rpc-protobuf:0.2.18 -io.rsocket:rsocket-core:0.12.2-RC4 -io.rsocket:rsocket-transport-netty:0.12.2-RC4 +io.rsocket:rsocket-core:1.0.0-RC5 +io.rsocket:rsocket-transport-netty:1.0.0-RC5 io.zipkin.brave:brave:5.6.1 io.zipkin.reporter2:zipkin-reporter:2.7.14 io.zipkin.zipkin2:zipkin:2.12.0 @@ -48,5 +49,5 @@ org.checkerframework:checker-qual:2.5.2 org.codehaus.mojo:animal-sniffer-annotations:1.17 org.hdrhistogram:HdrHistogram:2.1.10 org.latencyutils:LatencyUtils:2.0.3 -org.reactivestreams:reactive-streams:1.0.2 +org.reactivestreams:reactive-streams:1.0.3 org.slf4j:slf4j-api:1.7.25 diff --git a/netifi-tracing-openzipkin/gradle/dependency-locks/compileClasspath.lockfile b/netifi-tracing-openzipkin/gradle/dependency-locks/compileClasspath.lockfile index 64a06b53..0b9476a1 100644 --- a/netifi-tracing-openzipkin/gradle/dependency-locks/compileClasspath.lockfile +++ b/netifi-tracing-openzipkin/gradle/dependency-locks/compileClasspath.lockfile @@ -32,13 +32,14 @@ io.netty:netty-transport-native-unix-common:4.1.36.Final io.netty:netty-transport:4.1.36.Final io.opentracing.brave:brave-opentracing:0.33.10 io.opentracing:opentracing-api:0.31.0 -io.projectreactor.addons:reactor-adapter:3.2.3.RELEASE -io.projectreactor.netty:reactor-netty:0.8.8.RELEASE -io.projectreactor:reactor-core:3.2.9.RELEASE +io.projectreactor.addons:reactor-adapter:3.3.0.RELEASE +io.projectreactor.addons:reactor-pool:0.1.0.RELEASE +io.projectreactor.netty:reactor-netty:0.9.0.RELEASE +io.projectreactor:reactor-core:3.3.0.RELEASE io.rsocket.rpc:rsocket-rpc-core:0.2.18 io.rsocket.rpc:rsocket-rpc-protobuf:0.2.18 -io.rsocket:rsocket-core:0.12.2-RC4 -io.rsocket:rsocket-transport-netty:0.12.2-RC4 +io.rsocket:rsocket-core:1.0.0-RC5 +io.rsocket:rsocket-transport-netty:1.0.0-RC5 io.zipkin.brave:brave:5.6.1 io.zipkin.reporter2:zipkin-reporter:2.7.14 io.zipkin.zipkin2:zipkin:2.12.0 @@ -48,5 +49,5 @@ org.checkerframework:checker-qual:2.5.2 org.codehaus.mojo:animal-sniffer-annotations:1.17 org.hdrhistogram:HdrHistogram:2.1.10 org.latencyutils:LatencyUtils:2.0.3 -org.reactivestreams:reactive-streams:1.0.2 +org.reactivestreams:reactive-streams:1.0.3 org.slf4j:slf4j-api:1.7.25 diff --git a/netifi-tracing-openzipkin/gradle/dependency-locks/testCompile.lockfile b/netifi-tracing-openzipkin/gradle/dependency-locks/testCompile.lockfile index b36d74fc..235fb180 100644 --- a/netifi-tracing-openzipkin/gradle/dependency-locks/testCompile.lockfile +++ b/netifi-tracing-openzipkin/gradle/dependency-locks/testCompile.lockfile @@ -32,15 +32,16 @@ io.netty:netty-transport-native-unix-common:4.1.36.Final io.netty:netty-transport:4.1.36.Final io.opentracing.brave:brave-opentracing:0.33.10 io.opentracing:opentracing-api:0.31.0 -io.projectreactor.addons:reactor-adapter:3.2.3.RELEASE -io.projectreactor.netty:reactor-netty:0.8.8.RELEASE -io.projectreactor:reactor-core:3.2.9.RELEASE -io.projectreactor:reactor-test:3.2.9.RELEASE +io.projectreactor.addons:reactor-adapter:3.3.0.RELEASE +io.projectreactor.addons:reactor-pool:0.1.0.RELEASE +io.projectreactor.netty:reactor-netty:0.9.0.RELEASE +io.projectreactor:reactor-core:3.3.0.RELEASE +io.projectreactor:reactor-test:3.3.0.RELEASE io.rsocket.rpc:rsocket-rpc-core:0.2.18 io.rsocket.rpc:rsocket-rpc-protobuf:0.2.18 -io.rsocket:rsocket-core:0.12.2-RC4 -io.rsocket:rsocket-transport-local:0.12.2-RC4 -io.rsocket:rsocket-transport-netty:0.12.2-RC4 +io.rsocket:rsocket-core:1.0.0-RC5 +io.rsocket:rsocket-transport-local:1.0.0-RC5 +io.rsocket:rsocket-transport-netty:1.0.0-RC5 io.zipkin.brave:brave:5.6.1 io.zipkin.reporter2:zipkin-reporter:2.7.14 io.zipkin.zipkin2:zipkin:2.12.0 @@ -59,5 +60,5 @@ org.hdrhistogram:HdrHistogram:2.1.10 org.latencyutils:LatencyUtils:2.0.3 org.mockito:mockito-core:2.25.0 org.objenesis:objenesis:2.6 -org.reactivestreams:reactive-streams:1.0.2 +org.reactivestreams:reactive-streams:1.0.3 org.slf4j:slf4j-api:1.7.25 diff --git a/netifi-tracing-openzipkin/gradle/dependency-locks/testCompileClasspath.lockfile b/netifi-tracing-openzipkin/gradle/dependency-locks/testCompileClasspath.lockfile index b36d74fc..235fb180 100644 --- a/netifi-tracing-openzipkin/gradle/dependency-locks/testCompileClasspath.lockfile +++ b/netifi-tracing-openzipkin/gradle/dependency-locks/testCompileClasspath.lockfile @@ -32,15 +32,16 @@ io.netty:netty-transport-native-unix-common:4.1.36.Final io.netty:netty-transport:4.1.36.Final io.opentracing.brave:brave-opentracing:0.33.10 io.opentracing:opentracing-api:0.31.0 -io.projectreactor.addons:reactor-adapter:3.2.3.RELEASE -io.projectreactor.netty:reactor-netty:0.8.8.RELEASE -io.projectreactor:reactor-core:3.2.9.RELEASE -io.projectreactor:reactor-test:3.2.9.RELEASE +io.projectreactor.addons:reactor-adapter:3.3.0.RELEASE +io.projectreactor.addons:reactor-pool:0.1.0.RELEASE +io.projectreactor.netty:reactor-netty:0.9.0.RELEASE +io.projectreactor:reactor-core:3.3.0.RELEASE +io.projectreactor:reactor-test:3.3.0.RELEASE io.rsocket.rpc:rsocket-rpc-core:0.2.18 io.rsocket.rpc:rsocket-rpc-protobuf:0.2.18 -io.rsocket:rsocket-core:0.12.2-RC4 -io.rsocket:rsocket-transport-local:0.12.2-RC4 -io.rsocket:rsocket-transport-netty:0.12.2-RC4 +io.rsocket:rsocket-core:1.0.0-RC5 +io.rsocket:rsocket-transport-local:1.0.0-RC5 +io.rsocket:rsocket-transport-netty:1.0.0-RC5 io.zipkin.brave:brave:5.6.1 io.zipkin.reporter2:zipkin-reporter:2.7.14 io.zipkin.zipkin2:zipkin:2.12.0 @@ -59,5 +60,5 @@ org.hdrhistogram:HdrHistogram:2.1.10 org.latencyutils:LatencyUtils:2.0.3 org.mockito:mockito-core:2.25.0 org.objenesis:objenesis:2.6 -org.reactivestreams:reactive-streams:1.0.2 +org.reactivestreams:reactive-streams:1.0.3 org.slf4j:slf4j-api:1.7.25 diff --git a/netifi-tracing-openzipkin/gradle/dependency-locks/testRuntimeClasspath.lockfile b/netifi-tracing-openzipkin/gradle/dependency-locks/testRuntimeClasspath.lockfile index b36d74fc..235fb180 100644 --- a/netifi-tracing-openzipkin/gradle/dependency-locks/testRuntimeClasspath.lockfile +++ b/netifi-tracing-openzipkin/gradle/dependency-locks/testRuntimeClasspath.lockfile @@ -32,15 +32,16 @@ io.netty:netty-transport-native-unix-common:4.1.36.Final io.netty:netty-transport:4.1.36.Final io.opentracing.brave:brave-opentracing:0.33.10 io.opentracing:opentracing-api:0.31.0 -io.projectreactor.addons:reactor-adapter:3.2.3.RELEASE -io.projectreactor.netty:reactor-netty:0.8.8.RELEASE -io.projectreactor:reactor-core:3.2.9.RELEASE -io.projectreactor:reactor-test:3.2.9.RELEASE +io.projectreactor.addons:reactor-adapter:3.3.0.RELEASE +io.projectreactor.addons:reactor-pool:0.1.0.RELEASE +io.projectreactor.netty:reactor-netty:0.9.0.RELEASE +io.projectreactor:reactor-core:3.3.0.RELEASE +io.projectreactor:reactor-test:3.3.0.RELEASE io.rsocket.rpc:rsocket-rpc-core:0.2.18 io.rsocket.rpc:rsocket-rpc-protobuf:0.2.18 -io.rsocket:rsocket-core:0.12.2-RC4 -io.rsocket:rsocket-transport-local:0.12.2-RC4 -io.rsocket:rsocket-transport-netty:0.12.2-RC4 +io.rsocket:rsocket-core:1.0.0-RC5 +io.rsocket:rsocket-transport-local:1.0.0-RC5 +io.rsocket:rsocket-transport-netty:1.0.0-RC5 io.zipkin.brave:brave:5.6.1 io.zipkin.reporter2:zipkin-reporter:2.7.14 io.zipkin.zipkin2:zipkin:2.12.0 @@ -59,5 +60,5 @@ org.hdrhistogram:HdrHistogram:2.1.10 org.latencyutils:LatencyUtils:2.0.3 org.mockito:mockito-core:2.25.0 org.objenesis:objenesis:2.6 -org.reactivestreams:reactive-streams:1.0.2 +org.reactivestreams:reactive-streams:1.0.3 org.slf4j:slf4j-api:1.7.25 From f8d60ac551486b1c9c062dbeda445ed5c3cbc6cd Mon Sep 17 00:00:00 2001 From: Oleh Dokuka Date: Wed, 15 May 2019 18:48:01 +0200 Subject: [PATCH 4/9] partial --- dependency-management.gradle | 6 +- .../buildscript-classpath.lockfile | 4 +- .../netifi/broker/DefaultBuilderConfig.java | 46 +- .../broker/DefaultBuilderConfigTest.java | 15 + .../testCompileClasspath.lockfile~merged | 35 + .../dependency-locks/protobuf.lockfile~merged | 3 + .../testCompileClasspath.lockfile~merged | 35 + .../annotationProcessor.lockfile~merged | 3 + .../googleJavaFormat1.6.lockfile~merged | 13 + .../testAnnotationProcessor.lockfile~merged | 3 + .../testCompileClasspath.lockfile~merged | 35 + .../testRuntimeClasspath.lockfile~merged | 35 + .../annotationProcessor.lockfile~merged | 3 + .../googleJavaFormat1.6.lockfile~merged | 13 + .../testAnnotationProcessor.lockfile~merged | 3 + .../annotationProcessor.lockfile~merged | 3 + .../googleJavaFormat1.6.lockfile~merged | 13 + .../testAnnotationProcessor.lockfile~merged | 3 + .../annotationProcessor.lockfile~merged | 3 + .../googleJavaFormat1.6.lockfile~merged | 13 + .../testAnnotationProcessor.lockfile~merged | 3 + .../annotationProcessor.lockfile~merged | 3 + .../googleJavaFormat1.6.lockfile~merged | 13 + .../testAnnotationProcessor.lockfile~merged | 3 + .../testCompileClasspath.lockfile~merged | 35 + .../testRuntimeClasspath.lockfile~merged | 35 + netifi-spring-boot-autoconfigure/build.gradle | 6 +- ...rokerClientMessagingAutoConfiguration.java | 104 +++ .../boot/BrokerClientMessagingProperties.java | 44 ++ .../main/resources/META-INF/spring.factories | 1 + .../boot/SpringMessagingIntegrationTest.java | 41 ++ .../spring/core/BrokerClientFactory.java | 8 + .../core/BrokerClientFactorySupport.java | 11 + .../core/DestinationAwareClientFactory.java | 3 +- .../annotation/BaseBrokerClientFactory.java | 105 +++ .../spring/core/annotation/BrokerClient.java | 53 +- ...ntBeanDefinitionRegistryPostProcessor.java | 24 +- .../annotation/BrokerClientStaticFactory.java | 678 ++++++++---------- .../DefaultBroadcastAwareClientFactory.java | 59 ++ .../DefaultDestinationAwareClientFactory.java | 59 ++ .../DefaultGroupAwareClientFactory.java | 59 ++ .../RpcBrokerClientFactorySupport.java | 48 ++ .../config/BrokerClientConfiguration.java | 10 + netifi-spring-messaging/build.gradle | 36 + .../annotationProcessor.lockfile | 3 + .../compileClasspath.lockfile | 39 + .../googleJavaFormat1.6.lockfile | 13 + .../testAnnotationProcessor.lockfile | 3 + .../testCompileClasspath.lockfile | 49 ++ .../testRuntimeClasspath.lockfile | 49 ++ ...ClientRequesterMethodArgumentResolver.java | 104 +++ ...essagingRSocketRequesterClientFactory.java | 61 ++ .../MetricsAwareRSocketRequester.java | 151 ++++ .../RSocketRequesterStaticFactory.java | 75 ++ .../spring/DefaultExternalIdlClient.java | 34 + .../java/com/netifi/spring/ExternalIdl.java | 18 + ...utowireInsideComponentIntegrationTest.java | 98 +++ ...sideConfigurationClassIntegrationTest.java | 101 +++ .../spring/core/DefaultClientTestIdl.java | 35 + .../core/PlainAutowireIntegrationTest.java | 87 +++ .../java/com/netifi/spring/core/TestBean.java | 59 ++ .../java/com/netifi/spring/core/TestIdl.java | 2 +- .../com/netifi/spring/core/TestIdlImpl.java | 18 + .../spring/core/TestIdlServiceServer.java | 33 + .../spring/core/TestableConfiguration.java | 37 + .../dependency-locks/compile.lockfile~merged | 3 + .../annotationProcessor.lockfile~merged | 3 + .../dependency-locks/protobuf.lockfile~merged | 3 + .../testAnnotationProcessor.lockfile~merged | 3 + settings.gradle | 1 + 70 files changed, 2392 insertions(+), 418 deletions(-) create mode 100644 netifi-broker-info-idl/gradle/dependency-locks/testCompileClasspath.lockfile~merged create mode 100644 netifi-broker-mgmt-idl/gradle/dependency-locks/protobuf.lockfile~merged create mode 100644 netifi-broker-mgmt-idl/gradle/dependency-locks/testCompileClasspath.lockfile~merged create mode 100644 netifi-common/gradle/dependency-locks/annotationProcessor.lockfile~merged create mode 100644 netifi-common/gradle/dependency-locks/googleJavaFormat1.6.lockfile~merged create mode 100644 netifi-common/gradle/dependency-locks/testAnnotationProcessor.lockfile~merged create mode 100644 netifi-common/gradle/dependency-locks/testCompileClasspath.lockfile~merged create mode 100644 netifi-common/gradle/dependency-locks/testRuntimeClasspath.lockfile~merged create mode 100644 netifi-discovery-aws/gradle/dependency-locks/annotationProcessor.lockfile~merged create mode 100644 netifi-discovery-aws/gradle/dependency-locks/googleJavaFormat1.6.lockfile~merged create mode 100644 netifi-discovery-aws/gradle/dependency-locks/testAnnotationProcessor.lockfile~merged create mode 100644 netifi-discovery-consul/gradle/dependency-locks/annotationProcessor.lockfile~merged create mode 100644 netifi-discovery-consul/gradle/dependency-locks/googleJavaFormat1.6.lockfile~merged create mode 100644 netifi-discovery-consul/gradle/dependency-locks/testAnnotationProcessor.lockfile~merged create mode 100644 netifi-discovery-kubernetes/gradle/dependency-locks/annotationProcessor.lockfile~merged create mode 100644 netifi-discovery-kubernetes/gradle/dependency-locks/googleJavaFormat1.6.lockfile~merged create mode 100644 netifi-discovery-kubernetes/gradle/dependency-locks/testAnnotationProcessor.lockfile~merged create mode 100644 netifi-discovery/gradle/dependency-locks/annotationProcessor.lockfile~merged create mode 100644 netifi-discovery/gradle/dependency-locks/googleJavaFormat1.6.lockfile~merged create mode 100644 netifi-discovery/gradle/dependency-locks/testAnnotationProcessor.lockfile~merged create mode 100644 netifi-discovery/gradle/dependency-locks/testCompileClasspath.lockfile~merged create mode 100644 netifi-discovery/gradle/dependency-locks/testRuntimeClasspath.lockfile~merged create mode 100644 netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientMessagingAutoConfiguration.java create mode 100644 netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientMessagingProperties.java create mode 100644 netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/SpringMessagingIntegrationTest.java create mode 100644 netifi-spring-core/src/main/java/com/netifi/spring/core/BrokerClientFactorySupport.java create mode 100644 netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BaseBrokerClientFactory.java create mode 100644 netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/DefaultBroadcastAwareClientFactory.java create mode 100644 netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/DefaultDestinationAwareClientFactory.java create mode 100644 netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/DefaultGroupAwareClientFactory.java create mode 100644 netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/RpcBrokerClientFactorySupport.java create mode 100644 netifi-spring-messaging/build.gradle create mode 100644 netifi-spring-messaging/gradle/dependency-locks/annotationProcessor.lockfile create mode 100644 netifi-spring-messaging/gradle/dependency-locks/compileClasspath.lockfile create mode 100644 netifi-spring-messaging/gradle/dependency-locks/googleJavaFormat1.6.lockfile create mode 100644 netifi-spring-messaging/gradle/dependency-locks/testAnnotationProcessor.lockfile create mode 100644 netifi-spring-messaging/gradle/dependency-locks/testCompileClasspath.lockfile create mode 100644 netifi-spring-messaging/gradle/dependency-locks/testRuntimeClasspath.lockfile create mode 100644 netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/BrokerClientRequesterMethodArgumentResolver.java create mode 100644 netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/MessagingRSocketRequesterClientFactory.java create mode 100644 netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/MetricsAwareRSocketRequester.java create mode 100644 netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/RSocketRequesterStaticFactory.java create mode 100644 netifi-spring-messaging/src/test/java/com/netifi/spring/DefaultExternalIdlClient.java create mode 100644 netifi-spring-messaging/src/test/java/com/netifi/spring/ExternalIdl.java create mode 100644 netifi-spring-messaging/src/test/java/com/netifi/spring/core/AutowireInsideComponentIntegrationTest.java create mode 100644 netifi-spring-messaging/src/test/java/com/netifi/spring/core/AutowireInsideConfigurationClassIntegrationTest.java create mode 100644 netifi-spring-messaging/src/test/java/com/netifi/spring/core/DefaultClientTestIdl.java create mode 100644 netifi-spring-messaging/src/test/java/com/netifi/spring/core/PlainAutowireIntegrationTest.java create mode 100644 netifi-spring-messaging/src/test/java/com/netifi/spring/core/TestBean.java rename netifi-spring-core/src/main/java/com/netifi/spring/core/NoClass.java => netifi-spring-messaging/src/test/java/com/netifi/spring/core/TestIdl.java (95%) create mode 100644 netifi-spring-messaging/src/test/java/com/netifi/spring/core/TestIdlImpl.java create mode 100644 netifi-spring-messaging/src/test/java/com/netifi/spring/core/TestIdlServiceServer.java create mode 100644 netifi-spring-messaging/src/test/java/com/netifi/spring/core/TestableConfiguration.java create mode 100644 netifi-tracing-idl/gradle/dependency-locks/compile.lockfile~merged create mode 100644 netifi-tracing-openzipkin/gradle/dependency-locks/annotationProcessor.lockfile~merged create mode 100644 netifi-tracing-openzipkin/gradle/dependency-locks/protobuf.lockfile~merged create mode 100644 netifi-tracing-openzipkin/gradle/dependency-locks/testAnnotationProcessor.lockfile~merged diff --git a/dependency-management.gradle b/dependency-management.gradle index cafe615c..f69e869c 100644 --- a/dependency-management.gradle +++ b/dependency-management.gradle @@ -15,7 +15,10 @@ dependencyManagement { dependencies { dependency "org.slf4j:slf4j-api:${slf4jVersion}" - + + dependency 'org.openjdk.jmh:jmh-core:0.9' + dependency 'org.openjdk.jmh:jmh-generator-annprocess:0.9' + dependency "com.github.davidmoten:rxjava2-jdbc:${rxjava2JdbcVersion}" dependency "com.github.davidmoten:rxjava2-jdbc:${rxjava2JdbcVersion}" dependency "com.google.guava:guava:${guavaVersion}" dependency "com.google.protobuf:protoc:${protobufVersion}" @@ -75,5 +78,6 @@ dependencyManagement { dependency "org.postgresql:postgresql:${postgresqlVersion}" dependency "org.roaringbitmap:RoaringBitmap:${roaringbitmapVersion}" dependency "org.springframework.boot:spring-boot-starter:${springBootDependenciesVersion}" + dependency "org.testcontainers:testcontainers:${testcontainersVersion}" } } \ No newline at end of file diff --git a/gradle/dependency-locks/buildscript-classpath.lockfile b/gradle/dependency-locks/buildscript-classpath.lockfile index 5b16e961..31202810 100644 --- a/gradle/dependency-locks/buildscript-classpath.lockfile +++ b/gradle/dependency-locks/buildscript-classpath.lockfile @@ -32,8 +32,8 @@ javax.annotation:jsr250-api:1.0 javax.enterprise:cdi-api:1.0 javax.inject:javax.inject:1 kr.motd.maven:os-maven-plugin:1.4.0.Final -me.champeau.gradle.jmh:me.champeau.gradle.jmh.gradle.plugin:0.4.7 -me.champeau.gradle:jmh-gradle-plugin:0.4.7 +me.champeau.gradle.jmh:me.champeau.gradle.jmh.gradle.plugin:0.4.8 +me.champeau.gradle:jmh-gradle-plugin:0.4.8 net.sf.jopt-simple:jopt-simple:4.6 org.apache.commons:commons-math3:3.2 org.apache.commons:commons-pool2:2.2 diff --git a/netifi-broker-client/src/main/java/com/netifi/broker/DefaultBuilderConfig.java b/netifi-broker-client/src/main/java/com/netifi/broker/DefaultBuilderConfig.java index 5e78456a..54abfbda 100644 --- a/netifi-broker-client/src/main/java/com/netifi/broker/DefaultBuilderConfig.java +++ b/netifi-broker-client/src/main/java/com/netifi/broker/DefaultBuilderConfig.java @@ -23,8 +23,11 @@ import java.net.SocketAddress; import java.net.UnknownHostException; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; /** * Gets current default configuration for {@link BrokerClient.Builder}. Can be overriden with System @@ -148,13 +151,40 @@ static short getAdditionalConnectionFlags() { static Tags getTags() { Tags tags = Tags.empty(); try { - Arrays.stream(conf.getString("netifi.client.tags").split(",")) - .forEach( - s -> { - String[] t = s.split(":"); - Tag tag = Tag.of(t[0], t[1]); - tags.and(tag); - }); + Stream stream = + conf.getObject("netifi.client.tags") + .entrySet() + .stream() + .map( + e -> { + StringBuilder key = new StringBuilder(e.getKey()); + ConfigValue configValue = e.getValue(); + + while (configValue != null && + configValue.valueType() == ConfigValueType.OBJECT) { + Set keySet = + ((ConfigObject) configValue).keySet(); + String nextKey = keySet.iterator() + .next(); + key.append(".").append(nextKey); + configValue = ((ConfigObject) configValue).get(nextKey); + } + + if (configValue != null && configValue.valueType() == ConfigValueType.STRING) { + String value = (String) configValue.unwrapped(); + + if (value.isEmpty()) { + throw new IllegalArgumentException("Tag mapping " + key + " is empty"); + } + + return Tag.of(key.toString(), value); + } + + throw new IllegalArgumentException( + "Tag mapping " + key + " is not a string: " + configValue); + }); + tags = Tags.of(stream.collect(Collectors.toList())); + } catch (ConfigException.Missing m) { } catch (Throwable t) { System.err.println("error parsing tags from config: " + t.getMessage()); diff --git a/netifi-broker-client/src/test/java/com/netifi/broker/DefaultBuilderConfigTest.java b/netifi-broker-client/src/test/java/com/netifi/broker/DefaultBuilderConfigTest.java index dcc639f8..cda37e56 100644 --- a/netifi-broker-client/src/test/java/com/netifi/broker/DefaultBuilderConfigTest.java +++ b/netifi-broker-client/src/test/java/com/netifi/broker/DefaultBuilderConfigTest.java @@ -18,6 +18,10 @@ import java.net.InetSocketAddress; import java.net.SocketAddress; import java.util.List; +import java.util.Optional; + +import com.netifi.common.tags.Tag; +import com.netifi.common.tags.Tags; import org.junit.Assert; import org.junit.Ignore; import org.junit.Test; @@ -60,6 +64,17 @@ public void testShouldThrowExceptionForInvalidAddress() { List seedAddress = DefaultBuilderConfig.getSeedAddress(); } + @Test + public void testShouldParseTagsSuccessfully() { + System.setProperty("netifi.client.tags.com.netifi.destination", "myDestination"); + Tags tags = DefaultBuilderConfig.getTags(); + Optional first = tags.stream() + .findFirst(); + + Assert.assertTrue(first.isPresent()); + Assert.assertEquals(first.get(), Tag.of("com.netifi.destination", "myDestination")); + } + @Test public void testShouldReturnNull() { List seedAddress = DefaultBuilderConfig.getSeedAddress(); diff --git a/netifi-broker-info-idl/gradle/dependency-locks/testCompileClasspath.lockfile~merged b/netifi-broker-info-idl/gradle/dependency-locks/testCompileClasspath.lockfile~merged new file mode 100644 index 00000000..597c5914 --- /dev/null +++ b/netifi-broker-info-idl/gradle/dependency-locks/testCompileClasspath.lockfile~merged @@ -0,0 +1,35 @@ +# This is a Gradle generated file for dependency locking. +# Manual edits can break the build and are not advised. +# This file is expected to be part of source control. +com.google.protobuf:protobuf-java:3.6.1 +io.netty:netty-buffer:4.1.31.Final +io.netty:netty-codec-http2:4.1.31.Final +io.netty:netty-codec-http:4.1.31.Final +io.netty:netty-codec-socks:4.1.31.Final +io.netty:netty-codec:4.1.31.Final +io.netty:netty-common:4.1.31.Final +io.netty:netty-handler-proxy:4.1.31.Final +io.netty:netty-handler:4.1.31.Final +io.netty:netty-resolver:4.1.31.Final +io.netty:netty-transport-native-epoll:4.1.31.Final +io.netty:netty-transport-native-unix-common:4.1.31.Final +io.netty:netty-transport:4.1.31.Final +io.projectreactor.netty:reactor-netty:0.8.5.RELEASE +io.projectreactor:reactor-core:3.2.6.RELEASE +io.projectreactor:reactor-test:3.2.6.RELEASE +io.rsocket:rsocket-core:0.11.17.2 +io.rsocket:rsocket-transport-local:0.11.17.2 +io.rsocket:rsocket-transport-netty:0.11.17.2 +javax.inject:javax.inject:1 +junit:junit:4.12 +net.bytebuddy:byte-buddy-agent:1.9.7 +net.bytebuddy:byte-buddy:1.9.7 +org.apache.logging.log4j:log4j-api:2.11.2 +org.apache.logging.log4j:log4j-core:2.11.2 +org.apache.logging.log4j:log4j-slf4j-impl:2.11.2 +org.hamcrest:hamcrest-core:1.3 +org.hdrhistogram:HdrHistogram:2.1.10 +org.mockito:mockito-core:2.25.0 +org.objenesis:objenesis:2.6 +org.reactivestreams:reactive-streams:1.0.2 +org.slf4j:slf4j-api:1.7.25 diff --git a/netifi-broker-mgmt-idl/gradle/dependency-locks/protobuf.lockfile~merged b/netifi-broker-mgmt-idl/gradle/dependency-locks/protobuf.lockfile~merged new file mode 100644 index 00000000..656c5dbc --- /dev/null +++ b/netifi-broker-mgmt-idl/gradle/dependency-locks/protobuf.lockfile~merged @@ -0,0 +1,3 @@ +# This is a Gradle generated file for dependency locking. +# Manual edits can break the build and are not advised. +# This file is expected to be part of source control. diff --git a/netifi-broker-mgmt-idl/gradle/dependency-locks/testCompileClasspath.lockfile~merged b/netifi-broker-mgmt-idl/gradle/dependency-locks/testCompileClasspath.lockfile~merged new file mode 100644 index 00000000..597c5914 --- /dev/null +++ b/netifi-broker-mgmt-idl/gradle/dependency-locks/testCompileClasspath.lockfile~merged @@ -0,0 +1,35 @@ +# This is a Gradle generated file for dependency locking. +# Manual edits can break the build and are not advised. +# This file is expected to be part of source control. +com.google.protobuf:protobuf-java:3.6.1 +io.netty:netty-buffer:4.1.31.Final +io.netty:netty-codec-http2:4.1.31.Final +io.netty:netty-codec-http:4.1.31.Final +io.netty:netty-codec-socks:4.1.31.Final +io.netty:netty-codec:4.1.31.Final +io.netty:netty-common:4.1.31.Final +io.netty:netty-handler-proxy:4.1.31.Final +io.netty:netty-handler:4.1.31.Final +io.netty:netty-resolver:4.1.31.Final +io.netty:netty-transport-native-epoll:4.1.31.Final +io.netty:netty-transport-native-unix-common:4.1.31.Final +io.netty:netty-transport:4.1.31.Final +io.projectreactor.netty:reactor-netty:0.8.5.RELEASE +io.projectreactor:reactor-core:3.2.6.RELEASE +io.projectreactor:reactor-test:3.2.6.RELEASE +io.rsocket:rsocket-core:0.11.17.2 +io.rsocket:rsocket-transport-local:0.11.17.2 +io.rsocket:rsocket-transport-netty:0.11.17.2 +javax.inject:javax.inject:1 +junit:junit:4.12 +net.bytebuddy:byte-buddy-agent:1.9.7 +net.bytebuddy:byte-buddy:1.9.7 +org.apache.logging.log4j:log4j-api:2.11.2 +org.apache.logging.log4j:log4j-core:2.11.2 +org.apache.logging.log4j:log4j-slf4j-impl:2.11.2 +org.hamcrest:hamcrest-core:1.3 +org.hdrhistogram:HdrHistogram:2.1.10 +org.mockito:mockito-core:2.25.0 +org.objenesis:objenesis:2.6 +org.reactivestreams:reactive-streams:1.0.2 +org.slf4j:slf4j-api:1.7.25 diff --git a/netifi-common/gradle/dependency-locks/annotationProcessor.lockfile~merged b/netifi-common/gradle/dependency-locks/annotationProcessor.lockfile~merged new file mode 100644 index 00000000..656c5dbc --- /dev/null +++ b/netifi-common/gradle/dependency-locks/annotationProcessor.lockfile~merged @@ -0,0 +1,3 @@ +# This is a Gradle generated file for dependency locking. +# Manual edits can break the build and are not advised. +# This file is expected to be part of source control. diff --git a/netifi-common/gradle/dependency-locks/googleJavaFormat1.6.lockfile~merged b/netifi-common/gradle/dependency-locks/googleJavaFormat1.6.lockfile~merged new file mode 100644 index 00000000..a02de22c --- /dev/null +++ b/netifi-common/gradle/dependency-locks/googleJavaFormat1.6.lockfile~merged @@ -0,0 +1,13 @@ +# This is a Gradle generated file for dependency locking. +# Manual edits can break the build and are not advised. +# This file is expected to be part of source control. +com.google.code.findbugs:jsr305:3.0.2 +com.google.errorprone:error_prone_annotations:2.2.0 +com.google.errorprone:javac-shaded:9+181-r4173-1 +com.google.googlejavaformat:google-java-format:1.6 +com.google.guava:failureaccess:1.0.1 +com.google.guava:guava:27.0.1-jre +com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava +com.google.j2objc:j2objc-annotations:1.1 +org.checkerframework:checker-qual:2.5.2 +org.codehaus.mojo:animal-sniffer-annotations:1.17 diff --git a/netifi-common/gradle/dependency-locks/testAnnotationProcessor.lockfile~merged b/netifi-common/gradle/dependency-locks/testAnnotationProcessor.lockfile~merged new file mode 100644 index 00000000..656c5dbc --- /dev/null +++ b/netifi-common/gradle/dependency-locks/testAnnotationProcessor.lockfile~merged @@ -0,0 +1,3 @@ +# This is a Gradle generated file for dependency locking. +# Manual edits can break the build and are not advised. +# This file is expected to be part of source control. diff --git a/netifi-common/gradle/dependency-locks/testCompileClasspath.lockfile~merged b/netifi-common/gradle/dependency-locks/testCompileClasspath.lockfile~merged new file mode 100644 index 00000000..597c5914 --- /dev/null +++ b/netifi-common/gradle/dependency-locks/testCompileClasspath.lockfile~merged @@ -0,0 +1,35 @@ +# This is a Gradle generated file for dependency locking. +# Manual edits can break the build and are not advised. +# This file is expected to be part of source control. +com.google.protobuf:protobuf-java:3.6.1 +io.netty:netty-buffer:4.1.31.Final +io.netty:netty-codec-http2:4.1.31.Final +io.netty:netty-codec-http:4.1.31.Final +io.netty:netty-codec-socks:4.1.31.Final +io.netty:netty-codec:4.1.31.Final +io.netty:netty-common:4.1.31.Final +io.netty:netty-handler-proxy:4.1.31.Final +io.netty:netty-handler:4.1.31.Final +io.netty:netty-resolver:4.1.31.Final +io.netty:netty-transport-native-epoll:4.1.31.Final +io.netty:netty-transport-native-unix-common:4.1.31.Final +io.netty:netty-transport:4.1.31.Final +io.projectreactor.netty:reactor-netty:0.8.5.RELEASE +io.projectreactor:reactor-core:3.2.6.RELEASE +io.projectreactor:reactor-test:3.2.6.RELEASE +io.rsocket:rsocket-core:0.11.17.2 +io.rsocket:rsocket-transport-local:0.11.17.2 +io.rsocket:rsocket-transport-netty:0.11.17.2 +javax.inject:javax.inject:1 +junit:junit:4.12 +net.bytebuddy:byte-buddy-agent:1.9.7 +net.bytebuddy:byte-buddy:1.9.7 +org.apache.logging.log4j:log4j-api:2.11.2 +org.apache.logging.log4j:log4j-core:2.11.2 +org.apache.logging.log4j:log4j-slf4j-impl:2.11.2 +org.hamcrest:hamcrest-core:1.3 +org.hdrhistogram:HdrHistogram:2.1.10 +org.mockito:mockito-core:2.25.0 +org.objenesis:objenesis:2.6 +org.reactivestreams:reactive-streams:1.0.2 +org.slf4j:slf4j-api:1.7.25 diff --git a/netifi-common/gradle/dependency-locks/testRuntimeClasspath.lockfile~merged b/netifi-common/gradle/dependency-locks/testRuntimeClasspath.lockfile~merged new file mode 100644 index 00000000..597c5914 --- /dev/null +++ b/netifi-common/gradle/dependency-locks/testRuntimeClasspath.lockfile~merged @@ -0,0 +1,35 @@ +# This is a Gradle generated file for dependency locking. +# Manual edits can break the build and are not advised. +# This file is expected to be part of source control. +com.google.protobuf:protobuf-java:3.6.1 +io.netty:netty-buffer:4.1.31.Final +io.netty:netty-codec-http2:4.1.31.Final +io.netty:netty-codec-http:4.1.31.Final +io.netty:netty-codec-socks:4.1.31.Final +io.netty:netty-codec:4.1.31.Final +io.netty:netty-common:4.1.31.Final +io.netty:netty-handler-proxy:4.1.31.Final +io.netty:netty-handler:4.1.31.Final +io.netty:netty-resolver:4.1.31.Final +io.netty:netty-transport-native-epoll:4.1.31.Final +io.netty:netty-transport-native-unix-common:4.1.31.Final +io.netty:netty-transport:4.1.31.Final +io.projectreactor.netty:reactor-netty:0.8.5.RELEASE +io.projectreactor:reactor-core:3.2.6.RELEASE +io.projectreactor:reactor-test:3.2.6.RELEASE +io.rsocket:rsocket-core:0.11.17.2 +io.rsocket:rsocket-transport-local:0.11.17.2 +io.rsocket:rsocket-transport-netty:0.11.17.2 +javax.inject:javax.inject:1 +junit:junit:4.12 +net.bytebuddy:byte-buddy-agent:1.9.7 +net.bytebuddy:byte-buddy:1.9.7 +org.apache.logging.log4j:log4j-api:2.11.2 +org.apache.logging.log4j:log4j-core:2.11.2 +org.apache.logging.log4j:log4j-slf4j-impl:2.11.2 +org.hamcrest:hamcrest-core:1.3 +org.hdrhistogram:HdrHistogram:2.1.10 +org.mockito:mockito-core:2.25.0 +org.objenesis:objenesis:2.6 +org.reactivestreams:reactive-streams:1.0.2 +org.slf4j:slf4j-api:1.7.25 diff --git a/netifi-discovery-aws/gradle/dependency-locks/annotationProcessor.lockfile~merged b/netifi-discovery-aws/gradle/dependency-locks/annotationProcessor.lockfile~merged new file mode 100644 index 00000000..656c5dbc --- /dev/null +++ b/netifi-discovery-aws/gradle/dependency-locks/annotationProcessor.lockfile~merged @@ -0,0 +1,3 @@ +# This is a Gradle generated file for dependency locking. +# Manual edits can break the build and are not advised. +# This file is expected to be part of source control. diff --git a/netifi-discovery-aws/gradle/dependency-locks/googleJavaFormat1.6.lockfile~merged b/netifi-discovery-aws/gradle/dependency-locks/googleJavaFormat1.6.lockfile~merged new file mode 100644 index 00000000..a02de22c --- /dev/null +++ b/netifi-discovery-aws/gradle/dependency-locks/googleJavaFormat1.6.lockfile~merged @@ -0,0 +1,13 @@ +# This is a Gradle generated file for dependency locking. +# Manual edits can break the build and are not advised. +# This file is expected to be part of source control. +com.google.code.findbugs:jsr305:3.0.2 +com.google.errorprone:error_prone_annotations:2.2.0 +com.google.errorprone:javac-shaded:9+181-r4173-1 +com.google.googlejavaformat:google-java-format:1.6 +com.google.guava:failureaccess:1.0.1 +com.google.guava:guava:27.0.1-jre +com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava +com.google.j2objc:j2objc-annotations:1.1 +org.checkerframework:checker-qual:2.5.2 +org.codehaus.mojo:animal-sniffer-annotations:1.17 diff --git a/netifi-discovery-aws/gradle/dependency-locks/testAnnotationProcessor.lockfile~merged b/netifi-discovery-aws/gradle/dependency-locks/testAnnotationProcessor.lockfile~merged new file mode 100644 index 00000000..656c5dbc --- /dev/null +++ b/netifi-discovery-aws/gradle/dependency-locks/testAnnotationProcessor.lockfile~merged @@ -0,0 +1,3 @@ +# This is a Gradle generated file for dependency locking. +# Manual edits can break the build and are not advised. +# This file is expected to be part of source control. diff --git a/netifi-discovery-consul/gradle/dependency-locks/annotationProcessor.lockfile~merged b/netifi-discovery-consul/gradle/dependency-locks/annotationProcessor.lockfile~merged new file mode 100644 index 00000000..656c5dbc --- /dev/null +++ b/netifi-discovery-consul/gradle/dependency-locks/annotationProcessor.lockfile~merged @@ -0,0 +1,3 @@ +# This is a Gradle generated file for dependency locking. +# Manual edits can break the build and are not advised. +# This file is expected to be part of source control. diff --git a/netifi-discovery-consul/gradle/dependency-locks/googleJavaFormat1.6.lockfile~merged b/netifi-discovery-consul/gradle/dependency-locks/googleJavaFormat1.6.lockfile~merged new file mode 100644 index 00000000..a02de22c --- /dev/null +++ b/netifi-discovery-consul/gradle/dependency-locks/googleJavaFormat1.6.lockfile~merged @@ -0,0 +1,13 @@ +# This is a Gradle generated file for dependency locking. +# Manual edits can break the build and are not advised. +# This file is expected to be part of source control. +com.google.code.findbugs:jsr305:3.0.2 +com.google.errorprone:error_prone_annotations:2.2.0 +com.google.errorprone:javac-shaded:9+181-r4173-1 +com.google.googlejavaformat:google-java-format:1.6 +com.google.guava:failureaccess:1.0.1 +com.google.guava:guava:27.0.1-jre +com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava +com.google.j2objc:j2objc-annotations:1.1 +org.checkerframework:checker-qual:2.5.2 +org.codehaus.mojo:animal-sniffer-annotations:1.17 diff --git a/netifi-discovery-consul/gradle/dependency-locks/testAnnotationProcessor.lockfile~merged b/netifi-discovery-consul/gradle/dependency-locks/testAnnotationProcessor.lockfile~merged new file mode 100644 index 00000000..656c5dbc --- /dev/null +++ b/netifi-discovery-consul/gradle/dependency-locks/testAnnotationProcessor.lockfile~merged @@ -0,0 +1,3 @@ +# This is a Gradle generated file for dependency locking. +# Manual edits can break the build and are not advised. +# This file is expected to be part of source control. diff --git a/netifi-discovery-kubernetes/gradle/dependency-locks/annotationProcessor.lockfile~merged b/netifi-discovery-kubernetes/gradle/dependency-locks/annotationProcessor.lockfile~merged new file mode 100644 index 00000000..656c5dbc --- /dev/null +++ b/netifi-discovery-kubernetes/gradle/dependency-locks/annotationProcessor.lockfile~merged @@ -0,0 +1,3 @@ +# This is a Gradle generated file for dependency locking. +# Manual edits can break the build and are not advised. +# This file is expected to be part of source control. diff --git a/netifi-discovery-kubernetes/gradle/dependency-locks/googleJavaFormat1.6.lockfile~merged b/netifi-discovery-kubernetes/gradle/dependency-locks/googleJavaFormat1.6.lockfile~merged new file mode 100644 index 00000000..a02de22c --- /dev/null +++ b/netifi-discovery-kubernetes/gradle/dependency-locks/googleJavaFormat1.6.lockfile~merged @@ -0,0 +1,13 @@ +# This is a Gradle generated file for dependency locking. +# Manual edits can break the build and are not advised. +# This file is expected to be part of source control. +com.google.code.findbugs:jsr305:3.0.2 +com.google.errorprone:error_prone_annotations:2.2.0 +com.google.errorprone:javac-shaded:9+181-r4173-1 +com.google.googlejavaformat:google-java-format:1.6 +com.google.guava:failureaccess:1.0.1 +com.google.guava:guava:27.0.1-jre +com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava +com.google.j2objc:j2objc-annotations:1.1 +org.checkerframework:checker-qual:2.5.2 +org.codehaus.mojo:animal-sniffer-annotations:1.17 diff --git a/netifi-discovery-kubernetes/gradle/dependency-locks/testAnnotationProcessor.lockfile~merged b/netifi-discovery-kubernetes/gradle/dependency-locks/testAnnotationProcessor.lockfile~merged new file mode 100644 index 00000000..656c5dbc --- /dev/null +++ b/netifi-discovery-kubernetes/gradle/dependency-locks/testAnnotationProcessor.lockfile~merged @@ -0,0 +1,3 @@ +# This is a Gradle generated file for dependency locking. +# Manual edits can break the build and are not advised. +# This file is expected to be part of source control. diff --git a/netifi-discovery/gradle/dependency-locks/annotationProcessor.lockfile~merged b/netifi-discovery/gradle/dependency-locks/annotationProcessor.lockfile~merged new file mode 100644 index 00000000..656c5dbc --- /dev/null +++ b/netifi-discovery/gradle/dependency-locks/annotationProcessor.lockfile~merged @@ -0,0 +1,3 @@ +# This is a Gradle generated file for dependency locking. +# Manual edits can break the build and are not advised. +# This file is expected to be part of source control. diff --git a/netifi-discovery/gradle/dependency-locks/googleJavaFormat1.6.lockfile~merged b/netifi-discovery/gradle/dependency-locks/googleJavaFormat1.6.lockfile~merged new file mode 100644 index 00000000..a02de22c --- /dev/null +++ b/netifi-discovery/gradle/dependency-locks/googleJavaFormat1.6.lockfile~merged @@ -0,0 +1,13 @@ +# This is a Gradle generated file for dependency locking. +# Manual edits can break the build and are not advised. +# This file is expected to be part of source control. +com.google.code.findbugs:jsr305:3.0.2 +com.google.errorprone:error_prone_annotations:2.2.0 +com.google.errorprone:javac-shaded:9+181-r4173-1 +com.google.googlejavaformat:google-java-format:1.6 +com.google.guava:failureaccess:1.0.1 +com.google.guava:guava:27.0.1-jre +com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava +com.google.j2objc:j2objc-annotations:1.1 +org.checkerframework:checker-qual:2.5.2 +org.codehaus.mojo:animal-sniffer-annotations:1.17 diff --git a/netifi-discovery/gradle/dependency-locks/testAnnotationProcessor.lockfile~merged b/netifi-discovery/gradle/dependency-locks/testAnnotationProcessor.lockfile~merged new file mode 100644 index 00000000..656c5dbc --- /dev/null +++ b/netifi-discovery/gradle/dependency-locks/testAnnotationProcessor.lockfile~merged @@ -0,0 +1,3 @@ +# This is a Gradle generated file for dependency locking. +# Manual edits can break the build and are not advised. +# This file is expected to be part of source control. diff --git a/netifi-discovery/gradle/dependency-locks/testCompileClasspath.lockfile~merged b/netifi-discovery/gradle/dependency-locks/testCompileClasspath.lockfile~merged new file mode 100644 index 00000000..597c5914 --- /dev/null +++ b/netifi-discovery/gradle/dependency-locks/testCompileClasspath.lockfile~merged @@ -0,0 +1,35 @@ +# This is a Gradle generated file for dependency locking. +# Manual edits can break the build and are not advised. +# This file is expected to be part of source control. +com.google.protobuf:protobuf-java:3.6.1 +io.netty:netty-buffer:4.1.31.Final +io.netty:netty-codec-http2:4.1.31.Final +io.netty:netty-codec-http:4.1.31.Final +io.netty:netty-codec-socks:4.1.31.Final +io.netty:netty-codec:4.1.31.Final +io.netty:netty-common:4.1.31.Final +io.netty:netty-handler-proxy:4.1.31.Final +io.netty:netty-handler:4.1.31.Final +io.netty:netty-resolver:4.1.31.Final +io.netty:netty-transport-native-epoll:4.1.31.Final +io.netty:netty-transport-native-unix-common:4.1.31.Final +io.netty:netty-transport:4.1.31.Final +io.projectreactor.netty:reactor-netty:0.8.5.RELEASE +io.projectreactor:reactor-core:3.2.6.RELEASE +io.projectreactor:reactor-test:3.2.6.RELEASE +io.rsocket:rsocket-core:0.11.17.2 +io.rsocket:rsocket-transport-local:0.11.17.2 +io.rsocket:rsocket-transport-netty:0.11.17.2 +javax.inject:javax.inject:1 +junit:junit:4.12 +net.bytebuddy:byte-buddy-agent:1.9.7 +net.bytebuddy:byte-buddy:1.9.7 +org.apache.logging.log4j:log4j-api:2.11.2 +org.apache.logging.log4j:log4j-core:2.11.2 +org.apache.logging.log4j:log4j-slf4j-impl:2.11.2 +org.hamcrest:hamcrest-core:1.3 +org.hdrhistogram:HdrHistogram:2.1.10 +org.mockito:mockito-core:2.25.0 +org.objenesis:objenesis:2.6 +org.reactivestreams:reactive-streams:1.0.2 +org.slf4j:slf4j-api:1.7.25 diff --git a/netifi-discovery/gradle/dependency-locks/testRuntimeClasspath.lockfile~merged b/netifi-discovery/gradle/dependency-locks/testRuntimeClasspath.lockfile~merged new file mode 100644 index 00000000..597c5914 --- /dev/null +++ b/netifi-discovery/gradle/dependency-locks/testRuntimeClasspath.lockfile~merged @@ -0,0 +1,35 @@ +# This is a Gradle generated file for dependency locking. +# Manual edits can break the build and are not advised. +# This file is expected to be part of source control. +com.google.protobuf:protobuf-java:3.6.1 +io.netty:netty-buffer:4.1.31.Final +io.netty:netty-codec-http2:4.1.31.Final +io.netty:netty-codec-http:4.1.31.Final +io.netty:netty-codec-socks:4.1.31.Final +io.netty:netty-codec:4.1.31.Final +io.netty:netty-common:4.1.31.Final +io.netty:netty-handler-proxy:4.1.31.Final +io.netty:netty-handler:4.1.31.Final +io.netty:netty-resolver:4.1.31.Final +io.netty:netty-transport-native-epoll:4.1.31.Final +io.netty:netty-transport-native-unix-common:4.1.31.Final +io.netty:netty-transport:4.1.31.Final +io.projectreactor.netty:reactor-netty:0.8.5.RELEASE +io.projectreactor:reactor-core:3.2.6.RELEASE +io.projectreactor:reactor-test:3.2.6.RELEASE +io.rsocket:rsocket-core:0.11.17.2 +io.rsocket:rsocket-transport-local:0.11.17.2 +io.rsocket:rsocket-transport-netty:0.11.17.2 +javax.inject:javax.inject:1 +junit:junit:4.12 +net.bytebuddy:byte-buddy-agent:1.9.7 +net.bytebuddy:byte-buddy:1.9.7 +org.apache.logging.log4j:log4j-api:2.11.2 +org.apache.logging.log4j:log4j-core:2.11.2 +org.apache.logging.log4j:log4j-slf4j-impl:2.11.2 +org.hamcrest:hamcrest-core:1.3 +org.hdrhistogram:HdrHistogram:2.1.10 +org.mockito:mockito-core:2.25.0 +org.objenesis:objenesis:2.6 +org.reactivestreams:reactive-streams:1.0.2 +org.slf4j:slf4j-api:1.7.25 diff --git a/netifi-spring-boot-autoconfigure/build.gradle b/netifi-spring-boot-autoconfigure/build.gradle index 83c5a0bd..b261b374 100644 --- a/netifi-spring-boot-autoconfigure/build.gradle +++ b/netifi-spring-boot-autoconfigure/build.gradle @@ -12,6 +12,7 @@ dependencyManagement { dependencies { compile project(':netifi-spring-core') + compile project(':netifi-spring-messaging') compile project(':netifi-broker-client') compile project(':netifi-discovery') @@ -20,7 +21,8 @@ dependencies { compile 'org.springframework.boot:spring-boot-starter-validation' compile 'io.opentracing:opentracing-api' compile 'io.micrometer:micrometer-core' - + + compileClasspath 'org.springframework:spring-messaging' compileClasspath project(':netifi-tracing-openzipkin') compileClasspath project(':netifi-metrics-micrometer') compileClasspath project(':netifi-discovery-aws') @@ -31,9 +33,11 @@ dependencies { annotationProcessor 'org.springframework.boot:spring-boot-autoconfigure-processor' testCompile 'org.springframework.boot:spring-boot-starter-test' + testCompile 'org.springframework:spring-messaging' testCompile 'org.mockito:mockito-core' testCompile 'org.junit.jupiter:junit-jupiter-api' testCompile 'org.junit.jupiter:junit-jupiter-engine' + testCompile "org.testcontainers:testcontainers" } test { diff --git a/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientMessagingAutoConfiguration.java b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientMessagingAutoConfiguration.java new file mode 100644 index 00000000..f9708e01 --- /dev/null +++ b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientMessagingAutoConfiguration.java @@ -0,0 +1,104 @@ +/* + * Copyright 2019 The Netifi Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.netifi.spring.boot; + +import java.util.Optional; + +import com.netifi.broker.BrokerClient; +import com.netifi.spring.messaging.BrokerClientRequesterMethodArgumentResolver; +import com.netifi.spring.messaging.MessagingRSocketRequesterClientFactory; +import io.micrometer.core.instrument.MeterRegistry; +import io.opentracing.Tracer; +import io.rsocket.AbstractRSocket; +import io.rsocket.RSocket; +import io.rsocket.RSocketFactory; +import io.rsocket.transport.netty.server.TcpServerTransport; + +import org.springframework.beans.factory.support.DefaultListableBeanFactory; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.rsocket.RSocketStrategiesAutoConfiguration; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.messaging.rsocket.MessageHandlerAcceptor; +import org.springframework.messaging.rsocket.RSocketRequester; +import org.springframework.messaging.rsocket.RSocketRequesterMethodArgumentResolver; +import org.springframework.messaging.rsocket.RSocketStrategies; + +/** + * {@link EnableAutoConfiguration Auto-configuration} for Spring RSocket support in Spring + * Messaging. + * + * @author Oleh Dokuka + * @since 1.7.0 + */ +@Configuration(proxyBeanMethods = false) +@ConditionalOnClass({ RSocketRequester.class, RSocketFactory.class, TcpServerTransport.class }) +@AutoConfigureAfter({ RSocketStrategiesAutoConfiguration.class, + BrokerClientAutoConfiguration.class }) +@EnableConfigurationProperties(BrokerClientMessagingProperties.class) +public class BrokerClientMessagingAutoConfiguration { + + private static final RSocket STUB_RSOCKET = new AbstractRSocket() {}; + + @Bean + @ConditionalOnMissingBean + public MessageHandlerAcceptor messageHandlerAcceptor( + BrokerClientMessagingProperties properties, + DefaultListableBeanFactory factory, + RSocketStrategies rSocketStrategies, + BrokerClient brokerClient + ) { + MessageHandlerAcceptor acceptor = new MessageHandlerAcceptor(); + acceptor.setRSocketStrategies(rSocketStrategies); + acceptor.getArgumentResolverConfigurer() + .getCustomResolvers() + .removeIf(r -> r instanceof RSocketRequesterMethodArgumentResolver); + + acceptor.getArgumentResolverConfigurer() + .addCustomResolver(new BrokerClientRequesterMethodArgumentResolver( + properties.getName(), + brokerClient, + factory, + rSocketStrategies + )); + + brokerClient.addNamedRSocket(properties.getName(), acceptor.apply(STUB_RSOCKET)); + + return acceptor; + } + + @Bean + public MessagingRSocketRequesterClientFactory messagingRSocketRequesterClientFactory( + BrokerClientMessagingProperties properties, + BrokerClient brokerClient, + RSocketStrategies rSocketStrategies, + Optional registry, + Optional tracer) { + return new MessagingRSocketRequesterClientFactory( + properties.getName(), + brokerClient, + registry.orElse(null), + tracer.orElse(null), + rSocketStrategies + ); + } + +} diff --git a/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientMessagingProperties.java b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientMessagingProperties.java new file mode 100644 index 00000000..57947229 --- /dev/null +++ b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientMessagingProperties.java @@ -0,0 +1,44 @@ +/* + * Copyright 2019 The Netifi Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.netifi.spring.boot; + +import javax.validation.constraints.Min; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.validation.annotation.Validated; + +/** + * Netifi Broker Client configuration options that can be set via the application + * properties files or system properties. + */ +@ConfigurationProperties("netifi.client.messaging") +@Validated +public class BrokerClientMessagingProperties { + + @NotEmpty + @NotNull + private String name = "spring-messaging"; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/netifi-spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories b/netifi-spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories index 079a0421..181bad26 100644 --- a/netifi-spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories +++ b/netifi-spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories @@ -1,4 +1,5 @@ # Auto Configure org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ com.netifi.spring.boot.BrokerClientAutoConfiguration,\ + com.netifi.spring.boot.BrokerClientMessagingAutoConfiguration,\ com.netifi.spring.core.config.BrokerClientConfiguration \ No newline at end of file diff --git a/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/SpringMessagingIntegrationTest.java b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/SpringMessagingIntegrationTest.java new file mode 100644 index 00000000..7c45ca39 --- /dev/null +++ b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/SpringMessagingIntegrationTest.java @@ -0,0 +1,41 @@ +package com.netifi.spring.boot; + +import com.netifi.spring.core.config.BrokerClientConfiguration; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.testcontainers.containers.GenericContainer; + +import org.springframework.boot.autoconfigure.ImportAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +@ExtendWith(SpringExtension.class) +@SpringBootTest +@DirtiesContext +@ImportAutoConfiguration({ + BrokerClientMessagingAutoConfiguration.class, + BrokerClientAutoConfiguration.class, + BrokerClientConfiguration.class, +}) +public class SpringMessagingIntegrationTest { + + @ClassRule + public static GenericContainer redis = + new GenericContainer("netifi/broker:1.6.2") + .withExposedPorts(8001, 7001, 6001, 8101) + .withEnv("BROKER_SERVER_OPTS", "-Dnetifi.broker.ssl.disabled=true " + + "-Dnetifi.authentication.0.accessKey=9007199254740991 " + + "-Dnetifi.authentication.0.accessToken=kTBDVtfRBO4tHOnZzSyY5ym2kfY= " + + "-Dnetifi.broker.admin.accessKey=9007199254740991 " + + "-Dnetifi.broker.admin.accessToken=kTBDVtfRBO4tHOnZzSyY5ym2kfY=" + ); + + + @Test + public void tests() { + + } + +} diff --git a/netifi-spring-core/src/main/java/com/netifi/spring/core/BrokerClientFactory.java b/netifi-spring-core/src/main/java/com/netifi/spring/core/BrokerClientFactory.java index f8a53e4f..d8a97765 100644 --- a/netifi-spring-core/src/main/java/com/netifi/spring/core/BrokerClientFactory.java +++ b/netifi-spring-core/src/main/java/com/netifi/spring/core/BrokerClientFactory.java @@ -27,4 +27,12 @@ public interface BrokerClientFactory { T lookup(BrokerClient.Type type); T lookup(BrokerClient.Type type, Tags tags); + + T lookup(String group, Tags tag); + + T lookup(String group, String... tags); + + T lookup(Tags tags); + + T lookup(); } diff --git a/netifi-spring-core/src/main/java/com/netifi/spring/core/BrokerClientFactorySupport.java b/netifi-spring-core/src/main/java/com/netifi/spring/core/BrokerClientFactorySupport.java new file mode 100644 index 00000000..32941d5e --- /dev/null +++ b/netifi-spring-core/src/main/java/com/netifi/spring/core/BrokerClientFactorySupport.java @@ -0,0 +1,11 @@ +package com.netifi.spring.core; + +import com.netifi.common.tags.Tags; +import com.netifi.spring.core.annotation.BrokerClient; + +public interface BrokerClientFactorySupport { + + boolean support(Class clazz); + + T lookup(Class tClass, BrokerClient.Type type, String group, Tags tag); +} diff --git a/netifi-spring-core/src/main/java/com/netifi/spring/core/DestinationAwareClientFactory.java b/netifi-spring-core/src/main/java/com/netifi/spring/core/DestinationAwareClientFactory.java index f6adbe86..eb206409 100644 --- a/netifi-spring-core/src/main/java/com/netifi/spring/core/DestinationAwareClientFactory.java +++ b/netifi-spring-core/src/main/java/com/netifi/spring/core/DestinationAwareClientFactory.java @@ -28,7 +28,6 @@ default T destination(String destination) { } default T destination(String destination, String group) { - return lookup( - BrokerClient.Type.DESTINATION, group, Tags.of("com.netifi.destination", destination)); + return lookup(BrokerClient.Type.DESTINATION, group, Tags.of("com.netifi.destination", destination)); } } diff --git a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BaseBrokerClientFactory.java b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BaseBrokerClientFactory.java new file mode 100644 index 00000000..76f1325f --- /dev/null +++ b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BaseBrokerClientFactory.java @@ -0,0 +1,105 @@ +package com.netifi.spring.core.annotation; + +import java.util.HashMap; +import java.util.Map; + +import com.netifi.common.tags.Tags; +import com.netifi.spring.core.BrokerClientFactory; +import com.netifi.spring.core.BrokerClientFactorySupport; +import io.micrometer.core.instrument.MeterRegistry; +import io.opentracing.Tracer; + +public class BaseBrokerClientFactory implements BrokerClientFactory { + + private final BrokerClientFactorySupport brokerClientFactorySupport; + private final BrokerClient.Type routeType; + private final String destination; + private final Class clientClass; + private final String group; + private final Tags tags; + private final Map instantiatedClients; + + public BaseBrokerClientFactory( + BrokerClientFactorySupport brokerClientFactorySupport, + BrokerClient.Type routeType, + String destination, + Class clientClass, + String group, + Tags tags + ) { + this.brokerClientFactorySupport = brokerClientFactorySupport; + this.routeType = routeType; + this.destination = destination; + this.clientClass = clientClass; + this.group = group; + this.tags = tags; + this.instantiatedClients = new HashMap<>(); + } + + @Override + @SuppressWarnings("unchecked") + public T lookup(BrokerClient.Type type, + String methodGroup, + Tags methodTags) { + String key = key(type, methodGroup, methodTags); + T client; + if (instantiatedClients.containsKey(key)) { + client = (T) instantiatedClients.get(key); + } + else { + try { + client = (T) brokerClientFactorySupport.lookup(clientClass, type, + methodGroup, methodTags); + instantiatedClients.put(key, client); + } + catch (Exception e) { + throw new RuntimeException(String.format( + "Error instantiating Netifi Broker Client for '%s'", + clientClass.getSimpleName()), e); + } + } + return client; + } + + @Override + public T lookup(BrokerClient.Type type, + String methodGroup, + String... methodTags) { + return lookup(type, methodGroup, Tags.of(methodTags)); + } + + @Override + public T lookup(BrokerClient.Type type) { + return lookup(type, group, tags); + } + + @Override + public T lookup(BrokerClient.Type type, Tags methodTags) { + return lookup(type, group, methodTags); + } + + @Override + public T lookup(String group, Tags tags) { + return lookup(routeType, group, tags); + } + + @Override + public T lookup(String group, String... tags) { + return lookup(routeType, group, tags); + } + + @Override + public T lookup(Tags tags) { + return lookup(routeType, tags); + } + + @Override + public T lookup() { + return lookup(routeType); + } + + //TODO: Do something smarter + private String key(BrokerClient.Type type, String group, Tags tags) { + return type.name() + group + destination + tags.hashCode(); + } +} diff --git a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClient.java b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClient.java index 481b6c98..2db47eda 100644 --- a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClient.java +++ b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClient.java @@ -1,23 +1,23 @@ -/* - * Copyright 2019 The Netifi Authors +/** + * Copyright 2019 Netifi Inc. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.netifi.spring.core.annotation; -import com.netifi.spring.core.NoClass; import com.netifi.spring.core.NoTagsSupplier; import com.netifi.spring.core.TagSupplier; + import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; @@ -25,33 +25,26 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -@Target({ - ElementType.FIELD, - ElementType.METHOD, - ElementType.PARAMETER, - ElementType.TYPE, - ElementType.ANNOTATION_TYPE -}) +@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.TYPE, + ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited public @interface BrokerClient { - Type type() default Type.GROUP; + Type type() default Type.GROUP; - String destination() default ""; + String destination() default ""; - String group() default ""; + String group() default ""; - Class clientClass() default NoClass.class; + Class clientClass() default Void.class; - Class tagSupplier() default NoTagsSupplier.class; + Class tagSupplier() default NoTagsSupplier.class; - Tag[] tags() default {}; + Tag[] tags() default {}; - enum Type { - DESTINATION, - GROUP, - BROADCAST, - } + enum Type { + DESTINATION, GROUP, BROADCAST, + } } diff --git a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClientBeanDefinitionRegistryPostProcessor.java b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClientBeanDefinitionRegistryPostProcessor.java index 967adf1b..7098472b 100644 --- a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClientBeanDefinitionRegistryPostProcessor.java +++ b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClientBeanDefinitionRegistryPostProcessor.java @@ -15,12 +15,17 @@ */ package com.netifi.spring.core.annotation; +import java.util.ArrayList; +import java.util.List; + import com.netifi.spring.core.BrokerClientFactory; +import com.netifi.spring.core.BrokerClientFactorySupport; import io.rsocket.rpc.RSocketRpcService; import io.rsocket.rpc.annotations.internal.Generated; import io.rsocket.rpc.annotations.internal.ResourceType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.beans.BeansException; import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition; import org.springframework.beans.factory.annotation.Qualifier; @@ -37,6 +42,7 @@ import org.springframework.context.annotation.ContextAnnotationAutowireCandidateResolver; import org.springframework.context.support.GenericApplicationContext; import org.springframework.core.annotation.AnnotatedElementUtils; +import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.core.type.AnnotationMetadata; import org.springframework.core.type.MethodMetadata; import org.springframework.util.ClassUtils; @@ -51,6 +57,11 @@ public class BrokerClientBeanDefinitionRegistryPostProcessor public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException { DefaultListableBeanFactory beanFactory = unwrapDefaultListableBeanFactory(registry); + List brokerClientFactories = + new ArrayList<>(beanFactory.getBeansOfType(BrokerClientFactorySupport.class) + .values()); + + AnnotationAwareOrderComparator.sort(brokerClientFactories); beanFactory.setAutowireCandidateResolver( new ContextAnnotationAutowireCandidateResolver() { @@ -72,14 +83,9 @@ public Object getSuggestedValue(DependencyDescriptor descriptor) { for (String beanName : beanNamesForType) { BeanDefinition beanDefinition = beanFactory.getMergedBeanDefinition(beanName); - if (isAutowireCandidate( - new BeanDefinitionHolder(beanDefinition, beanName), descriptor)) { - try { - return BrokerClientStaticFactory.getBeanInstance( - beanFactory, resolveClass(beanDefinition), annotation); - } catch (ClassNotFoundException e) { - LOGGER.error("Error during post processing of @Generated Netifi beans", e); - } + if (isAutowireCandidate(new BeanDefinitionHolder(beanDefinition, beanName), descriptor)) { + return BrokerClientStaticFactory.getBeanInstance( + beanFactory, descriptor.getResolvableType(), annotation, brokerClientFactories); } } @@ -88,7 +94,7 @@ public Object getSuggestedValue(DependencyDescriptor descriptor) { if ((generated != null && generated.type() == ResourceType.CLIENT) || BrokerClientFactory.class.isAssignableFrom(descriptor.getDeclaredType())) { return BrokerClientStaticFactory.getBeanInstance( - beanFactory, descriptor.getDeclaredType(), annotation); + beanFactory, descriptor.getResolvableType(), annotation, brokerClientFactories); } } diff --git a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClientStaticFactory.java b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClientStaticFactory.java index c08bf51b..5c50c7b1 100644 --- a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClientStaticFactory.java +++ b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClientStaticFactory.java @@ -1,39 +1,40 @@ -/* - * Copyright 2019 The Netifi Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/** + * Copyright 2019 Netifi Inc. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ + package com.netifi.spring.core.annotation; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.Collection; + import com.netifi.broker.rsocket.BrokerSocket; import com.netifi.common.tags.Tags; import com.netifi.spring.core.BroadcastAwareClientFactory; -import com.netifi.spring.core.BrokerClientFactory; +import com.netifi.spring.core.BrokerClientFactorySupport; import com.netifi.spring.core.DestinationAwareClientFactory; import com.netifi.spring.core.GroupAwareClientFactory; -import com.netifi.spring.core.NoClass; import com.netifi.spring.core.NoTagsSupplier; +import com.netifi.spring.core.BrokerClientFactory; import com.netifi.spring.core.TagSupplier; import io.micrometer.core.instrument.MeterRegistry; import io.opentracing.Tracer; import io.rsocket.RSocket; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.util.HashMap; -import java.util.Map; -import java.util.function.Supplier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.config.AutowireCapableBeanFactory; @@ -48,360 +49,309 @@ */ public class BrokerClientStaticFactory { - private static final Logger LOGGER = LoggerFactory.getLogger(BrokerClientStaticFactory.class); - - /** - * Creates an instance of the correct Netifi Broker client for injection into a annotated field. - * - * @return an instance of a {@link com.netifi.broker.BrokerClient} client - */ - public static Object getBeanInstance( - final DefaultListableBeanFactory beanFactory, - final Class targetClass, - final BrokerClient brokerClientAnnotation) { - final String beanName = getBeanName(brokerClientAnnotation, targetClass); - - if (!beanFactory.containsBean(beanName)) { - com.netifi.broker.BrokerClient brokerClient = - beanFactory.getBean(com.netifi.broker.BrokerClient.class); - - // Tags reconciliation - TagSupplier tagSupplier = NoTagsSupplier.INSTANCE; - if (brokerClientAnnotation.tagSupplier() != null - && !brokerClientAnnotation.tagSupplier().equals(NoTagsSupplier.class)) { - tagSupplier = beanFactory.getBean(brokerClientAnnotation.tagSupplier()); - } - - Tags suppliedTags = tagSupplier.get(); - for (Tag t : brokerClientAnnotation.tags()) { - if (!suppliedTags.stream().anyMatch(tag -> tag.getKey().equals(t.name()))) { - suppliedTags = suppliedTags.and(com.netifi.common.tags.Tag.of(t.name(), t.value())); + private static final Logger LOGGER = + LoggerFactory.getLogger(BrokerClientStaticFactory.class); + + /** + * Creates an instance of the correct Netifi Broker client for injection into a + * annotated field. + * + * @return an instance of a {@link com.netifi.broker.BrokerClient} client + */ + public static Object getBeanInstance(final DefaultListableBeanFactory beanFactory, + final ResolvableType targetClass, + final BrokerClient brokerClientAnnotation, + final Collection brokerClientFactories + ) { + final Class resolvedTargetClass = targetClass.toClass(); + final String beanName = getBeanName(brokerClientAnnotation, resolvedTargetClass); + + if (!beanFactory.containsBean(beanName)) { + final Tags suppliedTags = resolveTags(beanFactory, brokerClientAnnotation); + + Object toRegister = null; + try { +// String[] tracerSupplierBeanNames = +// beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics( +// Supplier.class, +// Tracer.class)); +// String[] meterRegistrySupplierBeanNames = +// beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics( +// Supplier.class, +// MeterRegistry.class)); +// +// Tracer tracer = null; +// MeterRegistry meterRegistry = null; +// +// // Tracers +// if (tracerSupplierBeanNames.length >= 1) { +// if (tracerSupplierBeanNames.length > 1) { +// LOGGER.warn( +// "More than one implementation of Tracer detected on the classpath. Arbitrarily choosing one to use."); +// } +// +// Supplier tracerSupplier = +// (Supplier) beanFactory.getBean(tracerSupplierBeanNames[0]); +// tracer = tracerSupplier.get(); +// } +// +// // Meter Registries +// if (meterRegistrySupplierBeanNames.length >= 1) { +// if (meterRegistrySupplierBeanNames.length > 1) { +// LOGGER.warn( +// "More than one implementation of MeterRegistry detected on the classpath. Arbitrarily choosing one to use."); +// } +// +// Supplier meterRegistrySupplier = +// (Supplier) beanFactory.getBean( +// meterRegistrySupplierBeanNames[0]); +// meterRegistry = meterRegistrySupplier.get(); +// } +// else { +// // Fallback to MeterRegistry implementations on the classpath if we can't find any suppliers +// Map meterRegistryBeans = +// beanFactory.getBeansOfType(MeterRegistry.class); +// +// if (!meterRegistryBeans.isEmpty()) { +// if (meterRegistryBeans.size() > 1) { +// LOGGER.warn( +// "More than one implementation of MeterRegistry detected on the classpath. Arbitrarily choosing one to use."); +// } +// +// meterRegistry = (MeterRegistry) meterRegistryBeans.values() +// .toArray()[0]; +// } +// } + + if (BrokerClientFactory.class.isAssignableFrom(resolvedTargetClass)) { + Class clientClass = brokerClientAnnotation.clientClass(); + + if (clientClass.equals(Void.class)) { + ResolvableType clientResolvableType = targetClass.getGeneric(0); + + if (clientResolvableType == ResolvableType.NONE) { + throw new RuntimeException( + "Instantiating BrokerClientFactory requires target client class"); + } + + clientClass = clientResolvableType.toClass(); + } + + for (BrokerClientFactorySupport brokerClientFactory : + brokerClientFactories) { + if (brokerClientFactory.support(clientClass)) { + toRegister = createBrokerClientFactory( + clientClass, + resolvedTargetClass, + brokerClientFactory, + brokerClientAnnotation.type(), + brokerClientAnnotation.group(), + brokerClientAnnotation.destination(), + suppliedTags + ); + } + } + } + else { + for (BrokerClientFactorySupport brokerClientFactory : brokerClientFactories) { + if (brokerClientFactory.support(resolvedTargetClass)) { + toRegister = + brokerClientFactory.lookup( + resolvedTargetClass, + brokerClientAnnotation.type(), + brokerClientAnnotation.group(), + suppliedTags + ); + break; + } + } + } + } + catch (Exception e) { + throw new RuntimeException(String.format("Error injecting bean '%s'", targetClass), e); + } + + if (toRegister == null) { + throw new RuntimeException(String.format("Unsupported bean '%s'", targetClass)); + } + + Object newInstance = beanFactory.initializeBean(toRegister, beanName); + beanFactory.autowireBeanProperties(newInstance, + AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, + true); + AnnotatedGenericBeanDefinition beanDefinition = + new AnnotatedGenericBeanDefinition(resolvedTargetClass); + AutowireCandidateQualifier qualifier = + new AutowireCandidateQualifier(Qualifier.class); + + qualifier.setAttribute("value", "client"); + beanDefinition.addQualifier(qualifier); + + beanFactory.registerBeanDefinition(beanName, beanDefinition); + beanFactory.registerSingleton(beanName, newInstance); + + LOGGER.debug("Bean named '{}' created successfully.", beanName); + + return newInstance; } - } - - Object toRegister = null; - try { - String[] tracerSupplierBeanNames = - beanFactory.getBeanNamesForType( - ResolvableType.forClassWithGenerics(Supplier.class, Tracer.class)); - String[] meterRegistrySupplierBeanNames = - beanFactory.getBeanNamesForType( - ResolvableType.forClassWithGenerics(Supplier.class, MeterRegistry.class)); - - Tracer tracer = null; - MeterRegistry meterRegistry = null; - - // Tracers - if (tracerSupplierBeanNames.length >= 1) { - if (tracerSupplierBeanNames.length > 1) { - LOGGER.warn( - "More than one implementation of Tracer detected on the classpath. Arbitrarily choosing one to use."); - } - - Supplier tracerSupplier = - (Supplier) beanFactory.getBean(tracerSupplierBeanNames[0]); - tracer = tracerSupplier.get(); + else { + LOGGER.debug( + "Bean named '{}' already exists, using as current bean reference.", + beanName); + return beanFactory.getBean(beanName); } + } - // Meter Registries - if (meterRegistrySupplierBeanNames.length >= 1) { - if (meterRegistrySupplierBeanNames.length > 1) { - LOGGER.warn( - "More than one implementation of MeterRegistry detected on the classpath. Arbitrarily choosing one to use."); - } - - Supplier meterRegistrySupplier = - (Supplier) beanFactory.getBean(meterRegistrySupplierBeanNames[0]); - meterRegistry = meterRegistrySupplier.get(); - } else { - // Fallback to MeterRegistry implementations on the classpath if we can't find any - // suppliers - Map meterRegistryBeans = - beanFactory.getBeansOfType(MeterRegistry.class); - - if (!meterRegistryBeans.isEmpty()) { - if (meterRegistryBeans.size() > 1) { - LOGGER.warn( - "More than one implementation of MeterRegistry detected on the classpath. Arbitrarily choosing one to use."); - } + public static Tags resolveTags( + DefaultListableBeanFactory beanFactory, + BrokerClient brokerClientAnnotation) { + //Tags reconciliation + TagSupplier tagSupplier = NoTagsSupplier.INSTANCE; + brokerClientAnnotation.tagSupplier(); + if (!brokerClientAnnotation.tagSupplier() + .equals(NoTagsSupplier.class)) { + tagSupplier = beanFactory.getBean(brokerClientAnnotation.tagSupplier()); + } - meterRegistry = (MeterRegistry) meterRegistryBeans.values().toArray()[0]; - } + Tags suppliedTags = tagSupplier.get(); + for (Tag t : brokerClientAnnotation.tags()) { + if (!suppliedTags.stream() + .anyMatch(tag -> tag.getKey() + .equals(t.name()))) { + suppliedTags = + suppliedTags.and(com.netifi.common.tags.Tag.of(t.name(), + t.value())); + } } + return suppliedTags; + } - Class clientClass = brokerClientAnnotation.clientClass(); - if (BrokerClientFactory.class.isAssignableFrom(targetClass)) { - - if (clientClass.equals(NoClass.class)) { - throw new RuntimeException( - "Instantiating BrokerClientFactory requires target client class"); - } - - BrokerClientFactory baseFactory = - createBaseClientFactory( - clientClass, - brokerClient, - brokerClientAnnotation.type(), - brokerClientAnnotation.group(), - brokerClientAnnotation.destination(), - suppliedTags, - tracer, - meterRegistry); - - // TODO: Lots of duplication here but I don't know how else to do this - if (targetClass.isAssignableFrom(GroupAwareClientFactory.class)) { - toRegister = - new GroupAwareClientFactory() { - @Override - public Object lookup(BrokerClient.Type type, String group, Tags tags) { - return baseFactory.lookup(type, group, tags); - } - - @Override - public Object lookup(BrokerClient.Type type, String group, String... tags) { - return baseFactory.lookup(type, group, tags); - } - - @Override - public Object lookup(BrokerClient.Type type) { - return baseFactory.lookup(type); - } - - @Override - public Object lookup(BrokerClient.Type type, Tags tags) { - return baseFactory.lookup(type, tags); - } - }; - } else if (targetClass.isAssignableFrom(DestinationAwareClientFactory.class)) { - toRegister = - new DestinationAwareClientFactory() { - @Override - public Object lookup(BrokerClient.Type type, String group, Tags tags) { - return baseFactory.lookup(type, group, tags); - } - - @Override - public Object lookup(BrokerClient.Type type, String group, String... tags) { - return baseFactory.lookup(type, group, tags); - } - - @Override - public Object lookup(BrokerClient.Type type) { - return baseFactory.lookup(type); - } - - @Override - public Object lookup(BrokerClient.Type type, Tags tags) { - return baseFactory.lookup(type, tags); - } - }; - } else if (targetClass.isAssignableFrom(BroadcastAwareClientFactory.class)) { - toRegister = - new BroadcastAwareClientFactory() { - @Override - public Object lookup(BrokerClient.Type type, String group, Tags tags) { - return baseFactory.lookup(type, group, tags); - } - - @Override - public Object lookup(BrokerClient.Type type, String group, String... tags) { - return baseFactory.lookup(type, group, tags); - } - - @Override - public Object lookup(BrokerClient.Type type) { - return baseFactory.lookup(type); - } - - @Override - public Object lookup(BrokerClient.Type type, Tags tags) { - return baseFactory.lookup(type, tags); - } - }; - } else { - toRegister = baseFactory; - } - - } else { - toRegister = - createBrokerClient( - brokerClient, - brokerClientAnnotation.type(), - brokerClientAnnotation.group(), - brokerClientAnnotation.destination(), - suppliedTags, - tracer, - meterRegistry, - targetClass); + /** + * Generates a unique bean name for the field. + * + * @param brokerClientAnnotation annotation data + * @param clazz target class + * @return bean name + */ + private static String getBeanName(BrokerClient brokerClientAnnotation, + Class clazz) { + Assert.hasText(brokerClientAnnotation.group(), + "@BrokerClient.group() must be specified"); + + String beanName = clazz.getSimpleName() + "_" + brokerClientAnnotation + .type() + .toString() + .toLowerCase() + "_" + brokerClientAnnotation.group(); + + if (!StringUtils.isEmpty(brokerClientAnnotation.destination())) { + beanName += "_" + brokerClientAnnotation.destination(); } - } catch (Exception e) { - throw new RuntimeException( - String.format("Error injecting bean '%s'", targetClass.getSimpleName()), e); - } - - Object newInstance = beanFactory.initializeBean(toRegister, beanName); - beanFactory.autowireBeanProperties( - newInstance, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, true); - AnnotatedGenericBeanDefinition beanDefinition = - new AnnotatedGenericBeanDefinition(targetClass); - AutowireCandidateQualifier qualifier = new AutowireCandidateQualifier(Qualifier.class); - - qualifier.setAttribute("value", "client"); - beanDefinition.addQualifier(qualifier); - - beanFactory.registerBeanDefinition(beanName, beanDefinition); - beanFactory.registerSingleton(beanName, newInstance); - - LOGGER.debug("Bean named '{}' created successfully.", beanName); - - return newInstance; - } else { - LOGGER.debug("Bean named '{}' already exists, using as current bean reference.", beanName); - return beanFactory.getBean(beanName); + + return beanName; } - } - - /** - * Generates a unique bean name for the field. - * - * @param brokerClientAnnotation annotation data - * @param clazz target class - * @return bean name - */ - private static String getBeanName(BrokerClient brokerClientAnnotation, Class clazz) { - Assert.hasText(brokerClientAnnotation.group(), "@BrokerClient.group() must be specified"); - - String beanName = - clazz.getSimpleName() - + "_" - + brokerClientAnnotation.type().toString().toLowerCase() - + "_" - + brokerClientAnnotation.group(); - - if (!StringUtils.isEmpty(brokerClientAnnotation.destination())) { - beanName += "_" + brokerClientAnnotation.destination(); + + static T createBrokerClient(com.netifi.broker.BrokerClient brokerClient, + BrokerClient.Type routeType, + String group, + String destination, + Tags tags, + Tracer tracer, + MeterRegistry meterRegistry, + Class clientClass) + throws NoSuchMethodException, InstantiationException, IllegalAccessException, + InvocationTargetException { + // Creating default BrokerSocket Instance + BrokerSocket brokerSocket = createBrokerRSocket(brokerClient, routeType, group, destination, tags); + + T toRegister; + + if (tracer == null && meterRegistry == null) { + // No Tracer or MeterRegistry + Constructor ctor = clientClass.getConstructor(RSocket.class); + toRegister = (T) ctor.newInstance(brokerSocket); + } + else if (tracer != null && meterRegistry == null) { + // Tracer Only + Constructor ctor = clientClass.getConstructor(RSocket.class, Tracer.class); + toRegister = (T) ctor.newInstance(brokerSocket, tracer); + } + else if (tracer == null && meterRegistry != null) { + // MeterRegistry Only + Constructor ctor = + clientClass.getConstructor(RSocket.class, MeterRegistry.class); + toRegister = (T) ctor.newInstance(brokerSocket, meterRegistry); + } + else { + // Both Tracer and MeterRegistry + Constructor ctor = clientClass.getConstructor( + RSocket.class, + MeterRegistry.class, + Tracer.class + ); + toRegister = (T) ctor.newInstance(brokerSocket, meterRegistry, tracer); + } + return toRegister; } - return beanName; - } - - private static T createBrokerClient( - com.netifi.broker.BrokerClient brokerClient, - BrokerClient.Type routeType, - String group, - String destination, - Tags tags, - Tracer tracer, - MeterRegistry meterRegistry, - Class clientClass) - throws NoSuchMethodException, InstantiationException, IllegalAccessException, - InvocationTargetException { - // Creating default BrokerSocket Instance - BrokerSocket brokerSocket = null; - - switch (routeType) { - case BROADCAST: - brokerSocket = brokerClient.broadcastServiceSocket(group, tags); - break; - case GROUP: - brokerSocket = brokerClient.groupServiceSocket(group, tags); - break; - case DESTINATION: - brokerSocket = - brokerClient.groupServiceSocket( - group, tags.and(Tags.of("com.netifi.destination", destination))); - break; + public static BrokerSocket createBrokerRSocket( + com.netifi.broker.BrokerClient brokerClient, + BrokerClient.Type routeType, + String group, + String destination, + Tags tags + ) { + BrokerSocket brokerSocket = null; + + switch (routeType) { + case BROADCAST: + brokerSocket = brokerClient.broadcastServiceSocket(group, tags); + break; + case GROUP: + brokerSocket = brokerClient.groupServiceSocket(group, tags); + break; + case DESTINATION: + brokerSocket = brokerClient.groupServiceSocket( + group, + StringUtils.isEmpty(destination) + ? tags + : Tags.of("com.netifi.destination", destination) + .and(tags) + ); + break; + } + return brokerSocket; } - T toRegister; - - if (tracer == null && meterRegistry == null) { - // No Tracer or MeterRegistry - Constructor ctor = clientClass.getConstructor(RSocket.class); - toRegister = (T) ctor.newInstance(brokerSocket); - } else if (tracer != null && meterRegistry == null) { - // Tracer Only - Constructor ctor = clientClass.getConstructor(RSocket.class, Tracer.class); - toRegister = (T) ctor.newInstance(brokerSocket, tracer); - } else if (tracer == null && meterRegistry != null) { - // MeterRegistry Only - Constructor ctor = clientClass.getConstructor(RSocket.class, MeterRegistry.class); - toRegister = (T) ctor.newInstance(brokerSocket, meterRegistry); - } else { - // Both Tracer and MeterRegistry - Constructor ctor = - clientClass.getConstructor(RSocket.class, MeterRegistry.class, Tracer.class); - toRegister = (T) ctor.newInstance(brokerSocket, meterRegistry, tracer); + public static BrokerClientFactory createBrokerClientFactory( + Class clientClass, + Class targetClass, + BrokerClientFactorySupport brokerClientFactorySupport, + BrokerClient.Type routeType, + String group, + String destination, + Tags tags + ) { + + final BaseBrokerClientFactory brokerClientFactory = + new BaseBrokerClientFactory<>( + brokerClientFactorySupport, + routeType, + destination, + clientClass, + group, + tags + ); + + if (targetClass.isAssignableFrom(GroupAwareClientFactory.class)) { + return new DefaultGroupAwareClientFactory<>(brokerClientFactory); + } + else if (targetClass.isAssignableFrom(DestinationAwareClientFactory.class)) { + return new DefaultDestinationAwareClientFactory<>(brokerClientFactory); + } + else if (targetClass.isAssignableFrom(BroadcastAwareClientFactory.class)) { + return new DefaultBroadcastAwareClientFactory<>(brokerClientFactory); + } + + return brokerClientFactory; } - return toRegister; - } - - private static BrokerClientFactory createBaseClientFactory( - Class clientClass, - com.netifi.broker.BrokerClient brokerClient, - BrokerClient.Type routeType, - String group, - String destination, - Tags tags, - Tracer tracer, - MeterRegistry meterRegistry) { - - BrokerClientFactory baseFactory = - new BrokerClientFactory() { - - Map instantiatedClients = new HashMap<>(); - - @Override - public Object lookup(BrokerClient.Type type, String methodGroup, Tags methodTags) { - String key = key(type, methodGroup, methodTags); - Object client = null; - if (instantiatedClients.containsKey(key)) { - client = instantiatedClients.get(key); - } else { - try { - client = - createBrokerClient( - brokerClient, - routeType, - methodGroup, - destination, - methodTags, - tracer, - meterRegistry, - clientClass); - instantiatedClients.put(key, client); - } catch (Exception e) { - throw new RuntimeException( - String.format( - "Error instantiating Netifi Broker Client for '%s'", - clientClass.getSimpleName()), - e); - } - } - return client; - } - - @Override - public Object lookup(BrokerClient.Type type, String methodGroup, String... methodTags) { - return lookup(type, methodGroup, Tags.of(methodTags)); - } - - @Override - public Object lookup(BrokerClient.Type type) { - return lookup(type, group, tags); - } - - @Override - public Object lookup(BrokerClient.Type type, Tags methodTags) { - return lookup(type, group, methodTags); - } - - // TODO: Do something smarter - private String key(BrokerClient.Type type, String group, Tags tags) { - return type.name() + group + destination + tags.hashCode(); - } - }; - - return baseFactory; - } } diff --git a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/DefaultBroadcastAwareClientFactory.java b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/DefaultBroadcastAwareClientFactory.java new file mode 100644 index 00000000..ab87a451 --- /dev/null +++ b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/DefaultBroadcastAwareClientFactory.java @@ -0,0 +1,59 @@ +package com.netifi.spring.core.annotation; + +import com.netifi.common.tags.Tags; +import com.netifi.spring.core.BroadcastAwareClientFactory; +import com.netifi.spring.core.BrokerClientFactory; + +class DefaultBroadcastAwareClientFactory + implements BroadcastAwareClientFactory { + + private final BrokerClientFactory baseFactory; + + DefaultBroadcastAwareClientFactory(BrokerClientFactory factory) { + baseFactory = factory; + } + + @Override + public T lookup(BrokerClient.Type type, + String group, + Tags tags) { + return baseFactory.lookup(type, group, tags); + } + + @Override + public T lookup(BrokerClient.Type type, + String group, + String... tags) { + return baseFactory.lookup(type, group, tags); + } + + @Override + public T lookup(BrokerClient.Type type) { + return baseFactory.lookup(type); + } + + @Override + public T lookup(BrokerClient.Type type, Tags tags) { + return baseFactory.lookup(type, tags); + } + + @Override + public T lookup(String group, Tags tag) { + return baseFactory.lookup(group, tag); + } + + @Override + public T lookup(String group, String... tags) { + return baseFactory.lookup(group, tags); + } + + @Override + public T lookup(Tags tags) { + return baseFactory.lookup(tags); + } + + @Override + public T lookup() { + return baseFactory.lookup(); + } +} diff --git a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/DefaultDestinationAwareClientFactory.java b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/DefaultDestinationAwareClientFactory.java new file mode 100644 index 00000000..cfd7c514 --- /dev/null +++ b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/DefaultDestinationAwareClientFactory.java @@ -0,0 +1,59 @@ +package com.netifi.spring.core.annotation; + +import com.netifi.common.tags.Tags; +import com.netifi.spring.core.BrokerClientFactory; +import com.netifi.spring.core.DestinationAwareClientFactory; + +class DefaultDestinationAwareClientFactory + implements DestinationAwareClientFactory { + + private final BrokerClientFactory baseFactory; + + DefaultDestinationAwareClientFactory(BrokerClientFactory factory) { + baseFactory = factory; + } + + @Override + public T lookup(BrokerClient.Type type, + String group, + Tags tags) { + return baseFactory.lookup(type, group, tags); + } + + @Override + public T lookup(BrokerClient.Type type, + String group, + String... tags) { + return baseFactory.lookup(type, group, tags); + } + + @Override + public T lookup(BrokerClient.Type type) { + return baseFactory.lookup(type); + } + + @Override + public T lookup(BrokerClient.Type type, Tags tags) { + return baseFactory.lookup(type, tags); + } + + @Override + public T lookup(String group, Tags tag) { + return baseFactory.lookup(group, tag); + } + + @Override + public T lookup(String group, String... tags) { + return baseFactory.lookup(group, tags); + } + + @Override + public T lookup(Tags tags) { + return baseFactory.lookup(tags); + } + + @Override + public T lookup() { + return baseFactory.lookup(); + } +} diff --git a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/DefaultGroupAwareClientFactory.java b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/DefaultGroupAwareClientFactory.java new file mode 100644 index 00000000..1619944a --- /dev/null +++ b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/DefaultGroupAwareClientFactory.java @@ -0,0 +1,59 @@ +package com.netifi.spring.core.annotation; + +import com.netifi.common.tags.Tags; +import com.netifi.spring.core.BrokerClientFactory; +import com.netifi.spring.core.GroupAwareClientFactory; + +public class DefaultGroupAwareClientFactory + implements GroupAwareClientFactory { + + private final BrokerClientFactory baseFactory; + + DefaultGroupAwareClientFactory(BrokerClientFactory factory) { + baseFactory = factory; + } + + @Override + public T lookup(BrokerClient.Type type, + String group, + Tags tags) { + return baseFactory.lookup(type, group, tags); + } + + @Override + public T lookup(BrokerClient.Type type, + String group, + String... tags) { + return baseFactory.lookup(type, group, tags); + } + + @Override + public T lookup(BrokerClient.Type type) { + return baseFactory.lookup(type); + } + + @Override + public T lookup(BrokerClient.Type type, Tags tags) { + return baseFactory.lookup(type, tags); + } + + @Override + public T lookup(String group, Tags tag) { + return baseFactory.lookup(group, tag); + } + + @Override + public T lookup(String group, String... tags) { + return baseFactory.lookup(group, tags); + } + + @Override + public T lookup(Tags tags) { + return baseFactory.lookup(tags); + } + + @Override + public T lookup() { + return baseFactory.lookup(); + } +} diff --git a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/RpcBrokerClientFactorySupport.java b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/RpcBrokerClientFactorySupport.java new file mode 100644 index 00000000..07edf790 --- /dev/null +++ b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/RpcBrokerClientFactorySupport.java @@ -0,0 +1,48 @@ +package com.netifi.spring.core.annotation; + +import com.netifi.common.tags.Tags; +import com.netifi.spring.core.BrokerClientFactorySupport; +import io.micrometer.core.instrument.MeterRegistry; +import io.opentracing.Tracer; + +public class RpcBrokerClientFactorySupport implements BrokerClientFactorySupport { + + private final com.netifi.broker.BrokerClient brokerClient; + private final Tracer tracer; + private final MeterRegistry meterRegistry; + + public RpcBrokerClientFactorySupport(com.netifi.broker.BrokerClient client, + MeterRegistry registry, + Tracer tracer) { + brokerClient = client; + this.tracer = tracer; + meterRegistry = registry; + } + + @Override + public boolean support(Class clazz) { + return true; + } + + @Override + public T lookup(Class clientClass, BrokerClient.Type type, String group, Tags tag) { + try { + return BrokerClientStaticFactory + .createBrokerClient( + brokerClient, + type, + group, + null, + tag, + tracer, + meterRegistry, + clientClass + ); + } + catch (Exception e) { + throw new RuntimeException(String.format( + "Error instantiating Netifi Broker Client for '%s'", + clientClass.getSimpleName()), e); + } + } +} diff --git a/netifi-spring-core/src/main/java/com/netifi/spring/core/config/BrokerClientConfiguration.java b/netifi-spring-core/src/main/java/com/netifi/spring/core/config/BrokerClientConfiguration.java index 66ad79be..65ed3f9a 100644 --- a/netifi-spring-core/src/main/java/com/netifi/spring/core/config/BrokerClientConfiguration.java +++ b/netifi-spring-core/src/main/java/com/netifi/spring/core/config/BrokerClientConfiguration.java @@ -20,7 +20,9 @@ import com.netifi.broker.info.BrokerInfoServiceClient; import com.netifi.broker.info.BrokerInfoServiceServer; import com.netifi.spring.core.BrokerClientApplicationEventListener; +import com.netifi.spring.core.annotation.BaseBrokerClientFactory; import com.netifi.spring.core.annotation.BrokerClientBeanDefinitionRegistryPostProcessor; +import com.netifi.spring.core.annotation.RpcBrokerClientFactorySupport; import io.micrometer.core.instrument.MeterRegistry; import io.opentracing.Tracer; import io.rsocket.ipc.MetadataDecoder; @@ -39,6 +41,14 @@ @Configuration public class BrokerClientConfiguration implements ApplicationContextAware { + @Bean + public RpcBrokerClientFactorySupport rpcBrokerClientFactorySupport( + BrokerClient brokerClient, + Optional registry, + Optional tracer) { + return new RpcBrokerClientFactorySupport(brokerClient, registry.orElse(null), tracer.orElse(null)); + } + @Bean(name = "internalBrokerClientBeanDefinitionRegistryPostProcessor") public BrokerClientBeanDefinitionRegistryPostProcessor brokerClientBeanDefinitionRegistryPostProcessor() { diff --git a/netifi-spring-messaging/build.gradle b/netifi-spring-messaging/build.gradle new file mode 100644 index 00000000..94254f9b --- /dev/null +++ b/netifi-spring-messaging/build.gradle @@ -0,0 +1,36 @@ +plugins { + id 'io.spring.dependency-management' +} + +description = 'Netifi Spring Core' + +dependencyManagement { + imports { + mavenBom "org.springframework.boot:spring-boot-dependencies:${springBootDependenciesVersion}" + } +} + +dependencies { + implementation project(":netifi-spring-core") + + implementation "com.netifi:netifi-common" + implementation "com.netifi:netifi-broker-client" + implementation 'org.slf4j:slf4j-api' + implementation 'org.springframework:spring-core' + implementation 'org.springframework:spring-context' + implementation 'javax.validation:validation-api' + + compileClasspath 'org.springframework:spring-messaging' + + testImplementation 'org.springframework:spring-test' + testImplementation 'org.mockito:mockito-core' + testImplementation 'org.junit.jupiter:junit-jupiter-api' + testImplementation 'org.junit.jupiter:junit-jupiter-engine' +} + +test { + testLogging { + events "passed", "skipped", "failed" + } + useJUnitPlatform() +} \ No newline at end of file diff --git a/netifi-spring-messaging/gradle/dependency-locks/annotationProcessor.lockfile b/netifi-spring-messaging/gradle/dependency-locks/annotationProcessor.lockfile new file mode 100644 index 00000000..656c5dbc --- /dev/null +++ b/netifi-spring-messaging/gradle/dependency-locks/annotationProcessor.lockfile @@ -0,0 +1,3 @@ +# This is a Gradle generated file for dependency locking. +# Manual edits can break the build and are not advised. +# This file is expected to be part of source control. diff --git a/netifi-spring-messaging/gradle/dependency-locks/compileClasspath.lockfile b/netifi-spring-messaging/gradle/dependency-locks/compileClasspath.lockfile new file mode 100644 index 00000000..641efe79 --- /dev/null +++ b/netifi-spring-messaging/gradle/dependency-locks/compileClasspath.lockfile @@ -0,0 +1,39 @@ +# This is a Gradle generated file for dependency locking. +# Manual edits can break the build and are not advised. +# This file is expected to be part of source control. +com.google.protobuf:protobuf-java:3.6.1 +com.typesafe:config:1.3.3 +io.micrometer:micrometer-core:1.0.6 +io.netty:netty-buffer:4.1.34.Final +io.netty:netty-codec-http2:4.1.34.Final +io.netty:netty-codec-http:4.1.34.Final +io.netty:netty-codec-socks:4.1.34.Final +io.netty:netty-codec:4.1.34.Final +io.netty:netty-common:4.1.34.Final +io.netty:netty-handler-proxy:4.1.34.Final +io.netty:netty-handler:4.1.34.Final +io.netty:netty-resolver:4.1.34.Final +io.netty:netty-tcnative:2.0.18.Final +io.netty:netty-transport-native-epoll:4.1.34.Final +io.netty:netty-transport-native-unix-common:4.1.34.Final +io.netty:netty-transport:4.1.34.Final +io.opentracing:opentracing-api:0.31.0 +io.projectreactor.netty:reactor-netty:0.9.0.BUILD-SNAPSHOT +io.projectreactor:reactor-core:3.3.0.BUILD-SNAPSHOT +io.rsocket.rpc:rsocket-rpc-core:0.2.13.3 +io.rsocket:rsocket-core:0.11.17.2 +io.rsocket:rsocket-transport-netty:0.11.17.2 +javax.annotation:javax.annotation-api:1.3.2 +javax.inject:javax.inject:1 +javax.validation:validation-api:2.0.1.Final +org.hdrhistogram:HdrHistogram:2.1.10 +org.latencyutils:LatencyUtils:2.0.3 +org.reactivestreams:reactive-streams:1.0.2 +org.slf4j:slf4j-api:1.7.25 +org.springframework:spring-aop:5.2.0.BUILD-SNAPSHOT +org.springframework:spring-beans:5.2.0.BUILD-SNAPSHOT +org.springframework:spring-context:5.2.0.BUILD-SNAPSHOT +org.springframework:spring-core:5.2.0.BUILD-SNAPSHOT +org.springframework:spring-expression:5.2.0.BUILD-SNAPSHOT +org.springframework:spring-jcl:5.2.0.BUILD-SNAPSHOT +org.springframework:spring-messaging:5.2.0.BUILD-SNAPSHOT diff --git a/netifi-spring-messaging/gradle/dependency-locks/googleJavaFormat1.6.lockfile b/netifi-spring-messaging/gradle/dependency-locks/googleJavaFormat1.6.lockfile new file mode 100644 index 00000000..a02de22c --- /dev/null +++ b/netifi-spring-messaging/gradle/dependency-locks/googleJavaFormat1.6.lockfile @@ -0,0 +1,13 @@ +# This is a Gradle generated file for dependency locking. +# Manual edits can break the build and are not advised. +# This file is expected to be part of source control. +com.google.code.findbugs:jsr305:3.0.2 +com.google.errorprone:error_prone_annotations:2.2.0 +com.google.errorprone:javac-shaded:9+181-r4173-1 +com.google.googlejavaformat:google-java-format:1.6 +com.google.guava:failureaccess:1.0.1 +com.google.guava:guava:27.0.1-jre +com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava +com.google.j2objc:j2objc-annotations:1.1 +org.checkerframework:checker-qual:2.5.2 +org.codehaus.mojo:animal-sniffer-annotations:1.17 diff --git a/netifi-spring-messaging/gradle/dependency-locks/testAnnotationProcessor.lockfile b/netifi-spring-messaging/gradle/dependency-locks/testAnnotationProcessor.lockfile new file mode 100644 index 00000000..656c5dbc --- /dev/null +++ b/netifi-spring-messaging/gradle/dependency-locks/testAnnotationProcessor.lockfile @@ -0,0 +1,3 @@ +# This is a Gradle generated file for dependency locking. +# Manual edits can break the build and are not advised. +# This file is expected to be part of source control. diff --git a/netifi-spring-messaging/gradle/dependency-locks/testCompileClasspath.lockfile b/netifi-spring-messaging/gradle/dependency-locks/testCompileClasspath.lockfile new file mode 100644 index 00000000..8a6e51b5 --- /dev/null +++ b/netifi-spring-messaging/gradle/dependency-locks/testCompileClasspath.lockfile @@ -0,0 +1,49 @@ +# This is a Gradle generated file for dependency locking. +# Manual edits can break the build and are not advised. +# This file is expected to be part of source control. +com.google.protobuf:protobuf-java:3.6.1 +com.typesafe:config:1.3.3 +io.micrometer:micrometer-core:1.0.6 +io.netty:netty-buffer:4.1.33.Final +io.netty:netty-codec-http2:4.1.33.Final +io.netty:netty-codec-http:4.1.33.Final +io.netty:netty-codec-socks:4.1.33.Final +io.netty:netty-codec:4.1.33.Final +io.netty:netty-common:4.1.33.Final +io.netty:netty-handler-proxy:4.1.33.Final +io.netty:netty-handler:4.1.33.Final +io.netty:netty-resolver:4.1.33.Final +io.netty:netty-tcnative:2.0.18.Final +io.netty:netty-transport-native-epoll:4.1.33.Final +io.netty:netty-transport-native-unix-common:4.1.33.Final +io.netty:netty-transport:4.1.33.Final +io.opentracing:opentracing-api:0.31.0 +io.projectreactor.netty:reactor-netty:0.8.5.RELEASE +io.projectreactor:reactor-core:3.2.6.RELEASE +io.rsocket.rpc:rsocket-rpc-core:0.2.13.3 +io.rsocket:rsocket-core:0.11.17.2 +io.rsocket:rsocket-transport-netty:0.11.17.2 +javax.annotation:javax.annotation-api:1.3.2 +javax.inject:javax.inject:1 +javax.validation:validation-api:2.0.1.Final +net.bytebuddy:byte-buddy-agent:1.9.10 +net.bytebuddy:byte-buddy:1.9.10 +org.apiguardian:apiguardian-api:1.0.0 +org.hdrhistogram:HdrHistogram:2.1.10 +org.junit.jupiter:junit-jupiter-api:5.3.2 +org.junit.jupiter:junit-jupiter-engine:5.3.2 +org.junit.platform:junit-platform-commons:1.3.2 +org.junit.platform:junit-platform-engine:1.3.2 +org.latencyutils:LatencyUtils:2.0.3 +org.mockito:mockito-core:2.25.0 +org.objenesis:objenesis:2.6 +org.opentest4j:opentest4j:1.1.1 +org.reactivestreams:reactive-streams:1.0.2 +org.slf4j:slf4j-api:1.7.25 +org.springframework:spring-aop:5.1.5.RELEASE +org.springframework:spring-beans:5.1.5.RELEASE +org.springframework:spring-context:5.1.5.RELEASE +org.springframework:spring-core:5.1.5.RELEASE +org.springframework:spring-expression:5.1.5.RELEASE +org.springframework:spring-jcl:5.1.5.RELEASE +org.springframework:spring-test:5.1.5.RELEASE diff --git a/netifi-spring-messaging/gradle/dependency-locks/testRuntimeClasspath.lockfile b/netifi-spring-messaging/gradle/dependency-locks/testRuntimeClasspath.lockfile new file mode 100644 index 00000000..8a6e51b5 --- /dev/null +++ b/netifi-spring-messaging/gradle/dependency-locks/testRuntimeClasspath.lockfile @@ -0,0 +1,49 @@ +# This is a Gradle generated file for dependency locking. +# Manual edits can break the build and are not advised. +# This file is expected to be part of source control. +com.google.protobuf:protobuf-java:3.6.1 +com.typesafe:config:1.3.3 +io.micrometer:micrometer-core:1.0.6 +io.netty:netty-buffer:4.1.33.Final +io.netty:netty-codec-http2:4.1.33.Final +io.netty:netty-codec-http:4.1.33.Final +io.netty:netty-codec-socks:4.1.33.Final +io.netty:netty-codec:4.1.33.Final +io.netty:netty-common:4.1.33.Final +io.netty:netty-handler-proxy:4.1.33.Final +io.netty:netty-handler:4.1.33.Final +io.netty:netty-resolver:4.1.33.Final +io.netty:netty-tcnative:2.0.18.Final +io.netty:netty-transport-native-epoll:4.1.33.Final +io.netty:netty-transport-native-unix-common:4.1.33.Final +io.netty:netty-transport:4.1.33.Final +io.opentracing:opentracing-api:0.31.0 +io.projectreactor.netty:reactor-netty:0.8.5.RELEASE +io.projectreactor:reactor-core:3.2.6.RELEASE +io.rsocket.rpc:rsocket-rpc-core:0.2.13.3 +io.rsocket:rsocket-core:0.11.17.2 +io.rsocket:rsocket-transport-netty:0.11.17.2 +javax.annotation:javax.annotation-api:1.3.2 +javax.inject:javax.inject:1 +javax.validation:validation-api:2.0.1.Final +net.bytebuddy:byte-buddy-agent:1.9.10 +net.bytebuddy:byte-buddy:1.9.10 +org.apiguardian:apiguardian-api:1.0.0 +org.hdrhistogram:HdrHistogram:2.1.10 +org.junit.jupiter:junit-jupiter-api:5.3.2 +org.junit.jupiter:junit-jupiter-engine:5.3.2 +org.junit.platform:junit-platform-commons:1.3.2 +org.junit.platform:junit-platform-engine:1.3.2 +org.latencyutils:LatencyUtils:2.0.3 +org.mockito:mockito-core:2.25.0 +org.objenesis:objenesis:2.6 +org.opentest4j:opentest4j:1.1.1 +org.reactivestreams:reactive-streams:1.0.2 +org.slf4j:slf4j-api:1.7.25 +org.springframework:spring-aop:5.1.5.RELEASE +org.springframework:spring-beans:5.1.5.RELEASE +org.springframework:spring-context:5.1.5.RELEASE +org.springframework:spring-core:5.1.5.RELEASE +org.springframework:spring-expression:5.1.5.RELEASE +org.springframework:spring-jcl:5.1.5.RELEASE +org.springframework:spring-test:5.1.5.RELEASE diff --git a/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/BrokerClientRequesterMethodArgumentResolver.java b/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/BrokerClientRequesterMethodArgumentResolver.java new file mode 100644 index 00000000..0e7ebb85 --- /dev/null +++ b/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/BrokerClientRequesterMethodArgumentResolver.java @@ -0,0 +1,104 @@ +/* + * Copyright 2002-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.netifi.spring.messaging; + +import com.netifi.broker.BrokerClient; +import io.rsocket.RSocket; +import reactor.core.publisher.Mono; + +import org.springframework.beans.factory.support.DefaultListableBeanFactory; +import org.springframework.core.MethodParameter; +import org.springframework.messaging.Message; +import org.springframework.messaging.handler.invocation.reactive.HandlerMethodArgumentResolver; +import org.springframework.messaging.rsocket.RSocketRequester; +import org.springframework.messaging.rsocket.RSocketStrategies; +import org.springframework.util.Assert; + +import static com.netifi.spring.core.annotation.BrokerClientStaticFactory.resolveTags; +import static com.netifi.spring.messaging.RSocketRequesterStaticFactory.createRSocketRequester; +import static com.netifi.spring.messaging.RSocketRequesterStaticFactory.resolveBrokerClientRSocket; +import static org.springframework.core.annotation.AnnotatedElementUtils.getMergedAnnotation; + +/** + * Resolves arguments of type {@link RSocket} that can be used for making + * requests to the remote peer. + * + * @author Rossen Stoyanchev + * @since 5.2 + */ +public class BrokerClientRequesterMethodArgumentResolver + implements HandlerMethodArgumentResolver { + + private final String rSocketName; + private final BrokerClient brokerClient; + private final DefaultListableBeanFactory listableBeanFactory; + private final RSocketStrategies rSocketStrategies; + + public BrokerClientRequesterMethodArgumentResolver( + String rSocketName, + BrokerClient client, + DefaultListableBeanFactory factory, + RSocketStrategies strategies + ) { + this.rSocketName = rSocketName; + brokerClient = client; + listableBeanFactory = factory; + rSocketStrategies = strategies; + } + + @Override + public boolean supportsParameter(MethodParameter parameter) { + Class type = parameter.getParameterType(); + return (RSocketRequester.class.equals(type) || RSocket.class.isAssignableFrom(type)); + } + + @Override + public Mono resolveArgument(MethodParameter parameter, Message message) { + Class type = parameter.getParameterType(); + com.netifi.spring.core.annotation.BrokerClient brokerClientAnnotation = + getMergedAnnotation(parameter.getParameter(), com.netifi.spring.core.annotation.BrokerClient.class); + + Assert.notNull( + brokerClientAnnotation, + "Incorrect Method Parameter, make sure your parameter is annotated with the @BrokerClient annotation" + ); + + if (RSocketRequester.class.equals(type)) { + return Mono.just(createRSocketRequester( + rSocketName, + brokerClient, + brokerClientAnnotation, + resolveTags(listableBeanFactory, brokerClientAnnotation), + rSocketStrategies + )); + } + else if (RSocket.class.isAssignableFrom(type)) { + return Mono.just(resolveBrokerClientRSocket( + rSocketName, + brokerClient, + brokerClientAnnotation.type(), + brokerClientAnnotation.group(), + brokerClientAnnotation.destination(), + resolveTags(listableBeanFactory, brokerClientAnnotation) + )); + } + else { + return Mono.error(new IllegalArgumentException("Unexpected parameter type: " + parameter)); + } + } + +} diff --git a/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/MessagingRSocketRequesterClientFactory.java b/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/MessagingRSocketRequesterClientFactory.java new file mode 100644 index 00000000..f6e0d977 --- /dev/null +++ b/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/MessagingRSocketRequesterClientFactory.java @@ -0,0 +1,61 @@ +package com.netifi.spring.messaging; + +import com.netifi.common.tags.Tags; +import com.netifi.spring.core.BrokerClientFactorySupport; +import com.netifi.spring.core.annotation.BrokerClient; +import io.micrometer.core.instrument.MeterRegistry; +import io.opentracing.Tracer; + +import org.springframework.messaging.rsocket.RSocketRequester; +import org.springframework.messaging.rsocket.RSocketStrategies; + +import static com.netifi.spring.messaging.RSocketRequesterStaticFactory.createRSocketRequester; + +public class MessagingRSocketRequesterClientFactory implements BrokerClientFactorySupport { + + private final String rSocketName; + private final com.netifi.broker.BrokerClient brokerClient; + private final Tracer tracer; + private final MeterRegistry meterRegistry; + private final RSocketStrategies rSocketStrategies; + + public MessagingRSocketRequesterClientFactory( + String rSocketName, + com.netifi.broker.BrokerClient brokerClient, + MeterRegistry meterRegistry, + Tracer tracer, + RSocketStrategies strategies + ) { + this.rSocketName = rSocketName; + this.brokerClient = brokerClient; + this.tracer = tracer; + this.meterRegistry = meterRegistry; + this.rSocketStrategies = strategies; + } + + @Override + public boolean support(Class clazz) { + return clazz.equals(RSocketRequester.class) || RSocketRequester.class.isAssignableFrom(clazz); + } + + @Override + @SuppressWarnings("unchecked") + public T lookup( + Class tClass, + BrokerClient.Type type, + String methodGroup, + Tags methodTags + ) { + return (T) createRSocketRequester( + rSocketName, + brokerClient, + type, + methodGroup, + null, + methodTags, + rSocketStrategies, + meterRegistry, + tracer + ); + } +} diff --git a/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/MetricsAwareRSocketRequester.java b/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/MetricsAwareRSocketRequester.java new file mode 100644 index 00000000..6cea01b7 --- /dev/null +++ b/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/MetricsAwareRSocketRequester.java @@ -0,0 +1,151 @@ +package com.netifi.spring.messaging; + +import io.micrometer.core.instrument.MeterRegistry; +import io.opentracing.Tracer; +import io.rsocket.RSocket; +import io.rsocket.rpc.metrics.Metrics; +import org.reactivestreams.Publisher; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.messaging.rsocket.RSocketRequester; + +public class MetricsAwareRSocketRequester implements RSocketRequester { + + private final RSocketRequester rSocketRequester; + private final MeterRegistry registry; + private final Tracer tracer; + + public MetricsAwareRSocketRequester( + RSocketRequester requester, + MeterRegistry meterRegistry, + Tracer tracer + ) { + this.rSocketRequester = requester; + this.registry = meterRegistry; + this.tracer = tracer; + } + + @Override + public RSocket rsocket() { + return rSocketRequester.rsocket(); + } + + @Override + public RequestSpec route(String route) { + return new MetricsAwareRequestSpec(rSocketRequester.route(route), route, + registry, + tracer); + } + + private static final class MetricsAwareRequestSpec implements RequestSpec { + + private final RequestSpec requestSpec; + private final String route; + private final MeterRegistry registry; + private final Tracer tracer; + + private MetricsAwareRequestSpec(RequestSpec spec, + String route, + MeterRegistry registry, + Tracer tracer) { + this.requestSpec = spec; + this.route = route; + this.registry = registry; + this.tracer = tracer; + } + + @Override + public ResponseSpec data(Object data) { + return requestSpec.data(data); + } + + @Override + public > ResponseSpec data(P publisher, Class dataType) { + return requestSpec.data(publisher, dataType); + } + + @Override + public > ResponseSpec data(P publisher, ParameterizedTypeReference dataTypeRef) { + return requestSpec.data(publisher, dataTypeRef); + } + } + + private static final class MetricsAwareResponseSepc implements ResponseSpec { + + private final ResponseSpec responseSpec; + private final String route; + private final MeterRegistry registry; + private final Tracer tracer; + + private MetricsAwareResponseSepc(ResponseSpec spec, + String route, + MeterRegistry registry, + Tracer tracer) { + this.responseSpec = spec; + this.route = route; + this.registry = registry; + this.tracer = tracer; + } + + @Override + public Mono send() { + return responseSpec + .send() + .transform(Metrics.timed( + registry, "rsocket.spring.client", + "route", route, + "call.type", "send" + )); + } + + @Override + public Mono retrieveMono(Class dataType) { + return responseSpec + .retrieveMono(dataType) + .transform(Metrics.timed( + registry, "rsocket.spring.client", + "route", route, + "call.type", "retrieveMono", + "data.type", dataType.getName() + )); + } + + @Override + public Mono retrieveMono(ParameterizedTypeReference dataTypeRef) { + return responseSpec + .retrieveMono(dataTypeRef) + .transform(Metrics.timed( + registry, "rsocket.spring.client", + "route", route, + "call.type", "retrieveMono", + "data.type", dataTypeRef.getType().getTypeName() + )); + } + + @Override + public Flux retrieveFlux(Class dataType) { + return responseSpec + .retrieveFlux(dataType) + .transform(Metrics.timed( + registry, "rsocket.spring.client", + "route", route, + "call.type", "retrieveFlux", + "data.type", dataType.getName() + )); + } + + @Override + public Flux retrieveFlux(ParameterizedTypeReference dataTypeRef) { + return responseSpec + .retrieveFlux(dataTypeRef) + .transform(Metrics.timed( + registry, "rsocket.spring.client", + "route", route, + "call.type", "retrieveFlux", + "data.type", dataTypeRef.getType().getTypeName() + )); + } + } +} diff --git a/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/RSocketRequesterStaticFactory.java b/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/RSocketRequesterStaticFactory.java new file mode 100644 index 00000000..6cff6124 --- /dev/null +++ b/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/RSocketRequesterStaticFactory.java @@ -0,0 +1,75 @@ +package com.netifi.spring.messaging; + +import com.netifi.broker.BrokerClient; +import com.netifi.broker.rsocket.BrokerSocket; +import com.netifi.broker.rsocket.NamedRSocketClientWrapper; +import com.netifi.common.tags.Tags; +import com.netifi.spring.core.annotation.BrokerClientStaticFactory; +import io.micrometer.core.instrument.MeterRegistry; +import io.opentracing.Tracer; + +import org.springframework.messaging.rsocket.RSocketRequester; +import org.springframework.messaging.rsocket.RSocketStrategies; + +class RSocketRequesterStaticFactory { + + static RSocketRequester createRSocketRequester( + String rSocketName, + BrokerClient brokerClient, + com.netifi.spring.core.annotation.BrokerClient brokerClientAnnotation, + Tags tags, + RSocketStrategies rSocketStrategies) { + return RSocketRequester.create( + resolveBrokerClientRSocket( + rSocketName, + brokerClient, + brokerClientAnnotation.type(), + brokerClientAnnotation.group(), + brokerClientAnnotation.destination(), + tags + ), + null, + rSocketStrategies + ); + } + + static RSocketRequester createRSocketRequester( + String rSocketName, + BrokerClient brokerClient, + com.netifi.spring.core.annotation.BrokerClient.Type routingType, + String group, + String destination, + Tags tags, + RSocketStrategies rSocketStrategies, + MeterRegistry meterRegistry, + Tracer tracer + ) { + + return new MetricsAwareRSocketRequester( + RSocketRequester.create( + resolveBrokerClientRSocket(rSocketName, brokerClient, routingType, group, destination, tags), + null, + rSocketStrategies + ), + meterRegistry, + tracer + ); + } + + static BrokerSocket resolveBrokerClientRSocket( + String rSocketName, + BrokerClient brokerClient, + com.netifi.spring.core.annotation.BrokerClient.Type routingType, + String group, + String destination, + Tags tags + ) { + return NamedRSocketClientWrapper.wrap(rSocketName, BrokerClientStaticFactory.createBrokerRSocket( + brokerClient, + routingType, + group, + destination, + tags + )); + } +} diff --git a/netifi-spring-messaging/src/test/java/com/netifi/spring/DefaultExternalIdlClient.java b/netifi-spring-messaging/src/test/java/com/netifi/spring/DefaultExternalIdlClient.java new file mode 100644 index 00000000..7a85072b --- /dev/null +++ b/netifi-spring-messaging/src/test/java/com/netifi/spring/DefaultExternalIdlClient.java @@ -0,0 +1,34 @@ +/* + * Copyright 2019 The Netifi Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.netifi.spring; + +import io.rsocket.rpc.annotations.internal.Generated; +import io.rsocket.rpc.annotations.internal.ResourceType; + +@Generated(type = ResourceType.CLIENT, idlClass = ExternalIdl.class) +public class DefaultExternalIdlClient implements ExternalIdl { + public DefaultExternalIdlClient(io.rsocket.RSocket rSocket) {} + + public DefaultExternalIdlClient( + io.rsocket.RSocket rSocket, io.micrometer.core.instrument.MeterRegistry registry) {} + + public DefaultExternalIdlClient(io.rsocket.RSocket rSocket, io.opentracing.Tracer tracer) {} + + public DefaultExternalIdlClient( + io.rsocket.RSocket rSocket, + io.micrometer.core.instrument.MeterRegistry registry, + io.opentracing.Tracer tracer) {} +} diff --git a/netifi-spring-messaging/src/test/java/com/netifi/spring/ExternalIdl.java b/netifi-spring-messaging/src/test/java/com/netifi/spring/ExternalIdl.java new file mode 100644 index 00000000..b0c759ef --- /dev/null +++ b/netifi-spring-messaging/src/test/java/com/netifi/spring/ExternalIdl.java @@ -0,0 +1,18 @@ +/* + * Copyright 2019 The Netifi Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.netifi.spring; + +public interface ExternalIdl {} diff --git a/netifi-spring-messaging/src/test/java/com/netifi/spring/core/AutowireInsideComponentIntegrationTest.java b/netifi-spring-messaging/src/test/java/com/netifi/spring/core/AutowireInsideComponentIntegrationTest.java new file mode 100644 index 00000000..8894070a --- /dev/null +++ b/netifi-spring-messaging/src/test/java/com/netifi/spring/core/AutowireInsideComponentIntegrationTest.java @@ -0,0 +1,98 @@ +/* + * Copyright 2019 The Netifi Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.netifi.spring.core; + +import com.netifi.broker.info.BrokerInfoService; +import com.netifi.broker.info.BrokerInfoServiceClient; +import com.netifi.spring.DefaultExternalIdlClient; +import com.netifi.spring.core.annotation.Broadcast; +import com.netifi.spring.core.annotation.BrokerClient; +import com.netifi.spring.core.annotation.Destination; +import com.netifi.spring.core.annotation.Group; +import io.rsocket.rpc.metrics.om.MetricsSnapshotHandler; +import io.rsocket.rpc.metrics.om.MetricsSnapshotHandlerClient; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +@ExtendWith(SpringExtension.class) +@ContextConfiguration( + classes = { + TestableConfiguration.class, + AutowireInsideComponentIntegrationTest.AutowirableConfiguration.class + }) +public class AutowireInsideComponentIntegrationTest { + + @Autowired TestBean testBean; + + @Test + public void shouldFindGeneratedBean() { + Assertions.assertEquals(DefaultClientTestIdl.class, testBean.broadcastTestIdlClient.getClass()); + Assertions.assertEquals(DefaultClientTestIdl.class, testBean.groupTestIdlClient.getClass()); + Assertions.assertEquals( + DefaultClientTestIdl.class, testBean.destinationTestIdaClient.getClass()); + Assertions.assertEquals( + MetricsSnapshotHandlerClient.class, testBean.metricsSnapshotHandlerClient.getClass()); + Assertions.assertEquals( + BrokerInfoServiceClient.class, testBean.brokerInfoServiceClient.getClass()); + Assertions.assertEquals(TestIdlImpl.class, testBean.serviceImpl.getClass()); + Assertions.assertNotNull(testBean.destinationAwareClientFactory); + Assertions.assertNotNull(testBean.groupAwareClientFactory); + Assertions.assertNotNull(testBean.broadcastAwareClientFactory); + Assertions.assertNotNull(testBean.defaultExternalIdlClient); + } + + @Configuration + public static class AutowirableConfiguration { + + @Bean + public TestBean testBean( + @Broadcast("test") TestIdl broadcastTestIdlClient, + @Group("test") TestIdl groupTestIdlClient, + @Destination(group = "test", destination = "test") TestIdl destinationTestIdaClient, + @Group("test") MetricsSnapshotHandler metricsSnapshotHandlerClient, + @Group("test") BrokerInfoService brokerInfoServiceClient, + @Destination(group = "test", destination = "test") + DefaultExternalIdlClient defaultExternalIdlClient, + @BrokerClient( + group = "test", + destination = "test", + clientClass = DefaultExternalIdlClient.class) + DestinationAwareClientFactory destinationAwareClientFactory, + @BrokerClient(group = "test", clientClass = DefaultExternalIdlClient.class) + GroupAwareClientFactory groupAwareClientFactory, + @BrokerClient(group = "test", clientClass = DefaultExternalIdlClient.class) + BroadcastAwareClientFactory broadcastAwareClientFactory, + TestIdl serviceImpl) { + return new TestBean( + broadcastTestIdlClient, + groupTestIdlClient, + destinationTestIdaClient, + metricsSnapshotHandlerClient, + brokerInfoServiceClient, + defaultExternalIdlClient, + destinationAwareClientFactory, + groupAwareClientFactory, + broadcastAwareClientFactory, + serviceImpl); + } + } +} diff --git a/netifi-spring-messaging/src/test/java/com/netifi/spring/core/AutowireInsideConfigurationClassIntegrationTest.java b/netifi-spring-messaging/src/test/java/com/netifi/spring/core/AutowireInsideConfigurationClassIntegrationTest.java new file mode 100644 index 00000000..ed7de891 --- /dev/null +++ b/netifi-spring-messaging/src/test/java/com/netifi/spring/core/AutowireInsideConfigurationClassIntegrationTest.java @@ -0,0 +1,101 @@ +/* + * Copyright 2019 The Netifi Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.netifi.spring.core; + +import com.netifi.broker.info.BrokerInfoService; +import com.netifi.broker.info.BrokerInfoServiceClient; +import com.netifi.spring.DefaultExternalIdlClient; +import com.netifi.spring.core.annotation.Broadcast; +import com.netifi.spring.core.annotation.BrokerClient; +import com.netifi.spring.core.annotation.Destination; +import com.netifi.spring.core.annotation.Group; +import io.rsocket.rpc.metrics.om.MetricsSnapshotHandler; +import io.rsocket.rpc.metrics.om.MetricsSnapshotHandlerClient; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +@ExtendWith(SpringExtension.class) +@ContextConfiguration( + classes = { + TestableConfiguration.class, + AutowireInsideConfigurationClassIntegrationTest.AutowirableComponent.class + }) +public class AutowireInsideConfigurationClassIntegrationTest { + + @Autowired AutowirableComponent component; + + @Test + public void shouldFindGeneratedBean() { + Assertions.assertEquals( + DefaultClientTestIdl.class, component.broadcastTestIdlClient.getClass()); + Assertions.assertEquals(DefaultClientTestIdl.class, component.groupTestIdlClient.getClass()); + Assertions.assertEquals( + DefaultClientTestIdl.class, component.destinationTestIdaClient.getClass()); + Assertions.assertEquals( + MetricsSnapshotHandlerClient.class, component.metricsSnapshotHandlerClient.getClass()); + Assertions.assertEquals( + BrokerInfoServiceClient.class, component.brokerInfoServiceClient.getClass()); + Assertions.assertEquals(TestIdlImpl.class, component.serviceImpl.getClass()); + Assertions.assertNotNull(component.destinationAwareClientFactory); + Assertions.assertNotNull(component.groupAwareClientFactory); + Assertions.assertNotNull(component.broadcastAwareClientFactory); + Assertions.assertNotNull(component.defaultExternalIdlClient); + } + + @Component + public static class AutowirableComponent { + + @Broadcast("test") + TestIdl broadcastTestIdlClient; + + @Group("test") + TestIdl groupTestIdlClient; + + @Destination(group = "test", destination = "test") + TestIdl destinationTestIdaClient; + + @Group("test") + MetricsSnapshotHandler metricsSnapshotHandlerClient; + + @Group("test") + BrokerInfoService brokerInfoServiceClient; + + @Destination(group = "test", destination = "test") + DefaultExternalIdlClient defaultExternalIdlClient; + + @Autowired + @BrokerClient( + group = "test", + destination = "test", + clientClass = DefaultExternalIdlClient.class) + DestinationAwareClientFactory destinationAwareClientFactory; + + @Autowired + @BrokerClient(group = "test", clientClass = DefaultExternalIdlClient.class) + GroupAwareClientFactory groupAwareClientFactory; + + @Autowired + @BrokerClient(group = "test", clientClass = DefaultExternalIdlClient.class) + BroadcastAwareClientFactory broadcastAwareClientFactory; + + @Autowired TestIdl serviceImpl; + } +} diff --git a/netifi-spring-messaging/src/test/java/com/netifi/spring/core/DefaultClientTestIdl.java b/netifi-spring-messaging/src/test/java/com/netifi/spring/core/DefaultClientTestIdl.java new file mode 100644 index 00000000..b381a1c5 --- /dev/null +++ b/netifi-spring-messaging/src/test/java/com/netifi/spring/core/DefaultClientTestIdl.java @@ -0,0 +1,35 @@ +/* + * Copyright 2019 The Netifi Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.netifi.spring.core; + +import io.rsocket.rpc.annotations.internal.Generated; +import io.rsocket.rpc.annotations.internal.ResourceType; + +@Generated(type = ResourceType.CLIENT, idlClass = TestIdl.class) +public class DefaultClientTestIdl implements TestIdl { + + public DefaultClientTestIdl(io.rsocket.RSocket rSocket) {} + + public DefaultClientTestIdl( + io.rsocket.RSocket rSocket, io.micrometer.core.instrument.MeterRegistry registry) {} + + public DefaultClientTestIdl(io.rsocket.RSocket rSocket, io.opentracing.Tracer tracer) {} + + public DefaultClientTestIdl( + io.rsocket.RSocket rSocket, + io.micrometer.core.instrument.MeterRegistry registry, + io.opentracing.Tracer tracer) {} +} diff --git a/netifi-spring-messaging/src/test/java/com/netifi/spring/core/PlainAutowireIntegrationTest.java b/netifi-spring-messaging/src/test/java/com/netifi/spring/core/PlainAutowireIntegrationTest.java new file mode 100644 index 00000000..0a8b359a --- /dev/null +++ b/netifi-spring-messaging/src/test/java/com/netifi/spring/core/PlainAutowireIntegrationTest.java @@ -0,0 +1,87 @@ +/* + * Copyright 2019 The Netifi Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.netifi.spring.core; + +import com.netifi.broker.info.BrokerInfoService; +import com.netifi.broker.info.BrokerInfoServiceClient; +import com.netifi.spring.DefaultExternalIdlClient; +import com.netifi.spring.core.annotation.Broadcast; +import com.netifi.spring.core.annotation.BrokerClient; +import com.netifi.spring.core.annotation.Destination; +import com.netifi.spring.core.annotation.Group; +import io.rsocket.rpc.metrics.om.MetricsSnapshotHandler; +import io.rsocket.rpc.metrics.om.MetricsSnapshotHandlerClient; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +@ExtendWith(SpringExtension.class) +@ContextConfiguration(classes = TestableConfiguration.class) +public class PlainAutowireIntegrationTest { + + @Autowired ConfigurableListableBeanFactory beanFactory; + + @Broadcast("test") + TestIdl broadcastTestIdlClient; + + @Group("test") + TestIdl groupTestIdlClient; + + @Destination(group = "test", destination = "test") + TestIdl destinationTestIdaClient; + + @Group("test") + MetricsSnapshotHandler metricsSnapshotHandlerClient; + + @Group("test") + BrokerInfoService brokerInfoServiceClient; + + @Destination(group = "test", destination = "test") + DefaultExternalIdlClient defaultExternalIdlClient; + + @Autowired + @BrokerClient(group = "test", destination = "test", clientClass = DefaultExternalIdlClient.class) + DestinationAwareClientFactory destinationAwareClientFactory; + + @Autowired + @BrokerClient(group = "test", clientClass = DefaultExternalIdlClient.class) + GroupAwareClientFactory groupAwareClientFactory; + + @Autowired + @BrokerClient(group = "test", clientClass = DefaultExternalIdlClient.class) + BroadcastAwareClientFactory broadcastAwareClientFactory; + + @Autowired TestIdl serviceImpl; + + @Test + public void shouldFindGeneratedBean() { + Assertions.assertEquals(DefaultClientTestIdl.class, broadcastTestIdlClient.getClass()); + Assertions.assertEquals(DefaultClientTestIdl.class, groupTestIdlClient.getClass()); + Assertions.assertEquals(DefaultClientTestIdl.class, destinationTestIdaClient.getClass()); + Assertions.assertEquals( + MetricsSnapshotHandlerClient.class, metricsSnapshotHandlerClient.getClass()); + Assertions.assertEquals(BrokerInfoServiceClient.class, brokerInfoServiceClient.getClass()); + Assertions.assertEquals(TestIdlImpl.class, serviceImpl.getClass()); + Assertions.assertNotNull(destinationAwareClientFactory); + Assertions.assertNotNull(groupAwareClientFactory); + Assertions.assertNotNull(broadcastAwareClientFactory); + Assertions.assertNotNull(defaultExternalIdlClient); + } +} diff --git a/netifi-spring-messaging/src/test/java/com/netifi/spring/core/TestBean.java b/netifi-spring-messaging/src/test/java/com/netifi/spring/core/TestBean.java new file mode 100644 index 00000000..5b08232f --- /dev/null +++ b/netifi-spring-messaging/src/test/java/com/netifi/spring/core/TestBean.java @@ -0,0 +1,59 @@ +/* + * Copyright 2019 The Netifi Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.netifi.spring.core; + +import com.netifi.broker.info.BrokerInfoService; +import com.netifi.spring.DefaultExternalIdlClient; +import io.rsocket.rpc.metrics.om.MetricsSnapshotHandler; + +public class TestBean { + + public final TestIdl broadcastTestIdlClient; + public final TestIdl groupTestIdlClient; + public final TestIdl destinationTestIdaClient; + public final MetricsSnapshotHandler metricsSnapshotHandlerClient; + public final BrokerInfoService brokerInfoServiceClient; + public final DefaultExternalIdlClient defaultExternalIdlClient; + public final DestinationAwareClientFactory + destinationAwareClientFactory; + public final GroupAwareClientFactory groupAwareClientFactory; + public final BroadcastAwareClientFactory broadcastAwareClientFactory; + public final TestIdl serviceImpl; + + public TestBean( + TestIdl broadcastTestIdlClient, + TestIdl groupTestIdlClient, + TestIdl destinationTestIdaClient, + MetricsSnapshotHandler metricsSnapshotHandlerClient, + BrokerInfoService brokerInfoServiceClient, + DefaultExternalIdlClient defaultExternalIdlClient, + DestinationAwareClientFactory destinationAwareClientFactory, + GroupAwareClientFactory groupAwareClientFactory, + BroadcastAwareClientFactory broadcastAwareClientFactory, + TestIdl serviceImpl) { + + this.broadcastTestIdlClient = broadcastTestIdlClient; + this.groupTestIdlClient = groupTestIdlClient; + this.destinationTestIdaClient = destinationTestIdaClient; + this.metricsSnapshotHandlerClient = metricsSnapshotHandlerClient; + this.brokerInfoServiceClient = brokerInfoServiceClient; + this.defaultExternalIdlClient = defaultExternalIdlClient; + this.destinationAwareClientFactory = destinationAwareClientFactory; + this.groupAwareClientFactory = groupAwareClientFactory; + this.broadcastAwareClientFactory = broadcastAwareClientFactory; + this.serviceImpl = serviceImpl; + } +} diff --git a/netifi-spring-core/src/main/java/com/netifi/spring/core/NoClass.java b/netifi-spring-messaging/src/test/java/com/netifi/spring/core/TestIdl.java similarity index 95% rename from netifi-spring-core/src/main/java/com/netifi/spring/core/NoClass.java rename to netifi-spring-messaging/src/test/java/com/netifi/spring/core/TestIdl.java index 294a0185..03b47847 100644 --- a/netifi-spring-core/src/main/java/com/netifi/spring/core/NoClass.java +++ b/netifi-spring-messaging/src/test/java/com/netifi/spring/core/TestIdl.java @@ -15,4 +15,4 @@ */ package com.netifi.spring.core; -public class NoClass {} +public interface TestIdl {} diff --git a/netifi-spring-messaging/src/test/java/com/netifi/spring/core/TestIdlImpl.java b/netifi-spring-messaging/src/test/java/com/netifi/spring/core/TestIdlImpl.java new file mode 100644 index 00000000..472e1941 --- /dev/null +++ b/netifi-spring-messaging/src/test/java/com/netifi/spring/core/TestIdlImpl.java @@ -0,0 +1,18 @@ +/* + * Copyright 2019 The Netifi Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.netifi.spring.core; + +public class TestIdlImpl implements TestIdl {} diff --git a/netifi-spring-messaging/src/test/java/com/netifi/spring/core/TestIdlServiceServer.java b/netifi-spring-messaging/src/test/java/com/netifi/spring/core/TestIdlServiceServer.java new file mode 100644 index 00000000..7f4945b7 --- /dev/null +++ b/netifi-spring-messaging/src/test/java/com/netifi/spring/core/TestIdlServiceServer.java @@ -0,0 +1,33 @@ +/* + * Copyright 2019 The Netifi Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.netifi.spring.core; + +import io.rsocket.rpc.AbstractRSocketService; + +@javax.annotation.Generated( + value = "by RSocket RPC proto compiler (version 0.2.10)", + comments = "Source: isvowel.proto") +@io.rsocket.rpc.annotations.internal.Generated( + type = io.rsocket.rpc.annotations.internal.ResourceType.SERVICE, + idlClass = TestIdl.class) +@javax.inject.Named(value = "TestIdlServiceServer") +public class TestIdlServiceServer extends AbstractRSocketService { + + @Override + public Class getServiceClass() { + return TestIdl.class; + } +} diff --git a/netifi-spring-messaging/src/test/java/com/netifi/spring/core/TestableConfiguration.java b/netifi-spring-messaging/src/test/java/com/netifi/spring/core/TestableConfiguration.java new file mode 100644 index 00000000..385f0378 --- /dev/null +++ b/netifi-spring-messaging/src/test/java/com/netifi/spring/core/TestableConfiguration.java @@ -0,0 +1,37 @@ +/* + * Copyright 2019 The Netifi Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.netifi.spring.core; + +import com.netifi.broker.BrokerClient; +import com.netifi.spring.core.config.EnableBrokerClient; +import org.mockito.Mockito; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +@EnableBrokerClient +public class TestableConfiguration { + + @Bean + public BrokerClient brokerClient() { + return Mockito.mock(BrokerClient.class); + } + + @Bean + public TestIdlImpl testIdlImpl() { + return new TestIdlImpl(); + } +} diff --git a/netifi-tracing-idl/gradle/dependency-locks/compile.lockfile~merged b/netifi-tracing-idl/gradle/dependency-locks/compile.lockfile~merged new file mode 100644 index 00000000..656c5dbc --- /dev/null +++ b/netifi-tracing-idl/gradle/dependency-locks/compile.lockfile~merged @@ -0,0 +1,3 @@ +# This is a Gradle generated file for dependency locking. +# Manual edits can break the build and are not advised. +# This file is expected to be part of source control. diff --git a/netifi-tracing-openzipkin/gradle/dependency-locks/annotationProcessor.lockfile~merged b/netifi-tracing-openzipkin/gradle/dependency-locks/annotationProcessor.lockfile~merged new file mode 100644 index 00000000..656c5dbc --- /dev/null +++ b/netifi-tracing-openzipkin/gradle/dependency-locks/annotationProcessor.lockfile~merged @@ -0,0 +1,3 @@ +# This is a Gradle generated file for dependency locking. +# Manual edits can break the build and are not advised. +# This file is expected to be part of source control. diff --git a/netifi-tracing-openzipkin/gradle/dependency-locks/protobuf.lockfile~merged b/netifi-tracing-openzipkin/gradle/dependency-locks/protobuf.lockfile~merged new file mode 100644 index 00000000..656c5dbc --- /dev/null +++ b/netifi-tracing-openzipkin/gradle/dependency-locks/protobuf.lockfile~merged @@ -0,0 +1,3 @@ +# This is a Gradle generated file for dependency locking. +# Manual edits can break the build and are not advised. +# This file is expected to be part of source control. diff --git a/netifi-tracing-openzipkin/gradle/dependency-locks/testAnnotationProcessor.lockfile~merged b/netifi-tracing-openzipkin/gradle/dependency-locks/testAnnotationProcessor.lockfile~merged new file mode 100644 index 00000000..656c5dbc --- /dev/null +++ b/netifi-tracing-openzipkin/gradle/dependency-locks/testAnnotationProcessor.lockfile~merged @@ -0,0 +1,3 @@ +# This is a Gradle generated file for dependency locking. +# Manual edits can break the build and are not advised. +# This file is expected to be part of source control. diff --git a/settings.gradle b/settings.gradle index dafa7718..648038f4 100644 --- a/settings.gradle +++ b/settings.gradle @@ -27,5 +27,6 @@ include 'netifi-metrics-micrometer' include 'netifi-metrics-prometheus' include 'netifi-tracing-openzipkin' include 'netifi-spring-core' +include 'netifi-spring-messaging' include 'netifi-spring-boot-starter' include 'netifi-spring-boot-autoconfigure' From ce3a562a9bbd36fcb4163189a1a0d8edb2c9e1c3 Mon Sep 17 00:00:00 2001 From: Oleh Dokuka Date: Wed, 5 Jun 2019 18:58:21 +0200 Subject: [PATCH 5/9] latest fixes and tests --- gradle.properties | 1 + .../buildscript-classpath.lockfile | 4 +- .../netifi/broker/DefaultBuilderConfig.java | 11 +- .../broker/DefaultBuilderConfigTest.java | 8 +- netifi-spring-boot-autoconfigure/build.gradle | 4 + .../annotationProcessor.lockfile | 4 +- .../compileClasspath.lockfile | 43 +- .../boot/BrokerClientAutoConfiguration.java | 15 +- ...rokerClientMessagingAutoConfiguration.java | 111 ++-- .../boot/BrokerClientMessagingProperties.java | 22 +- .../spring/boot/BrokerClientProperties.java | 53 +- .../boot/SpringMessagingIntegrationTest.java | 41 -- .../BrokerClientSpringIntegrationTest.java | 3 +- .../ClientConfigurationIntegrationTest.java | 14 +- .../boot/{ => test}/DefaultClientTestIdl.java | 2 +- .../spring/boot/test/MessageHandler.java | 18 + .../test/SpringMessagingIntegrationTest.java | 74 +++ .../boot/{ => test}/TestApplication.java | 12 +- .../spring/boot/{ => test}/TestIdl.java | 2 +- .../spring/boot/{ => test}/TestIdlImpl.java | 2 +- .../boot/{ => test}/TestIdlServiceServer.java | 2 +- .../compileClasspath.lockfile | 16 +- .../core/BrokerClientFactorySupport.java | 4 +- .../core/DestinationAwareClientFactory.java | 3 +- .../annotation/BaseBrokerClientFactory.java | 160 +++-- .../spring/core/annotation/BrokerClient.java | 44 +- ...ntBeanDefinitionRegistryPostProcessor.java | 62 +- .../annotation/BrokerClientStaticFactory.java | 579 +++++++++--------- .../DefaultBroadcastAwareClientFactory.java | 99 ++- .../DefaultDestinationAwareClientFactory.java | 99 ++- .../DefaultGroupAwareClientFactory.java | 99 ++- .../RpcBrokerClientFactorySupport.java | 64 +- .../config/BrokerClientConfiguration.java | 10 +- netifi-spring-messaging/build.gradle | 2 +- .../compileClasspath.lockfile | 32 +- ...ClientRequesterMethodArgumentResolver.java | 122 ++-- ...essagingRSocketRequesterClientFactory.java | 74 +-- .../MetricsAwareRSocketRequester.java | 253 ++++---- .../RSocketRequesterStaticFactory.java | 105 ++-- 39 files changed, 1183 insertions(+), 1090 deletions(-) delete mode 100644 netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/SpringMessagingIntegrationTest.java rename netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/{ => test}/BrokerClientSpringIntegrationTest.java (98%) rename netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/{ => test}/ClientConfigurationIntegrationTest.java (87%) rename netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/{ => test}/DefaultClientTestIdl.java (97%) create mode 100644 netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/MessageHandler.java create mode 100644 netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/SpringMessagingIntegrationTest.java rename netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/{ => test}/TestApplication.java (66%) rename netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/{ => test}/TestIdl.java (94%) rename netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/{ => test}/TestIdlImpl.java (95%) rename netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/{ => test}/TestIdlServiceServer.java (97%) diff --git a/gradle.properties b/gradle.properties index eea56849..c10d4c1c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -36,3 +36,4 @@ spectatorVersion=0.61.0 typesafeConfigVersion=1.3.3 zipkinSenderVersion=2.7.6 springBootDependenciesVersion=2.2.2.RELEASE +testcontainersVersion=1.11.3 diff --git a/gradle/dependency-locks/buildscript-classpath.lockfile b/gradle/dependency-locks/buildscript-classpath.lockfile index 31202810..5b16e961 100644 --- a/gradle/dependency-locks/buildscript-classpath.lockfile +++ b/gradle/dependency-locks/buildscript-classpath.lockfile @@ -32,8 +32,8 @@ javax.annotation:jsr250-api:1.0 javax.enterprise:cdi-api:1.0 javax.inject:javax.inject:1 kr.motd.maven:os-maven-plugin:1.4.0.Final -me.champeau.gradle.jmh:me.champeau.gradle.jmh.gradle.plugin:0.4.8 -me.champeau.gradle:jmh-gradle-plugin:0.4.8 +me.champeau.gradle.jmh:me.champeau.gradle.jmh.gradle.plugin:0.4.7 +me.champeau.gradle:jmh-gradle-plugin:0.4.7 net.sf.jopt-simple:jopt-simple:4.6 org.apache.commons:commons-math3:3.2 org.apache.commons:commons-pool2:2.2 diff --git a/netifi-broker-client/src/main/java/com/netifi/broker/DefaultBuilderConfig.java b/netifi-broker-client/src/main/java/com/netifi/broker/DefaultBuilderConfig.java index 54abfbda..37bd0cba 100644 --- a/netifi-broker-client/src/main/java/com/netifi/broker/DefaultBuilderConfig.java +++ b/netifi-broker-client/src/main/java/com/netifi/broker/DefaultBuilderConfig.java @@ -24,7 +24,6 @@ import java.net.UnknownHostException; import java.util.ArrayList; import java.util.List; -import java.util.Map; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -160,12 +159,10 @@ static Tags getTags() { StringBuilder key = new StringBuilder(e.getKey()); ConfigValue configValue = e.getValue(); - while (configValue != null && - configValue.valueType() == ConfigValueType.OBJECT) { - Set keySet = - ((ConfigObject) configValue).keySet(); - String nextKey = keySet.iterator() - .next(); + while (configValue != null + && configValue.valueType() == ConfigValueType.OBJECT) { + Set keySet = ((ConfigObject) configValue).keySet(); + String nextKey = keySet.iterator().next(); key.append(".").append(nextKey); configValue = ((ConfigObject) configValue).get(nextKey); } diff --git a/netifi-broker-client/src/test/java/com/netifi/broker/DefaultBuilderConfigTest.java b/netifi-broker-client/src/test/java/com/netifi/broker/DefaultBuilderConfigTest.java index cda37e56..34fdae54 100644 --- a/netifi-broker-client/src/test/java/com/netifi/broker/DefaultBuilderConfigTest.java +++ b/netifi-broker-client/src/test/java/com/netifi/broker/DefaultBuilderConfigTest.java @@ -15,13 +15,12 @@ */ package com.netifi.broker; +import com.netifi.common.tags.Tag; +import com.netifi.common.tags.Tags; import java.net.InetSocketAddress; import java.net.SocketAddress; import java.util.List; import java.util.Optional; - -import com.netifi.common.tags.Tag; -import com.netifi.common.tags.Tags; import org.junit.Assert; import org.junit.Ignore; import org.junit.Test; @@ -68,8 +67,7 @@ public void testShouldThrowExceptionForInvalidAddress() { public void testShouldParseTagsSuccessfully() { System.setProperty("netifi.client.tags.com.netifi.destination", "myDestination"); Tags tags = DefaultBuilderConfig.getTags(); - Optional first = tags.stream() - .findFirst(); + Optional first = tags.stream().findFirst(); Assert.assertTrue(first.isPresent()); Assert.assertEquals(first.get(), Tag.of("com.netifi.destination", "myDestination")); diff --git a/netifi-spring-boot-autoconfigure/build.gradle b/netifi-spring-boot-autoconfigure/build.gradle index b261b374..c5a825e1 100644 --- a/netifi-spring-boot-autoconfigure/build.gradle +++ b/netifi-spring-boot-autoconfigure/build.gradle @@ -32,6 +32,10 @@ dependencies { annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor' annotationProcessor 'org.springframework.boot:spring-boot-autoconfigure-processor' + + + testCompile project(':netifi-spring-core') + testCompile project(':netifi-spring-messaging') testCompile 'org.springframework.boot:spring-boot-starter-test' testCompile 'org.springframework:spring-messaging' testCompile 'org.mockito:mockito-core' diff --git a/netifi-spring-boot-autoconfigure/gradle/dependency-locks/annotationProcessor.lockfile b/netifi-spring-boot-autoconfigure/gradle/dependency-locks/annotationProcessor.lockfile index 63d5c6a1..4152d05f 100644 --- a/netifi-spring-boot-autoconfigure/gradle/dependency-locks/annotationProcessor.lockfile +++ b/netifi-spring-boot-autoconfigure/gradle/dependency-locks/annotationProcessor.lockfile @@ -1,5 +1,5 @@ # This is a Gradle generated file for dependency locking. # Manual edits can break the build and are not advised. # This file is expected to be part of source control. -org.springframework.boot:spring-boot-autoconfigure-processor:2.1.5.RELEASE -org.springframework.boot:spring-boot-configuration-processor:2.1.5.RELEASE +org.springframework.boot:spring-boot-autoconfigure-processor:2.2.0.BUILD-SNAPSHOT +org.springframework.boot:spring-boot-configuration-processor:2.2.0.BUILD-SNAPSHOT diff --git a/netifi-spring-boot-autoconfigure/gradle/dependency-locks/compileClasspath.lockfile b/netifi-spring-boot-autoconfigure/gradle/dependency-locks/compileClasspath.lockfile index 4492c676..ae284cfb 100644 --- a/netifi-spring-boot-autoconfigure/gradle/dependency-locks/compileClasspath.lockfile +++ b/netifi-spring-boot-autoconfigure/gradle/dependency-locks/compileClasspath.lockfile @@ -4,10 +4,10 @@ ch.qos.logback:logback-classic:1.2.3 ch.qos.logback:logback-core:1.2.3 com.fasterxml.jackson.core:jackson-annotations:2.9.0 -com.fasterxml.jackson.core:jackson-core:2.9.8 -com.fasterxml.jackson.core:jackson-databind:2.9.8 -com.fasterxml.jackson.dataformat:jackson-dataformat-smile:2.9.8 -com.fasterxml:classmate:1.4.0 +com.fasterxml.jackson.core:jackson-core:2.9.9 +com.fasterxml.jackson.core:jackson-databind:2.9.9 +com.fasterxml.jackson.dataformat:jackson-dataformat-smile:2.9.9 +com.fasterxml:classmate:1.5.0 com.google.code.findbugs:annotations:3.0.1 com.google.code.findbugs:jsr305:3.0.2 com.google.code.gson:gson:2.8.5 @@ -40,9 +40,9 @@ io.netty:netty-transport-native-unix-common:4.1.36.Final io.netty:netty-transport:4.1.36.Final io.opentracing.brave:brave-opentracing:0.33.10 io.opentracing:opentracing-api:0.31.0 -io.projectreactor.addons:reactor-adapter:3.2.3.RELEASE -io.projectreactor.netty:reactor-netty:0.8.8.RELEASE -io.projectreactor:reactor-core:3.2.9.RELEASE +io.projectreactor.addons:reactor-adapter:3.3.0.BUILD-SNAPSHOT +io.projectreactor.netty:reactor-netty:0.9.0.BUILD-SNAPSHOT +io.projectreactor:reactor-core:3.3.0.BUILD-SNAPSHOT io.rsocket.rpc:rsocket-rpc-core:0.2.18 io.rsocket.rpc:rsocket-rpc-protobuf:0.2.18 io.rsocket:rsocket-core:1.0.0-RC5 @@ -50,29 +50,32 @@ io.rsocket:rsocket-transport-netty:1.0.0-RC5 io.zipkin.brave:brave:5.6.1 io.zipkin.reporter2:zipkin-reporter:2.7.14 io.zipkin.zipkin2:zipkin:2.12.0 +jakarta.annotation:jakarta.annotation-api:1.3.4 +jakarta.validation:jakarta.validation-api:2.0.1 javax.annotation:javax.annotation-api:1.3.2 javax.inject:javax.inject:1 javax.validation:validation-api:2.0.1.Final org.apache.logging.log4j:log4j-api:2.11.2 org.apache.logging.log4j:log4j-to-slf4j:2.11.2 -org.apache.tomcat.embed:tomcat-embed-el:9.0.19 +org.apache.tomcat.embed:tomcat-embed-el:9.0.20 org.checkerframework:checker-qual:2.5.2 org.codehaus.mojo:animal-sniffer-annotations:1.17 org.hdrhistogram:HdrHistogram:2.1.10 org.hibernate.validator:hibernate-validator:6.0.16.Final -org.jboss.logging:jboss-logging:3.3.2.Final +org.jboss.logging:jboss-logging:3.4.0.Final org.latencyutils:LatencyUtils:2.0.3 org.reactivestreams:reactive-streams:1.0.2 org.slf4j:jul-to-slf4j:1.7.26 org.slf4j:slf4j-api:1.7.25 -org.springframework.boot:spring-boot-autoconfigure:2.1.5.RELEASE -org.springframework.boot:spring-boot-starter-logging:2.1.5.RELEASE -org.springframework.boot:spring-boot-starter-validation:2.1.5.RELEASE -org.springframework.boot:spring-boot-starter:2.1.5.RELEASE -org.springframework.boot:spring-boot:2.1.5.RELEASE -org.springframework:spring-aop:5.1.7.RELEASE -org.springframework:spring-beans:5.1.7.RELEASE -org.springframework:spring-context:5.1.7.RELEASE -org.springframework:spring-core:5.1.7.RELEASE -org.springframework:spring-expression:5.1.7.RELEASE -org.springframework:spring-jcl:5.1.7.RELEASE +org.springframework.boot:spring-boot-autoconfigure:2.2.0.BUILD-SNAPSHOT +org.springframework.boot:spring-boot-starter-logging:2.2.0.BUILD-SNAPSHOT +org.springframework.boot:spring-boot-starter-validation:2.2.0.BUILD-SNAPSHOT +org.springframework.boot:spring-boot-starter:2.2.0.BUILD-SNAPSHOT +org.springframework.boot:spring-boot:2.2.0.BUILD-SNAPSHOT +org.springframework:spring-aop:5.2.0.BUILD-SNAPSHOT +org.springframework:spring-beans:5.2.0.BUILD-SNAPSHOT +org.springframework:spring-context:5.2.0.BUILD-SNAPSHOT +org.springframework:spring-core:5.2.0.BUILD-SNAPSHOT +org.springframework:spring-expression:5.2.0.BUILD-SNAPSHOT +org.springframework:spring-jcl:5.2.0.BUILD-SNAPSHOT +org.springframework:spring-messaging:5.2.0.BUILD-SNAPSHOT diff --git a/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientAutoConfiguration.java b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientAutoConfiguration.java index 718f98a8..f54acffb 100644 --- a/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientAutoConfiguration.java +++ b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientAutoConfiguration.java @@ -35,7 +35,7 @@ import io.rsocket.transport.netty.client.WebsocketClientTransport; import java.util.List; import java.util.Optional; -import org.springframework.beans.BeansException; + import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor; import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -44,7 +44,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.boot.context.event.ApplicationFailedEvent; import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.ApplicationContext; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -75,8 +74,7 @@ static BrokerClient configureBrokerClient(List } @Bean(name = "internalScanClassPathBeanDefinitionRegistryPostProcessor") - public BeanDefinitionRegistryPostProcessor scanClassPathBeanDefinitionRegistryPostProcessor( - ApplicationContext applicationContext) throws BeansException { + public BeanDefinitionRegistryPostProcessor scanClassPathBeanDefinitionRegistryPostProcessor() { return new ScanClassPathBeanDefinitionRegistryPostProcessor(); } @@ -90,6 +88,7 @@ public BrokerClientConfigurer propertiesBasedBrokerClientConfigurer( BrokerClientProperties.AccessProperties access = brokerClientProperties.getAccess(); BrokerClientProperties.BrokerProperties broker = brokerClientProperties.getBroker(); BrokerClientProperties.DiscoveryProperties discovery = brokerClientProperties.getDiscovery(); + BrokerClientProperties.KeepAliveProperties keepalive = brokerClientProperties.getKeepalive(); if (!StringUtils.isEmpty(brokerClientProperties.getDestination())) { builder.destination(brokerClientProperties.getDestination()); @@ -172,7 +171,7 @@ public BrokerClientConfigurer propertiesBasedBrokerClientConfigurer( tags = tags.and(suppliedTags); } - boolean sslDisabled = brokerClientProperties.getSsl().isDisabled(); + boolean sslDisabled = ssl.isDisabled(); if (connectionType == BrokerClientProperties.ConnectionType.TCP) { builder.addressSelector(BrokerAddressSelectors.TCP_ADDRESS); @@ -210,6 +209,7 @@ public BrokerClientConfigurer propertiesBasedBrokerClientConfigurer( }); } else if (connectionType == BrokerClientProperties.ConnectionType.WS) { builder.addressSelector(BrokerAddressSelectors.WEBSOCKET_ADDRESS); + builder.tags(tags); builder.clientTransportFactory( address -> { if (sslDisabled) { @@ -244,7 +244,10 @@ public BrokerClientConfigurer propertiesBasedBrokerClientConfigurer( } return builder - .tags(tags) + .keepalive(keepalive.isEnabled()) + .ackTimeoutSeconds(keepalive.getAckTimeoutSeconds()) + .tickPeriodSeconds(keepalive.getTickPeriodSeconds()) + .missedAcks(keepalive.getMissedAcks()) .accessKey(access.getKey()) .accessToken(access.getToken()) .group(brokerClientProperties.getGroup()) diff --git a/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientMessagingAutoConfiguration.java b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientMessagingAutoConfiguration.java index f9708e01..3021c2b7 100644 --- a/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientMessagingAutoConfiguration.java +++ b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientMessagingAutoConfiguration.java @@ -16,18 +16,22 @@ package com.netifi.spring.boot; -import java.util.Optional; - import com.netifi.broker.BrokerClient; import com.netifi.spring.messaging.BrokerClientRequesterMethodArgumentResolver; import com.netifi.spring.messaging.MessagingRSocketRequesterClientFactory; import io.micrometer.core.instrument.MeterRegistry; +import io.netty.buffer.ByteBufAllocator; +import io.netty.buffer.Unpooled; import io.opentracing.Tracer; import io.rsocket.AbstractRSocket; +import io.rsocket.ConnectionSetupPayload; import io.rsocket.RSocket; import io.rsocket.RSocketFactory; +import io.rsocket.frame.SetupFrameFlyweight; import io.rsocket.transport.netty.server.TcpServerTransport; +import java.time.Duration; +import java.util.Optional; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -50,55 +54,74 @@ * @since 1.7.0 */ @Configuration(proxyBeanMethods = false) -@ConditionalOnClass({ RSocketRequester.class, RSocketFactory.class, TcpServerTransport.class }) -@AutoConfigureAfter({ RSocketStrategiesAutoConfiguration.class, - BrokerClientAutoConfiguration.class }) +@ConditionalOnClass({RSocketRequester.class, RSocketFactory.class, TcpServerTransport.class}) +@AutoConfigureAfter({RSocketStrategiesAutoConfiguration.class, BrokerClientAutoConfiguration.class}) @EnableConfigurationProperties(BrokerClientMessagingProperties.class) public class BrokerClientMessagingAutoConfiguration { - private static final RSocket STUB_RSOCKET = new AbstractRSocket() {}; + private static final RSocket STUB_RSOCKET = new AbstractRSocket() {}; - @Bean - @ConditionalOnMissingBean - public MessageHandlerAcceptor messageHandlerAcceptor( - BrokerClientMessagingProperties properties, - DefaultListableBeanFactory factory, - RSocketStrategies rSocketStrategies, - BrokerClient brokerClient - ) { - MessageHandlerAcceptor acceptor = new MessageHandlerAcceptor(); - acceptor.setRSocketStrategies(rSocketStrategies); - acceptor.getArgumentResolverConfigurer() - .getCustomResolvers() - .removeIf(r -> r instanceof RSocketRequesterMethodArgumentResolver); + @Bean + @ConditionalOnMissingBean + public MessageHandlerAcceptor messageHandlerAcceptor( + BrokerClientProperties brokerClientProperties, + BrokerClientMessagingProperties properties, + DefaultListableBeanFactory factory, + RSocketStrategies rSocketStrategies, + BrokerClient brokerClient) { + BrokerClientProperties.KeepAliveProperties keepalive = + brokerClientProperties.getKeepalive(); + Duration tickPeriod = Duration.ofSeconds(keepalive.getTickPeriodSeconds()); + Duration ackTimeout = Duration.ofSeconds(keepalive.getAckTimeoutSeconds()); + int missedAcks = keepalive.getMissedAcks(); - acceptor.getArgumentResolverConfigurer() - .addCustomResolver(new BrokerClientRequesterMethodArgumentResolver( - properties.getName(), - brokerClient, - factory, - rSocketStrategies - )); + ConnectionSetupPayload connectionSetupPayload = + // FIXME: hardcoded mime for responder + ConnectionSetupPayload.create( + SetupFrameFlyweight.encode( + ByteBufAllocator.DEFAULT, + false, + (int) tickPeriod.toMillis(), + (int) (ackTimeout.toMillis() + tickPeriod.toMillis() * missedAcks), + Unpooled.EMPTY_BUFFER, + "text/plain", + "text/plain", + Unpooled.EMPTY_BUFFER, + Unpooled.EMPTY_BUFFER + ) + ); + MessageHandlerAcceptor acceptor = new MessageHandlerAcceptor(); + acceptor.setRSocketStrategies(rSocketStrategies); + acceptor + .getArgumentResolverConfigurer() + .getCustomResolvers() + .removeIf(r -> r instanceof RSocketRequesterMethodArgumentResolver); - brokerClient.addNamedRSocket(properties.getName(), acceptor.apply(STUB_RSOCKET)); + acceptor + .getArgumentResolverConfigurer() + .addCustomResolver( + new BrokerClientRequesterMethodArgumentResolver( + properties.getName(), brokerClient, factory, rSocketStrategies)); - return acceptor; - } + brokerClient.addNamedRSocket( + properties.getName(), + acceptor.apply(connectionSetupPayload, STUB_RSOCKET)); - @Bean - public MessagingRSocketRequesterClientFactory messagingRSocketRequesterClientFactory( - BrokerClientMessagingProperties properties, - BrokerClient brokerClient, - RSocketStrategies rSocketStrategies, - Optional registry, - Optional tracer) { - return new MessagingRSocketRequesterClientFactory( - properties.getName(), - brokerClient, - registry.orElse(null), - tracer.orElse(null), - rSocketStrategies - ); - } + return acceptor; + } + @Bean + public MessagingRSocketRequesterClientFactory messagingRSocketRequesterClientFactory( + BrokerClientMessagingProperties properties, + BrokerClient brokerClient, + RSocketStrategies rSocketStrategies, + Optional registry, + Optional tracer) { + return new MessagingRSocketRequesterClientFactory( + properties.getName(), + brokerClient, + registry.orElse(null), + tracer.orElse(null), + rSocketStrategies); + } } diff --git a/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientMessagingProperties.java b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientMessagingProperties.java index 57947229..2b01234f 100644 --- a/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientMessagingProperties.java +++ b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientMessagingProperties.java @@ -15,30 +15,26 @@ */ package com.netifi.spring.boot; -import javax.validation.constraints.Min; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; - import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.validation.annotation.Validated; /** - * Netifi Broker Client configuration options that can be set via the application - * properties files or system properties. + * Netifi Broker Client configuration options that can be set via the application properties files + * or system properties. */ @ConfigurationProperties("netifi.client.messaging") @Validated public class BrokerClientMessagingProperties { - @NotEmpty - @NotNull - private String name = "spring-messaging"; + @NotEmpty @NotNull private String name = "spring-messaging"; - public String getName() { - return name; - } + public String getName() { + return name; + } - public void setName(String name) { - this.name = name; - } + public void setName(String name) { + this.name = name; + } } diff --git a/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientProperties.java b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientProperties.java index b4f9997d..43715059 100644 --- a/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientProperties.java +++ b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientProperties.java @@ -50,11 +50,13 @@ public class BrokerClientProperties { @Valid private BrokerProperties broker = new BrokerProperties(); - private MetricsProperties metrics = new MetricsProperties(); + @Valid private MetricsProperties metrics = new MetricsProperties(); - private TracingProperties tracing = new TracingProperties(); + @Valid private TracingProperties tracing = new TracingProperties(); - private DiscoveryProperties discovery = new DiscoveryProperties(); + @Valid private DiscoveryProperties discovery = new DiscoveryProperties(); + + @Valid private KeepAliveProperties keepalive = new KeepAliveProperties(); public List getTags() { return tags; @@ -88,6 +90,10 @@ public DiscoveryProperties getDiscovery() { return discovery; } + public KeepAliveProperties getKeepalive() { + return keepalive; + } + public String getDestination() { return destination; } @@ -140,6 +146,47 @@ public enum ConnectionType { public static final class Tags {} + public static final class KeepAliveProperties { + + @NotNull + private Boolean enabled = true; + private long tickPeriodSeconds = 20; + private long ackTimeoutSeconds = 30; + private int missedAcks = 3; + + public long getAckTimeoutSeconds() { + return ackTimeoutSeconds; + } + + public int getMissedAcks() { + return missedAcks; + } + + public long getTickPeriodSeconds() { + return tickPeriodSeconds; + } + + public Boolean isEnabled() { + return enabled; + } + + public void setAckTimeoutSeconds(long ackTimeoutSeconds) { + this.ackTimeoutSeconds = ackTimeoutSeconds; + } + + public void setEnabled(Boolean enabled) { + this.enabled = enabled; + } + + public void setMissedAcks(int missedAcks) { + this.missedAcks = missedAcks; + } + + public void setTickPeriodSeconds(long tickPeriodSeconds) { + this.tickPeriodSeconds = tickPeriodSeconds; + } + } + public static final class SslProperties { @NotNull private Boolean disabled = false; diff --git a/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/SpringMessagingIntegrationTest.java b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/SpringMessagingIntegrationTest.java deleted file mode 100644 index 7c45ca39..00000000 --- a/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/SpringMessagingIntegrationTest.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.netifi.spring.boot; - -import com.netifi.spring.core.config.BrokerClientConfiguration; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.testcontainers.containers.GenericContainer; - -import org.springframework.boot.autoconfigure.ImportAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -@ExtendWith(SpringExtension.class) -@SpringBootTest -@DirtiesContext -@ImportAutoConfiguration({ - BrokerClientMessagingAutoConfiguration.class, - BrokerClientAutoConfiguration.class, - BrokerClientConfiguration.class, -}) -public class SpringMessagingIntegrationTest { - - @ClassRule - public static GenericContainer redis = - new GenericContainer("netifi/broker:1.6.2") - .withExposedPorts(8001, 7001, 6001, 8101) - .withEnv("BROKER_SERVER_OPTS", "-Dnetifi.broker.ssl.disabled=true " + - "-Dnetifi.authentication.0.accessKey=9007199254740991 " + - "-Dnetifi.authentication.0.accessToken=kTBDVtfRBO4tHOnZzSyY5ym2kfY= " + - "-Dnetifi.broker.admin.accessKey=9007199254740991 " + - "-Dnetifi.broker.admin.accessToken=kTBDVtfRBO4tHOnZzSyY5ym2kfY=" - ); - - - @Test - public void tests() { - - } - -} diff --git a/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/BrokerClientSpringIntegrationTest.java b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/BrokerClientSpringIntegrationTest.java similarity index 98% rename from netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/BrokerClientSpringIntegrationTest.java rename to netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/BrokerClientSpringIntegrationTest.java index d6a96c11..23b7d013 100644 --- a/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/BrokerClientSpringIntegrationTest.java +++ b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/BrokerClientSpringIntegrationTest.java @@ -13,11 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.netifi.spring.boot; +package com.netifi.spring.boot.test; import com.netifi.broker.info.BrokerInfoService; import com.netifi.broker.info.BrokerInfoServiceClient; import com.netifi.spring.DefaultExternalIdlClient; +import com.netifi.spring.boot.BrokerClientAutoConfiguration; import com.netifi.spring.core.BroadcastAwareClientFactory; import com.netifi.spring.core.DestinationAwareClientFactory; import com.netifi.spring.core.GroupAwareClientFactory; diff --git a/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/ClientConfigurationIntegrationTest.java b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/ClientConfigurationIntegrationTest.java similarity index 87% rename from netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/ClientConfigurationIntegrationTest.java rename to netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/ClientConfigurationIntegrationTest.java index b9b9df57..8a192423 100644 --- a/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/ClientConfigurationIntegrationTest.java +++ b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/ClientConfigurationIntegrationTest.java @@ -13,11 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.netifi.spring.boot; +package com.netifi.spring.boot.test; import static org.mockito.ArgumentMatchers.any; import com.netifi.broker.BrokerClient; +import com.netifi.spring.boot.BrokerClientAutoConfiguration; import com.netifi.spring.boot.support.BrokerClientConfigurer; import com.netifi.spring.core.config.BrokerClientConfiguration; import org.junit.jupiter.api.Assertions; @@ -27,19 +28,16 @@ import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.test.context.junit.jupiter.SpringExtension; @ExtendWith(SpringExtension.class) -@SpringBootTest -@ImportAutoConfiguration({ - ClientConfigurationIntegrationTest.TestConfiguration.class, - BrokerClientAutoConfiguration.class, - BrokerClientConfiguration.class, - ClientConfigurationIntegrationTest.TestConfiguration.class +@SpringBootTest(classes = { + ClientConfigurationIntegrationTest.TestConfiguration.class, + BrokerClientAutoConfiguration.class, + BrokerClientConfiguration.class }) public class ClientConfigurationIntegrationTest { diff --git a/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/DefaultClientTestIdl.java b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/DefaultClientTestIdl.java similarity index 97% rename from netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/DefaultClientTestIdl.java rename to netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/DefaultClientTestIdl.java index 6d913704..beca6579 100644 --- a/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/DefaultClientTestIdl.java +++ b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/DefaultClientTestIdl.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.netifi.spring.boot; +package com.netifi.spring.boot.test; import io.rsocket.rpc.annotations.internal.Generated; import io.rsocket.rpc.annotations.internal.ResourceType; diff --git a/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/MessageHandler.java b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/MessageHandler.java new file mode 100644 index 00000000..9e93a33a --- /dev/null +++ b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/MessageHandler.java @@ -0,0 +1,18 @@ +package com.netifi.spring.boot.test; + +import reactor.core.publisher.Mono; + +import org.springframework.core.io.buffer.DataBuffer; +import org.springframework.messaging.handler.annotation.MessageMapping; +import org.springframework.messaging.handler.annotation.Payload; +import org.springframework.stereotype.Controller; + +@Controller +@MessageMapping("test") +public class MessageHandler { + + @MessageMapping("process") + public Mono process(@Payload Mono data) { + return Mono.just("Echo: " + data); + } +} diff --git a/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/SpringMessagingIntegrationTest.java b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/SpringMessagingIntegrationTest.java new file mode 100644 index 00000000..e1f2c8be --- /dev/null +++ b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/SpringMessagingIntegrationTest.java @@ -0,0 +1,74 @@ +/* + * Copyright 2019 The Netifi Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.netifi.spring.boot.test; + +import com.netifi.spring.core.annotation.Group; +import org.junit.Assert; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.wait.strategy.HostPortWaitStrategy; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.containers.wait.strategy.WaitStrategy; +import org.testcontainers.containers.wait.strategy.WaitStrategyTarget; + +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.messaging.rsocket.RSocketRequester; +import org.springframework.test.context.event.annotation.BeforeTestClass; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +@ExtendWith(SpringExtension.class) +@SpringBootTest +//@TestPropertySource(locations="classpath:application.properties") +public class SpringMessagingIntegrationTest { + + public static GenericContainer redis = + new GenericContainer("netifi/broker:1.6.4") + .withExposedPorts(8001, 7001, 6001, 8101) + .withEnv( + "BROKER_SERVER_OPTS", + "-Dnetifi.authentication.0.accessKey=9007199254740991 " + + "-Dnetifi.authentication.0.accessToken=kTBDVtfRBO4tHOnZzSyY5ym2kfY= " + + "-Dnetifi.broker.admin.accessKey=9007199254740991 " + + "-Dnetifi.broker.admin.accessToken=kTBDVtfRBO4tHOnZzSyY5ym2kfY=" + ); + + + static { + redis.start(); + System.setProperty("netifi.client.broker.hostname", redis.getContainerIpAddress()); + System.setProperty("netifi.client.broker.port", + String.valueOf(redis.getMappedPort(8001))); + } + + @Group("com.netifi.client.demo.vowelcount") + RSocketRequester requester; + + @Test + public void tests() { + Assert.assertNotNull(requester.rsocket()); + + requester.route("test.process") + .data("test") + .retrieveMono(String.class) + .log() + .block(); + } +} diff --git a/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/TestApplication.java b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/TestApplication.java similarity index 66% rename from netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/TestApplication.java rename to netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/TestApplication.java index 7b175912..ddf3f9dd 100644 --- a/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/TestApplication.java +++ b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/TestApplication.java @@ -13,12 +13,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.netifi.spring.boot; +package com.netifi.spring.boot.test; + +import com.netifi.spring.boot.BrokerClientAutoConfiguration; +import com.netifi.spring.boot.BrokerClientMessagingAutoConfiguration; +import com.netifi.spring.core.config.BrokerClientConfiguration; import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication +@ImportAutoConfiguration({ + BrokerClientMessagingAutoConfiguration.class, + BrokerClientAutoConfiguration.class, + BrokerClientConfiguration.class, +}) public class TestApplication { public static void main(String[] args) { SpringApplication.run(TestApplication.class, args); diff --git a/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/TestIdl.java b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/TestIdl.java similarity index 94% rename from netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/TestIdl.java rename to netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/TestIdl.java index 74391aa3..a4c596e1 100644 --- a/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/TestIdl.java +++ b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/TestIdl.java @@ -13,6 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.netifi.spring.boot; +package com.netifi.spring.boot.test; public interface TestIdl {} diff --git a/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/TestIdlImpl.java b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/TestIdlImpl.java similarity index 95% rename from netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/TestIdlImpl.java rename to netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/TestIdlImpl.java index 0f27d8ab..7bfe28a7 100644 --- a/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/TestIdlImpl.java +++ b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/TestIdlImpl.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.netifi.spring.boot; +package com.netifi.spring.boot.test; import org.springframework.stereotype.Service; diff --git a/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/TestIdlServiceServer.java b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/TestIdlServiceServer.java similarity index 97% rename from netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/TestIdlServiceServer.java rename to netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/TestIdlServiceServer.java index d1ea8564..327144f8 100644 --- a/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/TestIdlServiceServer.java +++ b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/TestIdlServiceServer.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.netifi.spring.boot; +package com.netifi.spring.boot.test; import java.util.Map; diff --git a/netifi-spring-core/gradle/dependency-locks/compileClasspath.lockfile b/netifi-spring-core/gradle/dependency-locks/compileClasspath.lockfile index 73ea6494..115d13ec 100644 --- a/netifi-spring-core/gradle/dependency-locks/compileClasspath.lockfile +++ b/netifi-spring-core/gradle/dependency-locks/compileClasspath.lockfile @@ -18,8 +18,8 @@ io.netty:netty-transport-native-epoll:4.1.36.Final io.netty:netty-transport-native-unix-common:4.1.36.Final io.netty:netty-transport:4.1.36.Final io.opentracing:opentracing-api:0.31.0 -io.projectreactor.netty:reactor-netty:0.8.8.RELEASE -io.projectreactor:reactor-core:3.2.9.RELEASE +io.projectreactor.netty:reactor-netty:0.9.0.BUILD-SNAPSHOT +io.projectreactor:reactor-core:3.3.0.BUILD-SNAPSHOT io.rsocket.rpc:rsocket-rpc-core:0.2.18 io.rsocket:rsocket-core:1.0.0-RC5 io.rsocket:rsocket-transport-netty:1.0.0-RC5 @@ -30,9 +30,9 @@ org.hdrhistogram:HdrHistogram:2.1.10 org.latencyutils:LatencyUtils:2.0.3 org.reactivestreams:reactive-streams:1.0.2 org.slf4j:slf4j-api:1.7.25 -org.springframework:spring-aop:5.1.7.RELEASE -org.springframework:spring-beans:5.1.7.RELEASE -org.springframework:spring-context:5.1.7.RELEASE -org.springframework:spring-core:5.1.7.RELEASE -org.springframework:spring-expression:5.1.7.RELEASE -org.springframework:spring-jcl:5.1.7.RELEASE +org.springframework:spring-aop:5.2.0.BUILD-SNAPSHOT +org.springframework:spring-beans:5.2.0.BUILD-SNAPSHOT +org.springframework:spring-context:5.2.0.BUILD-SNAPSHOT +org.springframework:spring-core:5.2.0.BUILD-SNAPSHOT +org.springframework:spring-expression:5.2.0.BUILD-SNAPSHOT +org.springframework:spring-jcl:5.2.0.BUILD-SNAPSHOT diff --git a/netifi-spring-core/src/main/java/com/netifi/spring/core/BrokerClientFactorySupport.java b/netifi-spring-core/src/main/java/com/netifi/spring/core/BrokerClientFactorySupport.java index 32941d5e..673a2486 100644 --- a/netifi-spring-core/src/main/java/com/netifi/spring/core/BrokerClientFactorySupport.java +++ b/netifi-spring-core/src/main/java/com/netifi/spring/core/BrokerClientFactorySupport.java @@ -5,7 +5,7 @@ public interface BrokerClientFactorySupport { - boolean support(Class clazz); + boolean support(Class clazz); - T lookup(Class tClass, BrokerClient.Type type, String group, Tags tag); + T lookup(Class tClass, BrokerClient.Type type, String group, Tags tag); } diff --git a/netifi-spring-core/src/main/java/com/netifi/spring/core/DestinationAwareClientFactory.java b/netifi-spring-core/src/main/java/com/netifi/spring/core/DestinationAwareClientFactory.java index eb206409..f6adbe86 100644 --- a/netifi-spring-core/src/main/java/com/netifi/spring/core/DestinationAwareClientFactory.java +++ b/netifi-spring-core/src/main/java/com/netifi/spring/core/DestinationAwareClientFactory.java @@ -28,6 +28,7 @@ default T destination(String destination) { } default T destination(String destination, String group) { - return lookup(BrokerClient.Type.DESTINATION, group, Tags.of("com.netifi.destination", destination)); + return lookup( + BrokerClient.Type.DESTINATION, group, Tags.of("com.netifi.destination", destination)); } } diff --git a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BaseBrokerClientFactory.java b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BaseBrokerClientFactory.java index 76f1325f..4e19cb76 100644 --- a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BaseBrokerClientFactory.java +++ b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BaseBrokerClientFactory.java @@ -1,105 +1,95 @@ package com.netifi.spring.core.annotation; -import java.util.HashMap; -import java.util.Map; - import com.netifi.common.tags.Tags; import com.netifi.spring.core.BrokerClientFactory; import com.netifi.spring.core.BrokerClientFactorySupport; -import io.micrometer.core.instrument.MeterRegistry; -import io.opentracing.Tracer; +import java.util.HashMap; +import java.util.Map; public class BaseBrokerClientFactory implements BrokerClientFactory { - private final BrokerClientFactorySupport brokerClientFactorySupport; - private final BrokerClient.Type routeType; - private final String destination; - private final Class clientClass; - private final String group; - private final Tags tags; - private final Map instantiatedClients; + private final BrokerClientFactorySupport brokerClientFactorySupport; + private final BrokerClient.Type routeType; + private final String destination; + private final Class clientClass; + private final String group; + private final Tags tags; + private final Map instantiatedClients; - public BaseBrokerClientFactory( - BrokerClientFactorySupport brokerClientFactorySupport, - BrokerClient.Type routeType, - String destination, - Class clientClass, - String group, - Tags tags - ) { - this.brokerClientFactorySupport = brokerClientFactorySupport; - this.routeType = routeType; - this.destination = destination; - this.clientClass = clientClass; - this.group = group; - this.tags = tags; - this.instantiatedClients = new HashMap<>(); - } + public BaseBrokerClientFactory( + BrokerClientFactorySupport brokerClientFactorySupport, + BrokerClient.Type routeType, + String destination, + Class clientClass, + String group, + Tags tags) { + this.brokerClientFactorySupport = brokerClientFactorySupport; + this.routeType = routeType; + this.destination = destination; + this.clientClass = clientClass; + this.group = group; + this.tags = tags; + this.instantiatedClients = new HashMap<>(); + } - @Override - @SuppressWarnings("unchecked") - public T lookup(BrokerClient.Type type, - String methodGroup, - Tags methodTags) { - String key = key(type, methodGroup, methodTags); - T client; - if (instantiatedClients.containsKey(key)) { - client = (T) instantiatedClients.get(key); - } - else { - try { - client = (T) brokerClientFactorySupport.lookup(clientClass, type, - methodGroup, methodTags); - instantiatedClients.put(key, client); - } - catch (Exception e) { - throw new RuntimeException(String.format( - "Error instantiating Netifi Broker Client for '%s'", - clientClass.getSimpleName()), e); - } - } - return client; + @Override + @SuppressWarnings("unchecked") + public T lookup(BrokerClient.Type type, String methodGroup, Tags methodTags) { + String key = key(type, methodGroup, methodTags); + T client; + if (instantiatedClients.containsKey(key)) { + client = (T) instantiatedClients.get(key); + } else { + try { + client = (T) brokerClientFactorySupport.lookup(clientClass, type, methodGroup, methodTags); + instantiatedClients.put(key, client); + } catch (Exception e) { + throw new RuntimeException( + String.format( + "Error instantiating Netifi Broker Client for '%s'", clientClass.getSimpleName()), + e); + } } + return client; + } - @Override - public T lookup(BrokerClient.Type type, - String methodGroup, - String... methodTags) { - return lookup(type, methodGroup, Tags.of(methodTags)); - } + @Override + public T lookup(BrokerClient.Type type, String methodGroup, String... methodTags) { + return lookup(type, methodGroup, Tags.of(methodTags)); + } - @Override - public T lookup(BrokerClient.Type type) { - return lookup(type, group, tags); - } + @Override + public T lookup(BrokerClient.Type type) { + return lookup(type, group, tags); + } - @Override - public T lookup(BrokerClient.Type type, Tags methodTags) { - return lookup(type, group, methodTags); - } + @Override + public T lookup(BrokerClient.Type type, Tags methodTags) { + return lookup(type, group, methodTags); + } - @Override - public T lookup(String group, Tags tags) { - return lookup(routeType, group, tags); - } + @Override + public T lookup(String group, Tags tags) { + return lookup(routeType, group, tags); + } - @Override - public T lookup(String group, String... tags) { - return lookup(routeType, group, tags); - } + @Override + public T lookup(String group, String... tags) { + return lookup(routeType, group, tags); + } - @Override - public T lookup(Tags tags) { - return lookup(routeType, tags); - } + @Override + public T lookup(Tags tags) { + return lookup(routeType, tags); + } - @Override - public T lookup() { - return lookup(routeType); - } + @Override + public T lookup() { + return lookup(routeType); + } - //TODO: Do something smarter - private String key(BrokerClient.Type type, String group, Tags tags) { - return type.name() + group + destination + tags.hashCode(); - } + // TODO: Do something smarter + private String key(BrokerClient.Type type, String group, Tags tags) { + return type.name() + group + destination + tags.hashCode(); + } } diff --git a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClient.java b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClient.java index 2db47eda..9e68a797 100644 --- a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClient.java +++ b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClient.java @@ -1,23 +1,20 @@ /** * Copyright 2019 Netifi Inc. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + *

http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and + *

Unless required by applicable law or agreed to in writing, software distributed under the + * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ package com.netifi.spring.core.annotation; import com.netifi.spring.core.NoTagsSupplier; import com.netifi.spring.core.TagSupplier; - import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; @@ -25,26 +22,33 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.TYPE, - ElementType.ANNOTATION_TYPE}) +@Target({ + ElementType.FIELD, + ElementType.METHOD, + ElementType.PARAMETER, + ElementType.TYPE, + ElementType.ANNOTATION_TYPE +}) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited public @interface BrokerClient { - Type type() default Type.GROUP; + Type type() default Type.GROUP; - String destination() default ""; + String destination() default ""; - String group() default ""; + String group() default ""; - Class clientClass() default Void.class; + Class clientClass() default Void.class; - Class tagSupplier() default NoTagsSupplier.class; + Class tagSupplier() default NoTagsSupplier.class; - Tag[] tags() default {}; + Tag[] tags() default {}; - enum Type { - DESTINATION, GROUP, BROADCAST, - } + enum Type { + DESTINATION, + GROUP, + BROADCAST, + } } diff --git a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClientBeanDefinitionRegistryPostProcessor.java b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClientBeanDefinitionRegistryPostProcessor.java index 7098472b..5d6d0a88 100644 --- a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClientBeanDefinitionRegistryPostProcessor.java +++ b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClientBeanDefinitionRegistryPostProcessor.java @@ -15,17 +15,16 @@ */ package com.netifi.spring.core.annotation; -import java.util.ArrayList; -import java.util.List; - import com.netifi.spring.core.BrokerClientFactory; import com.netifi.spring.core.BrokerClientFactorySupport; import io.rsocket.rpc.RSocketRpcService; import io.rsocket.rpc.annotations.internal.Generated; import io.rsocket.rpc.annotations.internal.ResourceType; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - import org.springframework.beans.BeansException; import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition; import org.springframework.beans.factory.annotation.Qualifier; @@ -39,8 +38,11 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor; import org.springframework.beans.factory.support.DefaultListableBeanFactory; +import org.springframework.beans.factory.support.GenericBeanDefinition; +import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.context.annotation.ContextAnnotationAutowireCandidateResolver; import org.springframework.context.support.GenericApplicationContext; +import org.springframework.core.ResolvableType; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.core.type.AnnotationMetadata; @@ -57,11 +59,6 @@ public class BrokerClientBeanDefinitionRegistryPostProcessor public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException { DefaultListableBeanFactory beanFactory = unwrapDefaultListableBeanFactory(registry); - List brokerClientFactories = - new ArrayList<>(beanFactory.getBeansOfType(BrokerClientFactorySupport.class) - .values()); - - AnnotationAwareOrderComparator.sort(brokerClientFactories); beanFactory.setAutowireCandidateResolver( new ContextAnnotationAutowireCandidateResolver() { @@ -69,6 +66,11 @@ public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) @Override public Object getSuggestedValue(DependencyDescriptor descriptor) { + List brokerClientFactories = + new ArrayList<>(beanFactory.getBeansOfType(BrokerClientFactorySupport.class).values()); + + AnnotationAwareOrderComparator.sort(brokerClientFactories); + BrokerClient annotation = descriptor.getField() == null ? AnnotatedElementUtils.getMergedAnnotation( @@ -77,22 +79,28 @@ public Object getSuggestedValue(DependencyDescriptor descriptor) { descriptor.getAnnotatedElement(), BrokerClient.class); if (annotation != null) { + Class descriptorDeclaredType = descriptor.getDeclaredType(); String[] beanNamesForType = - beanFactory.getBeanNamesForType(descriptor.getDeclaredType()); + beanFactory.getBeanNamesForType(descriptorDeclaredType); for (String beanName : beanNamesForType) { BeanDefinition beanDefinition = beanFactory.getMergedBeanDefinition(beanName); - if (isAutowireCandidate(new BeanDefinitionHolder(beanDefinition, beanName), descriptor)) { + if (isAutowireCandidate( + new BeanDefinitionHolder(beanDefinition, beanName), descriptor)) { return BrokerClientStaticFactory.getBeanInstance( - beanFactory, descriptor.getResolvableType(), annotation, brokerClientFactories); + beanFactory, + resolveResolvableType(beanDefinition), + annotation, + brokerClientFactories); } } - Generated generated = descriptor.getDeclaredType().getAnnotation(Generated.class); + Generated generated = descriptorDeclaredType.getAnnotation(Generated.class); if ((generated != null && generated.type() == ResourceType.CLIENT) - || BrokerClientFactory.class.isAssignableFrom(descriptor.getDeclaredType())) { + || BrokerClientFactory.class.isAssignableFrom(descriptorDeclaredType) + || isSuportedByFactories(brokerClientFactories, descriptorDeclaredType)) { return BrokerClientStaticFactory.getBeanInstance( beanFactory, descriptor.getResolvableType(), annotation, brokerClientFactories); } @@ -110,6 +118,18 @@ public Object getSuggestedValue(DependencyDescriptor descriptor) { public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {} + private static boolean isSuportedByFactories( + Collection brokerClientFactories, + Class clazz + ) { + for (BrokerClientFactorySupport factory : brokerClientFactories) { + if (factory.support(clazz)) { + return true; + } + } + return false; + } + private static void processAllGeneratedBeanDefinitions(DefaultListableBeanFactory beanFactory) { for (String beanName : beanFactory.getBeanNamesForAnnotation(Generated.class)) { try { @@ -161,7 +181,8 @@ private static void processRSocketServiceBeanDefinitions(DefaultListableBeanFact } } - public static Class resolveClass(BeanDefinition beanDefinition) throws ClassNotFoundException { + private static Class resolveClass(BeanDefinition beanDefinition) + throws ClassNotFoundException { Class clazz = null; if (beanDefinition.getBeanClassName() != null) { @@ -182,6 +203,17 @@ public static Class resolveClass(BeanDefinition beanDefinition) throws ClassN return clazz; } + private static ResolvableType resolveResolvableType(BeanDefinition beanDefinition) { + + if (beanDefinition instanceof RootBeanDefinition) { + return ((RootBeanDefinition) beanDefinition).getResolvableType(); + } else if (beanDefinition instanceof GenericBeanDefinition) { + return ResolvableType.forClass(((GenericBeanDefinition) beanDefinition).getBeanClass()); + } + + throw new IllegalArgumentException("Impossible to resolve bean type"); + } + private static boolean findRealImplementationAndMarkAsPrimary( DefaultListableBeanFactory beanFactory, Class clazz) { diff --git a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClientStaticFactory.java b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClientStaticFactory.java index 5c50c7b1..dac66236 100644 --- a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClientStaticFactory.java +++ b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClientStaticFactory.java @@ -1,40 +1,35 @@ /** * Copyright 2019 Netifi Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and + * + *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software distributed under the + * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing permissions and * limitations under the License. */ - package com.netifi.spring.core.annotation; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.util.Collection; - import com.netifi.broker.rsocket.BrokerSocket; import com.netifi.common.tags.Tags; import com.netifi.spring.core.BroadcastAwareClientFactory; +import com.netifi.spring.core.BrokerClientFactory; import com.netifi.spring.core.BrokerClientFactorySupport; import com.netifi.spring.core.DestinationAwareClientFactory; import com.netifi.spring.core.GroupAwareClientFactory; import com.netifi.spring.core.NoTagsSupplier; -import com.netifi.spring.core.BrokerClientFactory; import com.netifi.spring.core.TagSupplier; import io.micrometer.core.instrument.MeterRegistry; import io.opentracing.Tracer; import io.rsocket.RSocket; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.Collection; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - import org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.config.AutowireCapableBeanFactory; @@ -49,309 +44,281 @@ */ public class BrokerClientStaticFactory { - private static final Logger LOGGER = - LoggerFactory.getLogger(BrokerClientStaticFactory.class); - - /** - * Creates an instance of the correct Netifi Broker client for injection into a - * annotated field. - * - * @return an instance of a {@link com.netifi.broker.BrokerClient} client - */ - public static Object getBeanInstance(final DefaultListableBeanFactory beanFactory, - final ResolvableType targetClass, - final BrokerClient brokerClientAnnotation, - final Collection brokerClientFactories - ) { - final Class resolvedTargetClass = targetClass.toClass(); - final String beanName = getBeanName(brokerClientAnnotation, resolvedTargetClass); - - if (!beanFactory.containsBean(beanName)) { - final Tags suppliedTags = resolveTags(beanFactory, brokerClientAnnotation); - - Object toRegister = null; - try { -// String[] tracerSupplierBeanNames = -// beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics( -// Supplier.class, -// Tracer.class)); -// String[] meterRegistrySupplierBeanNames = -// beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics( -// Supplier.class, -// MeterRegistry.class)); -// -// Tracer tracer = null; -// MeterRegistry meterRegistry = null; -// -// // Tracers -// if (tracerSupplierBeanNames.length >= 1) { -// if (tracerSupplierBeanNames.length > 1) { -// LOGGER.warn( -// "More than one implementation of Tracer detected on the classpath. Arbitrarily choosing one to use."); -// } -// -// Supplier tracerSupplier = -// (Supplier) beanFactory.getBean(tracerSupplierBeanNames[0]); -// tracer = tracerSupplier.get(); -// } -// -// // Meter Registries -// if (meterRegistrySupplierBeanNames.length >= 1) { -// if (meterRegistrySupplierBeanNames.length > 1) { -// LOGGER.warn( -// "More than one implementation of MeterRegistry detected on the classpath. Arbitrarily choosing one to use."); -// } -// -// Supplier meterRegistrySupplier = -// (Supplier) beanFactory.getBean( -// meterRegistrySupplierBeanNames[0]); -// meterRegistry = meterRegistrySupplier.get(); -// } -// else { -// // Fallback to MeterRegistry implementations on the classpath if we can't find any suppliers -// Map meterRegistryBeans = -// beanFactory.getBeansOfType(MeterRegistry.class); -// -// if (!meterRegistryBeans.isEmpty()) { -// if (meterRegistryBeans.size() > 1) { -// LOGGER.warn( -// "More than one implementation of MeterRegistry detected on the classpath. Arbitrarily choosing one to use."); -// } -// -// meterRegistry = (MeterRegistry) meterRegistryBeans.values() -// .toArray()[0]; -// } -// } - - if (BrokerClientFactory.class.isAssignableFrom(resolvedTargetClass)) { - Class clientClass = brokerClientAnnotation.clientClass(); - - if (clientClass.equals(Void.class)) { - ResolvableType clientResolvableType = targetClass.getGeneric(0); - - if (clientResolvableType == ResolvableType.NONE) { - throw new RuntimeException( - "Instantiating BrokerClientFactory requires target client class"); - } - - clientClass = clientResolvableType.toClass(); - } - - for (BrokerClientFactorySupport brokerClientFactory : - brokerClientFactories) { - if (brokerClientFactory.support(clientClass)) { - toRegister = createBrokerClientFactory( - clientClass, - resolvedTargetClass, - brokerClientFactory, - brokerClientAnnotation.type(), - brokerClientAnnotation.group(), - brokerClientAnnotation.destination(), - suppliedTags - ); - } - } - } - else { - for (BrokerClientFactorySupport brokerClientFactory : brokerClientFactories) { - if (brokerClientFactory.support(resolvedTargetClass)) { - toRegister = - brokerClientFactory.lookup( - resolvedTargetClass, - brokerClientAnnotation.type(), - brokerClientAnnotation.group(), - suppliedTags - ); - break; - } - } - } - } - catch (Exception e) { - throw new RuntimeException(String.format("Error injecting bean '%s'", targetClass), e); + private static final Logger LOGGER = LoggerFactory.getLogger(BrokerClientStaticFactory.class); + + /** + * Creates an instance of the correct Netifi Broker client for injection into a annotated field. + * + * @return an instance of a {@link com.netifi.broker.BrokerClient} client + */ + public static Object getBeanInstance( + final DefaultListableBeanFactory beanFactory, + final ResolvableType targetClass, + final BrokerClient brokerClientAnnotation, + final Collection brokerClientFactories) { + final Class resolvedTargetClass = targetClass.toClass(); + final String beanName = getBeanName(brokerClientAnnotation, resolvedTargetClass); + + if (!beanFactory.containsBean(beanName)) { + final Tags suppliedTags = resolveTags(beanFactory, brokerClientAnnotation); + + Object toRegister = null; + try { + // String[] tracerSupplierBeanNames = + // beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics( + // Supplier.class, + // Tracer.class)); + // String[] meterRegistrySupplierBeanNames = + // beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics( + // Supplier.class, + // MeterRegistry.class)); + // + // Tracer tracer = null; + // MeterRegistry meterRegistry = null; + // + // // Tracers + // if (tracerSupplierBeanNames.length >= 1) { + // if (tracerSupplierBeanNames.length > 1) { + // LOGGER.warn( + // "More than one implementation of Tracer detected on the + // classpath. Arbitrarily choosing one to use."); + // } + // + // Supplier tracerSupplier = + // (Supplier) + // beanFactory.getBean(tracerSupplierBeanNames[0]); + // tracer = tracerSupplier.get(); + // } + // + // // Meter Registries + // if (meterRegistrySupplierBeanNames.length >= 1) { + // if (meterRegistrySupplierBeanNames.length > 1) { + // LOGGER.warn( + // "More than one implementation of MeterRegistry detected on the + // classpath. Arbitrarily choosing one to use."); + // } + // + // Supplier meterRegistrySupplier = + // (Supplier) beanFactory.getBean( + // meterRegistrySupplierBeanNames[0]); + // meterRegistry = meterRegistrySupplier.get(); + // } + // else { + // // Fallback to MeterRegistry implementations on the classpath if we + // can't find any suppliers + // Map meterRegistryBeans = + // beanFactory.getBeansOfType(MeterRegistry.class); + // + // if (!meterRegistryBeans.isEmpty()) { + // if (meterRegistryBeans.size() > 1) { + // LOGGER.warn( + // "More than one implementation of MeterRegistry detected on + // the classpath. Arbitrarily choosing one to use."); + // } + // + // meterRegistry = (MeterRegistry) meterRegistryBeans.values() + // .toArray()[0]; + // } + // } + + if (BrokerClientFactory.class.isAssignableFrom(resolvedTargetClass)) { + Class clientClass = brokerClientAnnotation.clientClass(); + + if (clientClass.equals(Void.class)) { + ResolvableType clientResolvableType = targetClass.getGeneric(0); + + if (clientResolvableType == ResolvableType.NONE) { + throw new RuntimeException( + "Instantiating BrokerClientFactory requires target client class"); } - if (toRegister == null) { - throw new RuntimeException(String.format("Unsupported bean '%s'", targetClass)); + clientClass = clientResolvableType.toClass(); + } + + for (BrokerClientFactorySupport brokerClientFactory : brokerClientFactories) { + if (brokerClientFactory.support(clientClass)) { + toRegister = + createBrokerClientFactory( + clientClass, + resolvedTargetClass, + brokerClientFactory, + brokerClientAnnotation.type(), + brokerClientAnnotation.group(), + brokerClientAnnotation.destination(), + suppliedTags); + } + } + } else { + for (BrokerClientFactorySupport brokerClientFactory : brokerClientFactories) { + if (brokerClientFactory.support(resolvedTargetClass)) { + toRegister = + brokerClientFactory.lookup( + resolvedTargetClass, + brokerClientAnnotation.type(), + brokerClientAnnotation.group(), + suppliedTags); + break; } + } + } + } catch (Exception e) { + throw new RuntimeException(String.format("Error injecting bean '%s'", targetClass), e); + } - Object newInstance = beanFactory.initializeBean(toRegister, beanName); - beanFactory.autowireBeanProperties(newInstance, - AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, - true); - AnnotatedGenericBeanDefinition beanDefinition = - new AnnotatedGenericBeanDefinition(resolvedTargetClass); - AutowireCandidateQualifier qualifier = - new AutowireCandidateQualifier(Qualifier.class); + if (toRegister == null) { + throw new RuntimeException(String.format("Unsupported bean '%s'", targetClass)); + } - qualifier.setAttribute("value", "client"); - beanDefinition.addQualifier(qualifier); + Object newInstance = beanFactory.initializeBean(toRegister, beanName); + beanFactory.autowireBeanProperties( + newInstance, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, true); + AnnotatedGenericBeanDefinition beanDefinition = + new AnnotatedGenericBeanDefinition(resolvedTargetClass); + AutowireCandidateQualifier qualifier = new AutowireCandidateQualifier(Qualifier.class); - beanFactory.registerBeanDefinition(beanName, beanDefinition); - beanFactory.registerSingleton(beanName, newInstance); + qualifier.setAttribute("value", "client"); + beanDefinition.addQualifier(qualifier); - LOGGER.debug("Bean named '{}' created successfully.", beanName); + beanFactory.registerBeanDefinition(beanName, beanDefinition); + beanFactory.registerSingleton(beanName, newInstance); - return newInstance; - } - else { - LOGGER.debug( - "Bean named '{}' already exists, using as current bean reference.", - beanName); - return beanFactory.getBean(beanName); - } - } - - public static Tags resolveTags( - DefaultListableBeanFactory beanFactory, - BrokerClient brokerClientAnnotation) { - //Tags reconciliation - TagSupplier tagSupplier = NoTagsSupplier.INSTANCE; - brokerClientAnnotation.tagSupplier(); - if (!brokerClientAnnotation.tagSupplier() - .equals(NoTagsSupplier.class)) { - tagSupplier = beanFactory.getBean(brokerClientAnnotation.tagSupplier()); - } + LOGGER.debug("Bean named '{}' created successfully.", beanName); - Tags suppliedTags = tagSupplier.get(); - for (Tag t : brokerClientAnnotation.tags()) { - if (!suppliedTags.stream() - .anyMatch(tag -> tag.getKey() - .equals(t.name()))) { - suppliedTags = - suppliedTags.and(com.netifi.common.tags.Tag.of(t.name(), - t.value())); - } - } - return suppliedTags; + return newInstance; + } else { + LOGGER.debug("Bean named '{}' already exists, using as current bean reference.", beanName); + return beanFactory.getBean(beanName); } - - /** - * Generates a unique bean name for the field. - * - * @param brokerClientAnnotation annotation data - * @param clazz target class - * @return bean name - */ - private static String getBeanName(BrokerClient brokerClientAnnotation, - Class clazz) { - Assert.hasText(brokerClientAnnotation.group(), - "@BrokerClient.group() must be specified"); - - String beanName = clazz.getSimpleName() + "_" + brokerClientAnnotation - .type() - .toString() - .toLowerCase() + "_" + brokerClientAnnotation.group(); - - if (!StringUtils.isEmpty(brokerClientAnnotation.destination())) { - beanName += "_" + brokerClientAnnotation.destination(); - } - - return beanName; + } + + public static Tags resolveTags( + DefaultListableBeanFactory beanFactory, BrokerClient brokerClientAnnotation) { + // Tags reconciliation + TagSupplier tagSupplier = NoTagsSupplier.INSTANCE; + brokerClientAnnotation.tagSupplier(); + if (!brokerClientAnnotation.tagSupplier().equals(NoTagsSupplier.class)) { + tagSupplier = beanFactory.getBean(brokerClientAnnotation.tagSupplier()); } - static T createBrokerClient(com.netifi.broker.BrokerClient brokerClient, - BrokerClient.Type routeType, - String group, - String destination, - Tags tags, - Tracer tracer, - MeterRegistry meterRegistry, - Class clientClass) - throws NoSuchMethodException, InstantiationException, IllegalAccessException, - InvocationTargetException { - // Creating default BrokerSocket Instance - BrokerSocket brokerSocket = createBrokerRSocket(brokerClient, routeType, group, destination, tags); - - T toRegister; - - if (tracer == null && meterRegistry == null) { - // No Tracer or MeterRegistry - Constructor ctor = clientClass.getConstructor(RSocket.class); - toRegister = (T) ctor.newInstance(brokerSocket); - } - else if (tracer != null && meterRegistry == null) { - // Tracer Only - Constructor ctor = clientClass.getConstructor(RSocket.class, Tracer.class); - toRegister = (T) ctor.newInstance(brokerSocket, tracer); - } - else if (tracer == null && meterRegistry != null) { - // MeterRegistry Only - Constructor ctor = - clientClass.getConstructor(RSocket.class, MeterRegistry.class); - toRegister = (T) ctor.newInstance(brokerSocket, meterRegistry); - } - else { - // Both Tracer and MeterRegistry - Constructor ctor = clientClass.getConstructor( - RSocket.class, - MeterRegistry.class, - Tracer.class - ); - toRegister = (T) ctor.newInstance(brokerSocket, meterRegistry, tracer); - } - return toRegister; + Tags suppliedTags = tagSupplier.get(); + for (Tag t : brokerClientAnnotation.tags()) { + if (!suppliedTags.stream().anyMatch(tag -> tag.getKey().equals(t.name()))) { + suppliedTags = suppliedTags.and(com.netifi.common.tags.Tag.of(t.name(), t.value())); + } } - - public static BrokerSocket createBrokerRSocket( - com.netifi.broker.BrokerClient brokerClient, - BrokerClient.Type routeType, - String group, - String destination, - Tags tags - ) { - BrokerSocket brokerSocket = null; - - switch (routeType) { - case BROADCAST: - brokerSocket = brokerClient.broadcastServiceSocket(group, tags); - break; - case GROUP: - brokerSocket = brokerClient.groupServiceSocket(group, tags); - break; - case DESTINATION: - brokerSocket = brokerClient.groupServiceSocket( - group, - StringUtils.isEmpty(destination) - ? tags - : Tags.of("com.netifi.destination", destination) - .and(tags) - ); - break; - } - return brokerSocket; + return suppliedTags; + } + + /** + * Generates a unique bean name for the field. + * + * @param brokerClientAnnotation annotation data + * @param clazz target class + * @return bean name + */ + private static String getBeanName(BrokerClient brokerClientAnnotation, Class clazz) { + Assert.hasText(brokerClientAnnotation.group(), "@BrokerClient.group() must be specified"); + + String beanName = + clazz.getSimpleName() + + "_" + + brokerClientAnnotation.type().toString().toLowerCase() + + "_" + + brokerClientAnnotation.group(); + + if (!StringUtils.isEmpty(brokerClientAnnotation.destination())) { + beanName += "_" + brokerClientAnnotation.destination(); } - public static BrokerClientFactory createBrokerClientFactory( - Class clientClass, - Class targetClass, - BrokerClientFactorySupport brokerClientFactorySupport, - BrokerClient.Type routeType, - String group, - String destination, - Tags tags - ) { - - final BaseBrokerClientFactory brokerClientFactory = - new BaseBrokerClientFactory<>( - brokerClientFactorySupport, - routeType, - destination, - clientClass, + return beanName; + } + + static T createBrokerClient( + com.netifi.broker.BrokerClient brokerClient, + BrokerClient.Type routeType, + String group, + String destination, + Tags tags, + Tracer tracer, + MeterRegistry meterRegistry, + Class clientClass) + throws NoSuchMethodException, InstantiationException, IllegalAccessException, + InvocationTargetException { + // Creating default BrokerSocket Instance + BrokerSocket brokerSocket = + createBrokerRSocket(brokerClient, routeType, group, destination, tags); + + T toRegister; + + if (tracer == null && meterRegistry == null) { + // No Tracer or MeterRegistry + Constructor ctor = clientClass.getConstructor(RSocket.class); + toRegister = (T) ctor.newInstance(brokerSocket); + } else if (tracer != null && meterRegistry == null) { + // Tracer Only + Constructor ctor = clientClass.getConstructor(RSocket.class, Tracer.class); + toRegister = (T) ctor.newInstance(brokerSocket, tracer); + } else if (tracer == null && meterRegistry != null) { + // MeterRegistry Only + Constructor ctor = clientClass.getConstructor(RSocket.class, MeterRegistry.class); + toRegister = (T) ctor.newInstance(brokerSocket, meterRegistry); + } else { + // Both Tracer and MeterRegistry + Constructor ctor = + clientClass.getConstructor(RSocket.class, MeterRegistry.class, Tracer.class); + toRegister = (T) ctor.newInstance(brokerSocket, meterRegistry, tracer); + } + return toRegister; + } + + public static BrokerSocket createBrokerRSocket( + com.netifi.broker.BrokerClient brokerClient, + BrokerClient.Type routeType, + String group, + String destination, + Tags tags) { + BrokerSocket brokerSocket = null; + + switch (routeType) { + case BROADCAST: + brokerSocket = brokerClient.broadcastServiceSocket(group, tags); + break; + case GROUP: + brokerSocket = brokerClient.groupServiceSocket(group, tags); + break; + case DESTINATION: + brokerSocket = + brokerClient.groupServiceSocket( group, - tags - ); - - if (targetClass.isAssignableFrom(GroupAwareClientFactory.class)) { - return new DefaultGroupAwareClientFactory<>(brokerClientFactory); - } - else if (targetClass.isAssignableFrom(DestinationAwareClientFactory.class)) { - return new DefaultDestinationAwareClientFactory<>(brokerClientFactory); - } - else if (targetClass.isAssignableFrom(BroadcastAwareClientFactory.class)) { - return new DefaultBroadcastAwareClientFactory<>(brokerClientFactory); - } - - return brokerClientFactory; + StringUtils.isEmpty(destination) + ? tags + : Tags.of("com.netifi.destination", destination).and(tags)); + break; } + return brokerSocket; + } + + public static BrokerClientFactory createBrokerClientFactory( + Class clientClass, + Class targetClass, + BrokerClientFactorySupport brokerClientFactorySupport, + BrokerClient.Type routeType, + String group, + String destination, + Tags tags) { + + final BaseBrokerClientFactory brokerClientFactory = + new BaseBrokerClientFactory<>( + brokerClientFactorySupport, routeType, destination, clientClass, group, tags); + + if (targetClass.isAssignableFrom(GroupAwareClientFactory.class)) { + return new DefaultGroupAwareClientFactory<>(brokerClientFactory); + } else if (targetClass.isAssignableFrom(DestinationAwareClientFactory.class)) { + return new DefaultDestinationAwareClientFactory<>(brokerClientFactory); + } else if (targetClass.isAssignableFrom(BroadcastAwareClientFactory.class)) { + return new DefaultBroadcastAwareClientFactory<>(brokerClientFactory); + } + + return brokerClientFactory; + } } diff --git a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/DefaultBroadcastAwareClientFactory.java b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/DefaultBroadcastAwareClientFactory.java index ab87a451..9d4e7c9d 100644 --- a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/DefaultBroadcastAwareClientFactory.java +++ b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/DefaultBroadcastAwareClientFactory.java @@ -4,56 +4,51 @@ import com.netifi.spring.core.BroadcastAwareClientFactory; import com.netifi.spring.core.BrokerClientFactory; -class DefaultBroadcastAwareClientFactory - implements BroadcastAwareClientFactory { - - private final BrokerClientFactory baseFactory; - - DefaultBroadcastAwareClientFactory(BrokerClientFactory factory) { - baseFactory = factory; - } - - @Override - public T lookup(BrokerClient.Type type, - String group, - Tags tags) { - return baseFactory.lookup(type, group, tags); - } - - @Override - public T lookup(BrokerClient.Type type, - String group, - String... tags) { - return baseFactory.lookup(type, group, tags); - } - - @Override - public T lookup(BrokerClient.Type type) { - return baseFactory.lookup(type); - } - - @Override - public T lookup(BrokerClient.Type type, Tags tags) { - return baseFactory.lookup(type, tags); - } - - @Override - public T lookup(String group, Tags tag) { - return baseFactory.lookup(group, tag); - } - - @Override - public T lookup(String group, String... tags) { - return baseFactory.lookup(group, tags); - } - - @Override - public T lookup(Tags tags) { - return baseFactory.lookup(tags); - } - - @Override - public T lookup() { - return baseFactory.lookup(); - } +class DefaultBroadcastAwareClientFactory implements BroadcastAwareClientFactory { + + private final BrokerClientFactory baseFactory; + + DefaultBroadcastAwareClientFactory(BrokerClientFactory factory) { + baseFactory = factory; + } + + @Override + public T lookup(BrokerClient.Type type, String group, Tags tags) { + return baseFactory.lookup(type, group, tags); + } + + @Override + public T lookup(BrokerClient.Type type, String group, String... tags) { + return baseFactory.lookup(type, group, tags); + } + + @Override + public T lookup(BrokerClient.Type type) { + return baseFactory.lookup(type); + } + + @Override + public T lookup(BrokerClient.Type type, Tags tags) { + return baseFactory.lookup(type, tags); + } + + @Override + public T lookup(String group, Tags tag) { + return baseFactory.lookup(group, tag); + } + + @Override + public T lookup(String group, String... tags) { + return baseFactory.lookup(group, tags); + } + + @Override + public T lookup(Tags tags) { + return baseFactory.lookup(tags); + } + + @Override + public T lookup() { + return baseFactory.lookup(); + } } diff --git a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/DefaultDestinationAwareClientFactory.java b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/DefaultDestinationAwareClientFactory.java index cfd7c514..0b5d1dda 100644 --- a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/DefaultDestinationAwareClientFactory.java +++ b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/DefaultDestinationAwareClientFactory.java @@ -4,56 +4,51 @@ import com.netifi.spring.core.BrokerClientFactory; import com.netifi.spring.core.DestinationAwareClientFactory; -class DefaultDestinationAwareClientFactory - implements DestinationAwareClientFactory { - - private final BrokerClientFactory baseFactory; - - DefaultDestinationAwareClientFactory(BrokerClientFactory factory) { - baseFactory = factory; - } - - @Override - public T lookup(BrokerClient.Type type, - String group, - Tags tags) { - return baseFactory.lookup(type, group, tags); - } - - @Override - public T lookup(BrokerClient.Type type, - String group, - String... tags) { - return baseFactory.lookup(type, group, tags); - } - - @Override - public T lookup(BrokerClient.Type type) { - return baseFactory.lookup(type); - } - - @Override - public T lookup(BrokerClient.Type type, Tags tags) { - return baseFactory.lookup(type, tags); - } - - @Override - public T lookup(String group, Tags tag) { - return baseFactory.lookup(group, tag); - } - - @Override - public T lookup(String group, String... tags) { - return baseFactory.lookup(group, tags); - } - - @Override - public T lookup(Tags tags) { - return baseFactory.lookup(tags); - } - - @Override - public T lookup() { - return baseFactory.lookup(); - } +class DefaultDestinationAwareClientFactory implements DestinationAwareClientFactory { + + private final BrokerClientFactory baseFactory; + + DefaultDestinationAwareClientFactory(BrokerClientFactory factory) { + baseFactory = factory; + } + + @Override + public T lookup(BrokerClient.Type type, String group, Tags tags) { + return baseFactory.lookup(type, group, tags); + } + + @Override + public T lookup(BrokerClient.Type type, String group, String... tags) { + return baseFactory.lookup(type, group, tags); + } + + @Override + public T lookup(BrokerClient.Type type) { + return baseFactory.lookup(type); + } + + @Override + public T lookup(BrokerClient.Type type, Tags tags) { + return baseFactory.lookup(type, tags); + } + + @Override + public T lookup(String group, Tags tag) { + return baseFactory.lookup(group, tag); + } + + @Override + public T lookup(String group, String... tags) { + return baseFactory.lookup(group, tags); + } + + @Override + public T lookup(Tags tags) { + return baseFactory.lookup(tags); + } + + @Override + public T lookup() { + return baseFactory.lookup(); + } } diff --git a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/DefaultGroupAwareClientFactory.java b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/DefaultGroupAwareClientFactory.java index 1619944a..e4b9c752 100644 --- a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/DefaultGroupAwareClientFactory.java +++ b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/DefaultGroupAwareClientFactory.java @@ -4,56 +4,51 @@ import com.netifi.spring.core.BrokerClientFactory; import com.netifi.spring.core.GroupAwareClientFactory; -public class DefaultGroupAwareClientFactory - implements GroupAwareClientFactory { - - private final BrokerClientFactory baseFactory; - - DefaultGroupAwareClientFactory(BrokerClientFactory factory) { - baseFactory = factory; - } - - @Override - public T lookup(BrokerClient.Type type, - String group, - Tags tags) { - return baseFactory.lookup(type, group, tags); - } - - @Override - public T lookup(BrokerClient.Type type, - String group, - String... tags) { - return baseFactory.lookup(type, group, tags); - } - - @Override - public T lookup(BrokerClient.Type type) { - return baseFactory.lookup(type); - } - - @Override - public T lookup(BrokerClient.Type type, Tags tags) { - return baseFactory.lookup(type, tags); - } - - @Override - public T lookup(String group, Tags tag) { - return baseFactory.lookup(group, tag); - } - - @Override - public T lookup(String group, String... tags) { - return baseFactory.lookup(group, tags); - } - - @Override - public T lookup(Tags tags) { - return baseFactory.lookup(tags); - } - - @Override - public T lookup() { - return baseFactory.lookup(); - } +public class DefaultGroupAwareClientFactory implements GroupAwareClientFactory { + + private final BrokerClientFactory baseFactory; + + DefaultGroupAwareClientFactory(BrokerClientFactory factory) { + baseFactory = factory; + } + + @Override + public T lookup(BrokerClient.Type type, String group, Tags tags) { + return baseFactory.lookup(type, group, tags); + } + + @Override + public T lookup(BrokerClient.Type type, String group, String... tags) { + return baseFactory.lookup(type, group, tags); + } + + @Override + public T lookup(BrokerClient.Type type) { + return baseFactory.lookup(type); + } + + @Override + public T lookup(BrokerClient.Type type, Tags tags) { + return baseFactory.lookup(type, tags); + } + + @Override + public T lookup(String group, Tags tag) { + return baseFactory.lookup(group, tag); + } + + @Override + public T lookup(String group, String... tags) { + return baseFactory.lookup(group, tags); + } + + @Override + public T lookup(Tags tags) { + return baseFactory.lookup(tags); + } + + @Override + public T lookup() { + return baseFactory.lookup(); + } } diff --git a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/RpcBrokerClientFactorySupport.java b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/RpcBrokerClientFactorySupport.java index 07edf790..292fc87f 100644 --- a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/RpcBrokerClientFactorySupport.java +++ b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/RpcBrokerClientFactorySupport.java @@ -4,45 +4,43 @@ import com.netifi.spring.core.BrokerClientFactorySupport; import io.micrometer.core.instrument.MeterRegistry; import io.opentracing.Tracer; +import io.rsocket.RSocket; public class RpcBrokerClientFactorySupport implements BrokerClientFactorySupport { - private final com.netifi.broker.BrokerClient brokerClient; - private final Tracer tracer; - private final MeterRegistry meterRegistry; + private final com.netifi.broker.BrokerClient brokerClient; + private final Tracer tracer; + private final MeterRegistry meterRegistry; - public RpcBrokerClientFactorySupport(com.netifi.broker.BrokerClient client, - MeterRegistry registry, - Tracer tracer) { - brokerClient = client; - this.tracer = tracer; - meterRegistry = registry; - } + public RpcBrokerClientFactorySupport( + com.netifi.broker.BrokerClient client, MeterRegistry registry, Tracer tracer) { + brokerClient = client; + this.tracer = tracer; + meterRegistry = registry; + } - @Override - public boolean support(Class clazz) { - return true; + @Override + public boolean support(Class clazz) { + boolean thereIsRSocketConstructor; + try { + clazz.getConstructor(RSocket.class); + thereIsRSocketConstructor = true; + } catch (NoSuchMethodException e) { + thereIsRSocketConstructor = false; } + return !clazz.isInterface() && thereIsRSocketConstructor; + } - @Override - public T lookup(Class clientClass, BrokerClient.Type type, String group, Tags tag) { - try { - return BrokerClientStaticFactory - .createBrokerClient( - brokerClient, - type, - group, - null, - tag, - tracer, - meterRegistry, - clientClass - ); - } - catch (Exception e) { - throw new RuntimeException(String.format( - "Error instantiating Netifi Broker Client for '%s'", - clientClass.getSimpleName()), e); - } + @Override + public T lookup(Class clientClass, BrokerClient.Type type, String group, Tags tag) { + try { + return BrokerClientStaticFactory.createBrokerClient( + brokerClient, type, group, null, tag, tracer, meterRegistry, clientClass); + } catch (Exception e) { + throw new RuntimeException( + String.format( + "Error instantiating Netifi Broker Client for '%s'", clientClass.getSimpleName()), + e); } + } } diff --git a/netifi-spring-core/src/main/java/com/netifi/spring/core/config/BrokerClientConfiguration.java b/netifi-spring-core/src/main/java/com/netifi/spring/core/config/BrokerClientConfiguration.java index 65ed3f9a..23522d53 100644 --- a/netifi-spring-core/src/main/java/com/netifi/spring/core/config/BrokerClientConfiguration.java +++ b/netifi-spring-core/src/main/java/com/netifi/spring/core/config/BrokerClientConfiguration.java @@ -19,8 +19,8 @@ import com.netifi.broker.info.BrokerInfoService; import com.netifi.broker.info.BrokerInfoServiceClient; import com.netifi.broker.info.BrokerInfoServiceServer; +import com.netifi.common.tags.Tags; import com.netifi.spring.core.BrokerClientApplicationEventListener; -import com.netifi.spring.core.annotation.BaseBrokerClientFactory; import com.netifi.spring.core.annotation.BrokerClientBeanDefinitionRegistryPostProcessor; import com.netifi.spring.core.annotation.RpcBrokerClientFactorySupport; import io.micrometer.core.instrument.MeterRegistry; @@ -37,16 +37,16 @@ import org.springframework.context.annotation.AnnotatedBeanDefinitionReader; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.core.annotation.Order; @Configuration public class BrokerClientConfiguration implements ApplicationContextAware { @Bean public RpcBrokerClientFactorySupport rpcBrokerClientFactorySupport( - BrokerClient brokerClient, - Optional registry, - Optional tracer) { - return new RpcBrokerClientFactorySupport(brokerClient, registry.orElse(null), tracer.orElse(null)); + BrokerClient brokerClient, Optional registry, Optional tracer) { + return new RpcBrokerClientFactorySupport( + brokerClient, registry.orElse(null), tracer.orElse(null)); } @Bean(name = "internalBrokerClientBeanDefinitionRegistryPostProcessor") diff --git a/netifi-spring-messaging/build.gradle b/netifi-spring-messaging/build.gradle index 94254f9b..06f75503 100644 --- a/netifi-spring-messaging/build.gradle +++ b/netifi-spring-messaging/build.gradle @@ -11,7 +11,7 @@ dependencyManagement { } dependencies { - implementation project(":netifi-spring-core") + compile project(":netifi-spring-core") implementation "com.netifi:netifi-common" implementation "com.netifi:netifi-broker-client" diff --git a/netifi-spring-messaging/gradle/dependency-locks/compileClasspath.lockfile b/netifi-spring-messaging/gradle/dependency-locks/compileClasspath.lockfile index 641efe79..ad181116 100644 --- a/netifi-spring-messaging/gradle/dependency-locks/compileClasspath.lockfile +++ b/netifi-spring-messaging/gradle/dependency-locks/compileClasspath.lockfile @@ -4,25 +4,25 @@ com.google.protobuf:protobuf-java:3.6.1 com.typesafe:config:1.3.3 io.micrometer:micrometer-core:1.0.6 -io.netty:netty-buffer:4.1.34.Final -io.netty:netty-codec-http2:4.1.34.Final -io.netty:netty-codec-http:4.1.34.Final -io.netty:netty-codec-socks:4.1.34.Final -io.netty:netty-codec:4.1.34.Final -io.netty:netty-common:4.1.34.Final -io.netty:netty-handler-proxy:4.1.34.Final -io.netty:netty-handler:4.1.34.Final -io.netty:netty-resolver:4.1.34.Final -io.netty:netty-tcnative:2.0.18.Final -io.netty:netty-transport-native-epoll:4.1.34.Final -io.netty:netty-transport-native-unix-common:4.1.34.Final -io.netty:netty-transport:4.1.34.Final +io.netty:netty-buffer:4.1.36.Final +io.netty:netty-codec-http2:4.1.36.Final +io.netty:netty-codec-http:4.1.36.Final +io.netty:netty-codec-socks:4.1.36.Final +io.netty:netty-codec:4.1.36.Final +io.netty:netty-common:4.1.36.Final +io.netty:netty-handler-proxy:4.1.36.Final +io.netty:netty-handler:4.1.36.Final +io.netty:netty-resolver:4.1.36.Final +io.netty:netty-tcnative:2.0.25.Final +io.netty:netty-transport-native-epoll:4.1.36.Final +io.netty:netty-transport-native-unix-common:4.1.36.Final +io.netty:netty-transport:4.1.36.Final io.opentracing:opentracing-api:0.31.0 io.projectreactor.netty:reactor-netty:0.9.0.BUILD-SNAPSHOT io.projectreactor:reactor-core:3.3.0.BUILD-SNAPSHOT -io.rsocket.rpc:rsocket-rpc-core:0.2.13.3 -io.rsocket:rsocket-core:0.11.17.2 -io.rsocket:rsocket-transport-netty:0.11.17.2 +io.rsocket.rpc:rsocket-rpc-core:0.2.18 +io.rsocket:rsocket-core:0.12.2-RC3 +io.rsocket:rsocket-transport-netty:0.12.2-RC3 javax.annotation:javax.annotation-api:1.3.2 javax.inject:javax.inject:1 javax.validation:validation-api:2.0.1.Final diff --git a/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/BrokerClientRequesterMethodArgumentResolver.java b/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/BrokerClientRequesterMethodArgumentResolver.java index 0e7ebb85..db7d9830 100644 --- a/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/BrokerClientRequesterMethodArgumentResolver.java +++ b/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/BrokerClientRequesterMethodArgumentResolver.java @@ -16,10 +16,13 @@ package com.netifi.spring.messaging; +import static com.netifi.spring.core.annotation.BrokerClientStaticFactory.resolveTags; +import static com.netifi.spring.messaging.RSocketRequesterStaticFactory.createRSocketRequester; +import static com.netifi.spring.messaging.RSocketRequesterStaticFactory.resolveBrokerClientRSocket; +import static org.springframework.core.annotation.AnnotatedElementUtils.getMergedAnnotation; + import com.netifi.broker.BrokerClient; import io.rsocket.RSocket; -import reactor.core.publisher.Mono; - import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.core.MethodParameter; import org.springframework.messaging.Message; @@ -27,78 +30,69 @@ import org.springframework.messaging.rsocket.RSocketRequester; import org.springframework.messaging.rsocket.RSocketStrategies; import org.springframework.util.Assert; - -import static com.netifi.spring.core.annotation.BrokerClientStaticFactory.resolveTags; -import static com.netifi.spring.messaging.RSocketRequesterStaticFactory.createRSocketRequester; -import static com.netifi.spring.messaging.RSocketRequesterStaticFactory.resolveBrokerClientRSocket; -import static org.springframework.core.annotation.AnnotatedElementUtils.getMergedAnnotation; +import reactor.core.publisher.Mono; /** - * Resolves arguments of type {@link RSocket} that can be used for making - * requests to the remote peer. + * Resolves arguments of type {@link RSocket} that can be used for making requests to the remote + * peer. * * @author Rossen Stoyanchev * @since 5.2 */ -public class BrokerClientRequesterMethodArgumentResolver - implements HandlerMethodArgumentResolver { - - private final String rSocketName; - private final BrokerClient brokerClient; - private final DefaultListableBeanFactory listableBeanFactory; - private final RSocketStrategies rSocketStrategies; +public class BrokerClientRequesterMethodArgumentResolver implements HandlerMethodArgumentResolver { - public BrokerClientRequesterMethodArgumentResolver( - String rSocketName, - BrokerClient client, - DefaultListableBeanFactory factory, - RSocketStrategies strategies - ) { - this.rSocketName = rSocketName; - brokerClient = client; - listableBeanFactory = factory; - rSocketStrategies = strategies; - } + private final String rSocketName; + private final BrokerClient brokerClient; + private final DefaultListableBeanFactory listableBeanFactory; + private final RSocketStrategies rSocketStrategies; - @Override - public boolean supportsParameter(MethodParameter parameter) { - Class type = parameter.getParameterType(); - return (RSocketRequester.class.equals(type) || RSocket.class.isAssignableFrom(type)); - } + public BrokerClientRequesterMethodArgumentResolver( + String rSocketName, + BrokerClient client, + DefaultListableBeanFactory factory, + RSocketStrategies strategies) { + this.rSocketName = rSocketName; + brokerClient = client; + listableBeanFactory = factory; + rSocketStrategies = strategies; + } - @Override - public Mono resolveArgument(MethodParameter parameter, Message message) { - Class type = parameter.getParameterType(); - com.netifi.spring.core.annotation.BrokerClient brokerClientAnnotation = - getMergedAnnotation(parameter.getParameter(), com.netifi.spring.core.annotation.BrokerClient.class); + @Override + public boolean supportsParameter(MethodParameter parameter) { + Class type = parameter.getParameterType(); + return (RSocketRequester.class.equals(type) || RSocket.class.isAssignableFrom(type)); + } - Assert.notNull( - brokerClientAnnotation, - "Incorrect Method Parameter, make sure your parameter is annotated with the @BrokerClient annotation" - ); + @Override + public Mono resolveArgument(MethodParameter parameter, Message message) { + Class type = parameter.getParameterType(); + com.netifi.spring.core.annotation.BrokerClient brokerClientAnnotation = + getMergedAnnotation( + parameter.getParameter(), com.netifi.spring.core.annotation.BrokerClient.class); - if (RSocketRequester.class.equals(type)) { - return Mono.just(createRSocketRequester( - rSocketName, - brokerClient, - brokerClientAnnotation, - resolveTags(listableBeanFactory, brokerClientAnnotation), - rSocketStrategies - )); - } - else if (RSocket.class.isAssignableFrom(type)) { - return Mono.just(resolveBrokerClientRSocket( - rSocketName, - brokerClient, - brokerClientAnnotation.type(), - brokerClientAnnotation.group(), - brokerClientAnnotation.destination(), - resolveTags(listableBeanFactory, brokerClientAnnotation) - )); - } - else { - return Mono.error(new IllegalArgumentException("Unexpected parameter type: " + parameter)); - } - } + Assert.notNull( + brokerClientAnnotation, + "Incorrect Method Parameter, make sure your parameter is annotated with the @BrokerClient annotation"); + if (RSocketRequester.class.equals(type)) { + return Mono.just( + createRSocketRequester( + rSocketName, + brokerClient, + brokerClientAnnotation, + resolveTags(listableBeanFactory, brokerClientAnnotation), + rSocketStrategies)); + } else if (RSocket.class.isAssignableFrom(type)) { + return Mono.just( + resolveBrokerClientRSocket( + rSocketName, + brokerClient, + brokerClientAnnotation.type(), + brokerClientAnnotation.group(), + brokerClientAnnotation.destination(), + resolveTags(listableBeanFactory, brokerClientAnnotation))); + } else { + return Mono.error(new IllegalArgumentException("Unexpected parameter type: " + parameter)); + } + } } diff --git a/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/MessagingRSocketRequesterClientFactory.java b/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/MessagingRSocketRequesterClientFactory.java index f6e0d977..e4c5b457 100644 --- a/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/MessagingRSocketRequesterClientFactory.java +++ b/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/MessagingRSocketRequesterClientFactory.java @@ -1,52 +1,47 @@ package com.netifi.spring.messaging; +import static com.netifi.spring.messaging.RSocketRequesterStaticFactory.createRSocketRequester; + import com.netifi.common.tags.Tags; import com.netifi.spring.core.BrokerClientFactorySupport; import com.netifi.spring.core.annotation.BrokerClient; import io.micrometer.core.instrument.MeterRegistry; import io.opentracing.Tracer; - import org.springframework.messaging.rsocket.RSocketRequester; import org.springframework.messaging.rsocket.RSocketStrategies; -import static com.netifi.spring.messaging.RSocketRequesterStaticFactory.createRSocketRequester; - public class MessagingRSocketRequesterClientFactory implements BrokerClientFactorySupport { - private final String rSocketName; - private final com.netifi.broker.BrokerClient brokerClient; - private final Tracer tracer; - private final MeterRegistry meterRegistry; - private final RSocketStrategies rSocketStrategies; - - public MessagingRSocketRequesterClientFactory( - String rSocketName, - com.netifi.broker.BrokerClient brokerClient, - MeterRegistry meterRegistry, - Tracer tracer, - RSocketStrategies strategies - ) { - this.rSocketName = rSocketName; - this.brokerClient = brokerClient; - this.tracer = tracer; - this.meterRegistry = meterRegistry; - this.rSocketStrategies = strategies; - } - - @Override - public boolean support(Class clazz) { - return clazz.equals(RSocketRequester.class) || RSocketRequester.class.isAssignableFrom(clazz); - } - - @Override - @SuppressWarnings("unchecked") - public T lookup( - Class tClass, - BrokerClient.Type type, - String methodGroup, - Tags methodTags - ) { - return (T) createRSocketRequester( + private final String rSocketName; + private final com.netifi.broker.BrokerClient brokerClient; + private final Tracer tracer; + private final MeterRegistry meterRegistry; + private final RSocketStrategies rSocketStrategies; + + public MessagingRSocketRequesterClientFactory( + String rSocketName, + com.netifi.broker.BrokerClient brokerClient, + MeterRegistry meterRegistry, + Tracer tracer, + RSocketStrategies strategies) { + this.rSocketName = rSocketName; + this.brokerClient = brokerClient; + this.tracer = tracer; + this.meterRegistry = meterRegistry; + this.rSocketStrategies = strategies; + } + + @Override + public boolean support(Class clazz) { + return clazz.equals(RSocketRequester.class) || RSocketRequester.class.isAssignableFrom(clazz); + } + + @Override + @SuppressWarnings("unchecked") + public T lookup( + Class tClass, BrokerClient.Type type, String methodGroup, Tags methodTags) { + return (T) + createRSocketRequester( rSocketName, brokerClient, type, @@ -55,7 +50,6 @@ public T lookup( methodTags, rSocketStrategies, meterRegistry, - tracer - ); - } + tracer); + } } diff --git a/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/MetricsAwareRSocketRequester.java b/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/MetricsAwareRSocketRequester.java index 6cea01b7..ec0aabd4 100644 --- a/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/MetricsAwareRSocketRequester.java +++ b/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/MetricsAwareRSocketRequester.java @@ -5,147 +5,152 @@ import io.rsocket.RSocket; import io.rsocket.rpc.metrics.Metrics; import org.reactivestreams.Publisher; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; - import org.springframework.core.ParameterizedTypeReference; import org.springframework.messaging.rsocket.RSocketRequester; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; public class MetricsAwareRSocketRequester implements RSocketRequester { - private final RSocketRequester rSocketRequester; + private final RSocketRequester rSocketRequester; + private final MeterRegistry registry; + private final Tracer tracer; + + public MetricsAwareRSocketRequester( + RSocketRequester requester, MeterRegistry meterRegistry, Tracer tracer) { + this.rSocketRequester = requester; + this.registry = meterRegistry; + this.tracer = tracer; + } + + @Override + public RSocket rsocket() { + return rSocketRequester.rsocket(); + } + + @Override + public RequestSpec route(String route) { + return new MetricsAwareRequestSpec(rSocketRequester.route(route), route, registry, tracer); + } + + private static final class MetricsAwareRequestSpec implements RequestSpec { + + private final RequestSpec requestSpec; + private final String route; + private final MeterRegistry registry; + private final Tracer tracer; + + private MetricsAwareRequestSpec( + RequestSpec spec, String route, MeterRegistry registry, Tracer tracer) { + this.requestSpec = spec; + this.route = route; + this.registry = registry; + this.tracer = tracer; + } + + @Override + public ResponseSpec data(Object data) { + return requestSpec.data(data); + } + + @Override + public > ResponseSpec data(P publisher, Class dataType) { + return requestSpec.data(publisher, dataType); + } + + @Override + public > ResponseSpec data( + P publisher, ParameterizedTypeReference dataTypeRef) { + return requestSpec.data(publisher, dataTypeRef); + } + } + + private static final class MetricsAwareResponseSepc implements ResponseSpec { + + private final ResponseSpec responseSpec; + private final String route; private final MeterRegistry registry; private final Tracer tracer; - public MetricsAwareRSocketRequester( - RSocketRequester requester, - MeterRegistry meterRegistry, - Tracer tracer - ) { - this.rSocketRequester = requester; - this.registry = meterRegistry; - this.tracer = tracer; + private MetricsAwareResponseSepc( + ResponseSpec spec, String route, MeterRegistry registry, Tracer tracer) { + this.responseSpec = spec; + this.route = route; + this.registry = registry; + this.tracer = tracer; } @Override - public RSocket rsocket() { - return rSocketRequester.rsocket(); + public Mono send() { + return responseSpec + .send() + .transform( + Metrics.timed( + registry, "rsocket.spring.client", "route", route, "call.type", "send")); } @Override - public RequestSpec route(String route) { - return new MetricsAwareRequestSpec(rSocketRequester.route(route), route, - registry, - tracer); + public Mono retrieveMono(Class dataType) { + return responseSpec + .retrieveMono(dataType) + .transform( + Metrics.timed( + registry, + "rsocket.spring.client", + "route", + route, + "call.type", + "retrieveMono", + "data.type", + dataType.getName())); } - private static final class MetricsAwareRequestSpec implements RequestSpec { - - private final RequestSpec requestSpec; - private final String route; - private final MeterRegistry registry; - private final Tracer tracer; - - private MetricsAwareRequestSpec(RequestSpec spec, - String route, - MeterRegistry registry, - Tracer tracer) { - this.requestSpec = spec; - this.route = route; - this.registry = registry; - this.tracer = tracer; - } - - @Override - public ResponseSpec data(Object data) { - return requestSpec.data(data); - } - - @Override - public > ResponseSpec data(P publisher, Class dataType) { - return requestSpec.data(publisher, dataType); - } - - @Override - public > ResponseSpec data(P publisher, ParameterizedTypeReference dataTypeRef) { - return requestSpec.data(publisher, dataTypeRef); - } + @Override + public Mono retrieveMono(ParameterizedTypeReference dataTypeRef) { + return responseSpec + .retrieveMono(dataTypeRef) + .transform( + Metrics.timed( + registry, + "rsocket.spring.client", + "route", + route, + "call.type", + "retrieveMono", + "data.type", + dataTypeRef.getType().getTypeName())); } - private static final class MetricsAwareResponseSepc implements ResponseSpec { - - private final ResponseSpec responseSpec; - private final String route; - private final MeterRegistry registry; - private final Tracer tracer; - - private MetricsAwareResponseSepc(ResponseSpec spec, - String route, - MeterRegistry registry, - Tracer tracer) { - this.responseSpec = spec; - this.route = route; - this.registry = registry; - this.tracer = tracer; - } - - @Override - public Mono send() { - return responseSpec - .send() - .transform(Metrics.timed( - registry, "rsocket.spring.client", - "route", route, - "call.type", "send" - )); - } - - @Override - public Mono retrieveMono(Class dataType) { - return responseSpec - .retrieveMono(dataType) - .transform(Metrics.timed( - registry, "rsocket.spring.client", - "route", route, - "call.type", "retrieveMono", - "data.type", dataType.getName() - )); - } - - @Override - public Mono retrieveMono(ParameterizedTypeReference dataTypeRef) { - return responseSpec - .retrieveMono(dataTypeRef) - .transform(Metrics.timed( - registry, "rsocket.spring.client", - "route", route, - "call.type", "retrieveMono", - "data.type", dataTypeRef.getType().getTypeName() - )); - } - - @Override - public Flux retrieveFlux(Class dataType) { - return responseSpec - .retrieveFlux(dataType) - .transform(Metrics.timed( - registry, "rsocket.spring.client", - "route", route, - "call.type", "retrieveFlux", - "data.type", dataType.getName() - )); - } - - @Override - public Flux retrieveFlux(ParameterizedTypeReference dataTypeRef) { - return responseSpec - .retrieveFlux(dataTypeRef) - .transform(Metrics.timed( - registry, "rsocket.spring.client", - "route", route, - "call.type", "retrieveFlux", - "data.type", dataTypeRef.getType().getTypeName() - )); - } + @Override + public Flux retrieveFlux(Class dataType) { + return responseSpec + .retrieveFlux(dataType) + .transform( + Metrics.timed( + registry, + "rsocket.spring.client", + "route", + route, + "call.type", + "retrieveFlux", + "data.type", + dataType.getName())); + } + + @Override + public Flux retrieveFlux(ParameterizedTypeReference dataTypeRef) { + return responseSpec + .retrieveFlux(dataTypeRef) + .transform( + Metrics.timed( + registry, + "rsocket.spring.client", + "route", + route, + "call.type", + "retrieveFlux", + "data.type", + dataTypeRef.getType().getTypeName())); } + } } diff --git a/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/RSocketRequesterStaticFactory.java b/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/RSocketRequesterStaticFactory.java index 6cff6124..84c37c97 100644 --- a/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/RSocketRequesterStaticFactory.java +++ b/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/RSocketRequesterStaticFactory.java @@ -7,69 +7,60 @@ import com.netifi.spring.core.annotation.BrokerClientStaticFactory; import io.micrometer.core.instrument.MeterRegistry; import io.opentracing.Tracer; - import org.springframework.messaging.rsocket.RSocketRequester; import org.springframework.messaging.rsocket.RSocketStrategies; class RSocketRequesterStaticFactory { - static RSocketRequester createRSocketRequester( - String rSocketName, - BrokerClient brokerClient, - com.netifi.spring.core.annotation.BrokerClient brokerClientAnnotation, - Tags tags, - RSocketStrategies rSocketStrategies) { - return RSocketRequester.create( - resolveBrokerClientRSocket( - rSocketName, - brokerClient, - brokerClientAnnotation.type(), - brokerClientAnnotation.group(), - brokerClientAnnotation.destination(), - tags - ), - null, - rSocketStrategies - ); - } + static RSocketRequester createRSocketRequester( + String rSocketName, + BrokerClient brokerClient, + com.netifi.spring.core.annotation.BrokerClient brokerClientAnnotation, + Tags tags, + RSocketStrategies rSocketStrategies) { + return RSocketRequester.create( + resolveBrokerClientRSocket( + rSocketName, + brokerClient, + brokerClientAnnotation.type(), + brokerClientAnnotation.group(), + brokerClientAnnotation.destination(), + tags), + null, + rSocketStrategies); + } - static RSocketRequester createRSocketRequester( - String rSocketName, - BrokerClient brokerClient, - com.netifi.spring.core.annotation.BrokerClient.Type routingType, - String group, - String destination, - Tags tags, - RSocketStrategies rSocketStrategies, - MeterRegistry meterRegistry, - Tracer tracer - ) { + static RSocketRequester createRSocketRequester( + String rSocketName, + BrokerClient brokerClient, + com.netifi.spring.core.annotation.BrokerClient.Type routingType, + String group, + String destination, + Tags tags, + RSocketStrategies rSocketStrategies, + MeterRegistry meterRegistry, + Tracer tracer) { - return new MetricsAwareRSocketRequester( - RSocketRequester.create( - resolveBrokerClientRSocket(rSocketName, brokerClient, routingType, group, destination, tags), - null, - rSocketStrategies - ), - meterRegistry, - tracer - ); - } + return new MetricsAwareRSocketRequester( + RSocketRequester.wrap( + resolveBrokerClientRSocket( + rSocketName, brokerClient, routingType, group, destination, tags), + null, + rSocketStrategies), + meterRegistry, + tracer); + } - static BrokerSocket resolveBrokerClientRSocket( - String rSocketName, - BrokerClient brokerClient, - com.netifi.spring.core.annotation.BrokerClient.Type routingType, - String group, - String destination, - Tags tags - ) { - return NamedRSocketClientWrapper.wrap(rSocketName, BrokerClientStaticFactory.createBrokerRSocket( - brokerClient, - routingType, - group, - destination, - tags - )); - } + static BrokerSocket resolveBrokerClientRSocket( + String rSocketName, + BrokerClient brokerClient, + com.netifi.spring.core.annotation.BrokerClient.Type routingType, + String group, + String destination, + Tags tags) { + return NamedRSocketClientWrapper.wrap( + rSocketName, + BrokerClientStaticFactory.createBrokerRSocket( + brokerClient, routingType, group, destination, tags)); + } } From e025d14ece4a6801e56707cec1fabbf116c21197 Mon Sep 17 00:00:00 2001 From: Oleh Dokuka Date: Thu, 6 Jun 2019 00:21:31 +0200 Subject: [PATCH 6/9] google format and test fixes --- .../boot/BrokerClientAutoConfiguration.java | 1 - ...rokerClientMessagingAutoConfiguration.java | 11 ++----- .../spring/boot/BrokerClientProperties.java | 9 +++--- .../BrokerClientSpringIntegrationTest.java | 6 ---- .../ClientConfigurationIntegrationTest.java | 12 ++++---- .../spring/boot/test/MessageHandler.java | 27 ++++++++++++----- .../test/SpringMessagingIntegrationTest.java | 30 ++++--------------- .../spring/boot/test/TestApplication.java | 7 ++--- ...ntBeanDefinitionRegistryPostProcessor.java | 10 +++---- .../config/BrokerClientConfiguration.java | 1 - 10 files changed, 46 insertions(+), 68 deletions(-) diff --git a/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientAutoConfiguration.java b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientAutoConfiguration.java index f54acffb..f8ad09b6 100644 --- a/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientAutoConfiguration.java +++ b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientAutoConfiguration.java @@ -35,7 +35,6 @@ import io.rsocket.transport.netty.client.WebsocketClientTransport; import java.util.List; import java.util.Optional; - import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor; import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; diff --git a/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientMessagingAutoConfiguration.java b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientMessagingAutoConfiguration.java index 3021c2b7..51412f11 100644 --- a/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientMessagingAutoConfiguration.java +++ b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientMessagingAutoConfiguration.java @@ -29,7 +29,6 @@ import io.rsocket.RSocketFactory; import io.rsocket.frame.SetupFrameFlyweight; import io.rsocket.transport.netty.server.TcpServerTransport; - import java.time.Duration; import java.util.Optional; import org.springframework.beans.factory.support.DefaultListableBeanFactory; @@ -69,8 +68,7 @@ public MessageHandlerAcceptor messageHandlerAcceptor( DefaultListableBeanFactory factory, RSocketStrategies rSocketStrategies, BrokerClient brokerClient) { - BrokerClientProperties.KeepAliveProperties keepalive = - brokerClientProperties.getKeepalive(); + BrokerClientProperties.KeepAliveProperties keepalive = brokerClientProperties.getKeepalive(); Duration tickPeriod = Duration.ofSeconds(keepalive.getTickPeriodSeconds()); Duration ackTimeout = Duration.ofSeconds(keepalive.getAckTimeoutSeconds()); int missedAcks = keepalive.getMissedAcks(); @@ -87,9 +85,7 @@ public MessageHandlerAcceptor messageHandlerAcceptor( "text/plain", "text/plain", Unpooled.EMPTY_BUFFER, - Unpooled.EMPTY_BUFFER - ) - ); + Unpooled.EMPTY_BUFFER)); MessageHandlerAcceptor acceptor = new MessageHandlerAcceptor(); acceptor.setRSocketStrategies(rSocketStrategies); acceptor @@ -104,8 +100,7 @@ public MessageHandlerAcceptor messageHandlerAcceptor( properties.getName(), brokerClient, factory, rSocketStrategies)); brokerClient.addNamedRSocket( - properties.getName(), - acceptor.apply(connectionSetupPayload, STUB_RSOCKET)); + properties.getName(), acceptor.apply(connectionSetupPayload, STUB_RSOCKET)); return acceptor; } diff --git a/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientProperties.java b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientProperties.java index 43715059..6305ce56 100644 --- a/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientProperties.java +++ b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientProperties.java @@ -148,11 +148,10 @@ public static final class Tags {} public static final class KeepAliveProperties { - @NotNull - private Boolean enabled = true; - private long tickPeriodSeconds = 20; - private long ackTimeoutSeconds = 30; - private int missedAcks = 3; + @NotNull private Boolean enabled = true; + private long tickPeriodSeconds = 20; + private long ackTimeoutSeconds = 30; + private int missedAcks = 3; public long getAckTimeoutSeconds() { return ackTimeoutSeconds; diff --git a/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/BrokerClientSpringIntegrationTest.java b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/BrokerClientSpringIntegrationTest.java index 23b7d013..71993379 100644 --- a/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/BrokerClientSpringIntegrationTest.java +++ b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/BrokerClientSpringIntegrationTest.java @@ -46,12 +46,6 @@ @ExtendWith(SpringExtension.class) @SpringBootTest -@DirtiesContext -@ImportAutoConfiguration({ - BrokerClientAutoConfiguration.class, - BrokerClientConfiguration.class, - BrokerClientSpringIntegrationTest.TestConfiguration.class -}) public class BrokerClientSpringIntegrationTest { @Autowired ConfigurableListableBeanFactory beanFactory; diff --git a/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/ClientConfigurationIntegrationTest.java b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/ClientConfigurationIntegrationTest.java index 8a192423..ad4daa00 100644 --- a/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/ClientConfigurationIntegrationTest.java +++ b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/ClientConfigurationIntegrationTest.java @@ -34,19 +34,19 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; @ExtendWith(SpringExtension.class) -@SpringBootTest(classes = { - ClientConfigurationIntegrationTest.TestConfiguration.class, - BrokerClientAutoConfiguration.class, - BrokerClientConfiguration.class -}) +@SpringBootTest public class ClientConfigurationIntegrationTest { @Autowired @Qualifier("mock2") BrokerClientConfigurer configurer; + @Autowired + BrokerClient brokerClient; + @Test public void testThatConfigurerWorks() { + Assertions.assertNotNull(brokerClient); ArgumentCaptor captor = ArgumentCaptor.forClass(BrokerClient.CustomizableBuilder.class); @@ -56,7 +56,7 @@ public void testThatConfigurerWorks() { } @org.springframework.boot.test.context.TestConfiguration - @ComponentScan +// @ComponentScan static class TestConfiguration { @Bean diff --git a/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/MessageHandler.java b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/MessageHandler.java index 9e93a33a..022146b3 100644 --- a/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/MessageHandler.java +++ b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/MessageHandler.java @@ -1,18 +1,31 @@ +/* + * Copyright 2019 The Netifi Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.netifi.spring.boot.test; -import reactor.core.publisher.Mono; - -import org.springframework.core.io.buffer.DataBuffer; import org.springframework.messaging.handler.annotation.MessageMapping; import org.springframework.messaging.handler.annotation.Payload; import org.springframework.stereotype.Controller; +import reactor.core.publisher.Mono; @Controller @MessageMapping("test") public class MessageHandler { - @MessageMapping("process") - public Mono process(@Payload Mono data) { - return Mono.just("Echo: " + data); - } + @MessageMapping("process") + public Mono process(@Payload Mono data) { + return Mono.just("Echo: " + data); + } } diff --git a/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/SpringMessagingIntegrationTest.java b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/SpringMessagingIntegrationTest.java index e1f2c8be..55111375 100644 --- a/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/SpringMessagingIntegrationTest.java +++ b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/SpringMessagingIntegrationTest.java @@ -17,26 +17,15 @@ import com.netifi.spring.core.annotation.Group; import org.junit.Assert; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.testcontainers.containers.GenericContainer; -import org.testcontainers.containers.wait.strategy.HostPortWaitStrategy; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.containers.wait.strategy.WaitStrategy; -import org.testcontainers.containers.wait.strategy.WaitStrategyTarget; - import org.springframework.boot.test.context.SpringBootTest; import org.springframework.messaging.rsocket.RSocketRequester; -import org.springframework.test.context.event.annotation.BeforeTestClass; import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.testcontainers.containers.GenericContainer; @ExtendWith(SpringExtension.class) @SpringBootTest -//@TestPropertySource(locations="classpath:application.properties") public class SpringMessagingIntegrationTest { public static GenericContainer redis = @@ -45,17 +34,14 @@ public class SpringMessagingIntegrationTest { .withEnv( "BROKER_SERVER_OPTS", "-Dnetifi.authentication.0.accessKey=9007199254740991 " - + "-Dnetifi.authentication.0.accessToken=kTBDVtfRBO4tHOnZzSyY5ym2kfY= " - + "-Dnetifi.broker.admin.accessKey=9007199254740991 " - + "-Dnetifi.broker.admin.accessToken=kTBDVtfRBO4tHOnZzSyY5ym2kfY=" - ); - + + "-Dnetifi.authentication.0.accessToken=kTBDVtfRBO4tHOnZzSyY5ym2kfY= " + + "-Dnetifi.broker.admin.accessKey=9007199254740991 " + + "-Dnetifi.broker.admin.accessToken=kTBDVtfRBO4tHOnZzSyY5ym2kfY="); static { redis.start(); System.setProperty("netifi.client.broker.hostname", redis.getContainerIpAddress()); - System.setProperty("netifi.client.broker.port", - String.valueOf(redis.getMappedPort(8001))); + System.setProperty("netifi.client.broker.port", String.valueOf(redis.getMappedPort(8001))); } @Group("com.netifi.client.demo.vowelcount") @@ -65,10 +51,6 @@ public class SpringMessagingIntegrationTest { public void tests() { Assert.assertNotNull(requester.rsocket()); - requester.route("test.process") - .data("test") - .retrieveMono(String.class) - .log() - .block(); + requester.route("test.process").data("test").retrieveMono(String.class).log().block(); } } diff --git a/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/TestApplication.java b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/TestApplication.java index ddf3f9dd..2f32858b 100644 --- a/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/TestApplication.java +++ b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/TestApplication.java @@ -18,16 +18,15 @@ import com.netifi.spring.boot.BrokerClientAutoConfiguration; import com.netifi.spring.boot.BrokerClientMessagingAutoConfiguration; import com.netifi.spring.core.config.BrokerClientConfiguration; - import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication @ImportAutoConfiguration({ - BrokerClientMessagingAutoConfiguration.class, - BrokerClientAutoConfiguration.class, - BrokerClientConfiguration.class, + BrokerClientMessagingAutoConfiguration.class, + BrokerClientAutoConfiguration.class, + BrokerClientConfiguration.class, }) public class TestApplication { public static void main(String[] args) { diff --git a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClientBeanDefinitionRegistryPostProcessor.java b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClientBeanDefinitionRegistryPostProcessor.java index 5d6d0a88..24f55806 100644 --- a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClientBeanDefinitionRegistryPostProcessor.java +++ b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClientBeanDefinitionRegistryPostProcessor.java @@ -67,7 +67,8 @@ public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) @Override public Object getSuggestedValue(DependencyDescriptor descriptor) { List brokerClientFactories = - new ArrayList<>(beanFactory.getBeansOfType(BrokerClientFactorySupport.class).values()); + new ArrayList<>( + beanFactory.getBeansOfType(BrokerClientFactorySupport.class).values()); AnnotationAwareOrderComparator.sort(brokerClientFactories); @@ -80,8 +81,7 @@ public Object getSuggestedValue(DependencyDescriptor descriptor) { if (annotation != null) { Class descriptorDeclaredType = descriptor.getDeclaredType(); - String[] beanNamesForType = - beanFactory.getBeanNamesForType(descriptorDeclaredType); + String[] beanNamesForType = beanFactory.getBeanNamesForType(descriptorDeclaredType); for (String beanName : beanNamesForType) { BeanDefinition beanDefinition = beanFactory.getMergedBeanDefinition(beanName); @@ -119,9 +119,7 @@ public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {} private static boolean isSuportedByFactories( - Collection brokerClientFactories, - Class clazz - ) { + Collection brokerClientFactories, Class clazz) { for (BrokerClientFactorySupport factory : brokerClientFactories) { if (factory.support(clazz)) { return true; diff --git a/netifi-spring-core/src/main/java/com/netifi/spring/core/config/BrokerClientConfiguration.java b/netifi-spring-core/src/main/java/com/netifi/spring/core/config/BrokerClientConfiguration.java index 23522d53..1d45417b 100644 --- a/netifi-spring-core/src/main/java/com/netifi/spring/core/config/BrokerClientConfiguration.java +++ b/netifi-spring-core/src/main/java/com/netifi/spring/core/config/BrokerClientConfiguration.java @@ -19,7 +19,6 @@ import com.netifi.broker.info.BrokerInfoService; import com.netifi.broker.info.BrokerInfoServiceClient; import com.netifi.broker.info.BrokerInfoServiceServer; -import com.netifi.common.tags.Tags; import com.netifi.spring.core.BrokerClientApplicationEventListener; import com.netifi.spring.core.annotation.BrokerClientBeanDefinitionRegistryPostProcessor; import com.netifi.spring.core.annotation.RpcBrokerClientFactorySupport; From 36983587663e056e74b4f631e422b8906a72e474 Mon Sep 17 00:00:00 2001 From: Oleh Dokuka Date: Mon, 18 Nov 2019 10:09:28 +0200 Subject: [PATCH 7/9] Merge remote-tracking branch 'rebranded/develop' into develop # Conflicts: # netifi-broker-client/src/main/java/com/netifi/broker/DefaultBuilderConfig.java # netifi-spring-core/src/main/java/com/netifi/spring/core/DestinationAwareClientFactory.java # netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClientStaticFactory.java --- build.gradle | 2 +- .../buildscript-classpath.lockfile | 4 +- .../compileClasspath.lockfile | 43 ++++++++-------- .../compileClasspath.lockfile | 49 ++++++++++--------- 4 files changed, 50 insertions(+), 48 deletions(-) diff --git a/build.gradle b/build.gradle index 4dac4377..e188fde2 100644 --- a/build.gradle +++ b/build.gradle @@ -11,7 +11,7 @@ plugins { id 'com.github.sherter.google-java-format' version '0.8' apply false id 'me.champeau.gradle.jmh' version '0.4.7' apply false id 'io.morethan.jmhreport' version '0.6.2.1' apply false - id 'io.spring.dependency-management' version '1.0.7.RELEASE' apply false + id 'io.spring.dependency-management' version '1.0.8.RELEASE' apply false id 'com.google.protobuf' version '0.8.8' apply false id 'com.palantir.git-version' version '0.12.0-rc2' } diff --git a/gradle/dependency-locks/buildscript-classpath.lockfile b/gradle/dependency-locks/buildscript-classpath.lockfile index 5b16e961..8e83bf1f 100644 --- a/gradle/dependency-locks/buildscript-classpath.lockfile +++ b/gradle/dependency-locks/buildscript-classpath.lockfile @@ -26,8 +26,8 @@ gradle.plugin.com.hierynomus.gradle.plugins:license-gradle-plugin:0.15.0 gradle.plugin.com.palantir.gradle.gitversion:gradle-git-version:0.12.0-rc2 gradle.plugin.io.morethan.jmhreport:gradle-jmh-report:0.6.2.1 io.morethan.jmhreport:io.morethan.jmhreport.gradle.plugin:0.6.2.1 -io.spring.dependency-management:io.spring.dependency-management.gradle.plugin:1.0.7.RELEASE -io.spring.gradle:dependency-management-plugin:1.0.7.RELEASE +io.spring.dependency-management:io.spring.dependency-management.gradle.plugin:1.0.8.RELEASE +io.spring.gradle:dependency-management-plugin:1.0.8.RELEASE javax.annotation:jsr250-api:1.0 javax.enterprise:cdi-api:1.0 javax.inject:javax.inject:1 diff --git a/netifi-spring-core/gradle/dependency-locks/compileClasspath.lockfile b/netifi-spring-core/gradle/dependency-locks/compileClasspath.lockfile index 115d13ec..17961a09 100644 --- a/netifi-spring-core/gradle/dependency-locks/compileClasspath.lockfile +++ b/netifi-spring-core/gradle/dependency-locks/compileClasspath.lockfile @@ -4,22 +4,23 @@ com.google.protobuf:protobuf-java:3.6.1 com.typesafe:config:1.3.3 io.micrometer:micrometer-core:1.0.6 -io.netty:netty-buffer:4.1.36.Final -io.netty:netty-codec-http2:4.1.36.Final -io.netty:netty-codec-http:4.1.36.Final -io.netty:netty-codec-socks:4.1.36.Final -io.netty:netty-codec:4.1.36.Final -io.netty:netty-common:4.1.36.Final -io.netty:netty-handler-proxy:4.1.36.Final -io.netty:netty-handler:4.1.36.Final -io.netty:netty-resolver:4.1.36.Final +io.netty:netty-buffer:4.1.42.Final +io.netty:netty-codec-http2:4.1.42.Final +io.netty:netty-codec-http:4.1.42.Final +io.netty:netty-codec-socks:4.1.42.Final +io.netty:netty-codec:4.1.42.Final +io.netty:netty-common:4.1.42.Final +io.netty:netty-handler-proxy:4.1.42.Final +io.netty:netty-handler:4.1.42.Final +io.netty:netty-resolver:4.1.42.Final io.netty:netty-tcnative:2.0.25.Final -io.netty:netty-transport-native-epoll:4.1.36.Final -io.netty:netty-transport-native-unix-common:4.1.36.Final -io.netty:netty-transport:4.1.36.Final +io.netty:netty-transport-native-epoll:4.1.42.Final +io.netty:netty-transport-native-unix-common:4.1.42.Final +io.netty:netty-transport:4.1.42.Final io.opentracing:opentracing-api:0.31.0 -io.projectreactor.netty:reactor-netty:0.9.0.BUILD-SNAPSHOT -io.projectreactor:reactor-core:3.3.0.BUILD-SNAPSHOT +io.projectreactor.addons:reactor-pool:0.1.0.RELEASE +io.projectreactor.netty:reactor-netty:0.9.0.RELEASE +io.projectreactor:reactor-core:3.3.0.RELEASE io.rsocket.rpc:rsocket-rpc-core:0.2.18 io.rsocket:rsocket-core:1.0.0-RC5 io.rsocket:rsocket-transport-netty:1.0.0-RC5 @@ -28,11 +29,11 @@ javax.inject:javax.inject:1 javax.validation:validation-api:2.0.1.Final org.hdrhistogram:HdrHistogram:2.1.10 org.latencyutils:LatencyUtils:2.0.3 -org.reactivestreams:reactive-streams:1.0.2 +org.reactivestreams:reactive-streams:1.0.3 org.slf4j:slf4j-api:1.7.25 -org.springframework:spring-aop:5.2.0.BUILD-SNAPSHOT -org.springframework:spring-beans:5.2.0.BUILD-SNAPSHOT -org.springframework:spring-context:5.2.0.BUILD-SNAPSHOT -org.springframework:spring-core:5.2.0.BUILD-SNAPSHOT -org.springframework:spring-expression:5.2.0.BUILD-SNAPSHOT -org.springframework:spring-jcl:5.2.0.BUILD-SNAPSHOT +org.springframework:spring-aop:5.2.0.RELEASE +org.springframework:spring-beans:5.2.0.RELEASE +org.springframework:spring-context:5.2.0.RELEASE +org.springframework:spring-core:5.2.0.RELEASE +org.springframework:spring-expression:5.2.0.RELEASE +org.springframework:spring-jcl:5.2.0.RELEASE diff --git a/netifi-spring-messaging/gradle/dependency-locks/compileClasspath.lockfile b/netifi-spring-messaging/gradle/dependency-locks/compileClasspath.lockfile index ad181116..7914c03e 100644 --- a/netifi-spring-messaging/gradle/dependency-locks/compileClasspath.lockfile +++ b/netifi-spring-messaging/gradle/dependency-locks/compileClasspath.lockfile @@ -4,36 +4,37 @@ com.google.protobuf:protobuf-java:3.6.1 com.typesafe:config:1.3.3 io.micrometer:micrometer-core:1.0.6 -io.netty:netty-buffer:4.1.36.Final -io.netty:netty-codec-http2:4.1.36.Final -io.netty:netty-codec-http:4.1.36.Final -io.netty:netty-codec-socks:4.1.36.Final -io.netty:netty-codec:4.1.36.Final -io.netty:netty-common:4.1.36.Final -io.netty:netty-handler-proxy:4.1.36.Final -io.netty:netty-handler:4.1.36.Final -io.netty:netty-resolver:4.1.36.Final +io.netty:netty-buffer:4.1.42.Final +io.netty:netty-codec-http2:4.1.42.Final +io.netty:netty-codec-http:4.1.42.Final +io.netty:netty-codec-socks:4.1.42.Final +io.netty:netty-codec:4.1.42.Final +io.netty:netty-common:4.1.42.Final +io.netty:netty-handler-proxy:4.1.42.Final +io.netty:netty-handler:4.1.42.Final +io.netty:netty-resolver:4.1.42.Final io.netty:netty-tcnative:2.0.25.Final -io.netty:netty-transport-native-epoll:4.1.36.Final -io.netty:netty-transport-native-unix-common:4.1.36.Final -io.netty:netty-transport:4.1.36.Final +io.netty:netty-transport-native-epoll:4.1.42.Final +io.netty:netty-transport-native-unix-common:4.1.42.Final +io.netty:netty-transport:4.1.42.Final io.opentracing:opentracing-api:0.31.0 -io.projectreactor.netty:reactor-netty:0.9.0.BUILD-SNAPSHOT -io.projectreactor:reactor-core:3.3.0.BUILD-SNAPSHOT +io.projectreactor.addons:reactor-pool:0.1.0.RELEASE +io.projectreactor.netty:reactor-netty:0.9.0.RELEASE +io.projectreactor:reactor-core:3.3.0.RELEASE io.rsocket.rpc:rsocket-rpc-core:0.2.18 -io.rsocket:rsocket-core:0.12.2-RC3 -io.rsocket:rsocket-transport-netty:0.12.2-RC3 +io.rsocket:rsocket-core:1.0.0-RC5 +io.rsocket:rsocket-transport-netty:1.0.0-RC5 javax.annotation:javax.annotation-api:1.3.2 javax.inject:javax.inject:1 javax.validation:validation-api:2.0.1.Final org.hdrhistogram:HdrHistogram:2.1.10 org.latencyutils:LatencyUtils:2.0.3 -org.reactivestreams:reactive-streams:1.0.2 +org.reactivestreams:reactive-streams:1.0.3 org.slf4j:slf4j-api:1.7.25 -org.springframework:spring-aop:5.2.0.BUILD-SNAPSHOT -org.springframework:spring-beans:5.2.0.BUILD-SNAPSHOT -org.springframework:spring-context:5.2.0.BUILD-SNAPSHOT -org.springframework:spring-core:5.2.0.BUILD-SNAPSHOT -org.springframework:spring-expression:5.2.0.BUILD-SNAPSHOT -org.springframework:spring-jcl:5.2.0.BUILD-SNAPSHOT -org.springframework:spring-messaging:5.2.0.BUILD-SNAPSHOT +org.springframework:spring-aop:5.2.0.RELEASE +org.springframework:spring-beans:5.2.0.RELEASE +org.springframework:spring-context:5.2.0.RELEASE +org.springframework:spring-core:5.2.0.RELEASE +org.springframework:spring-expression:5.2.0.RELEASE +org.springframework:spring-jcl:5.2.0.RELEASE +org.springframework:spring-messaging:5.2.0.RELEASE From 6b3b267b788486272b4e09122b7b5cb9135864fc Mon Sep 17 00:00:00 2001 From: Oleh Dokuka Date: Tue, 7 Jan 2020 21:40:57 +0200 Subject: [PATCH 8/9] provides final spring messaging integration --- build.gradle | 13 +- dependency-management.gradle | 3 + gradle.properties | 2 +- gradle/wrapper/gradle-wrapper.jar | Bin 55190 -> 55616 bytes gradle/wrapper/gradle-wrapper.properties | 2 +- gradlew | 22 +- gradlew.bat | 18 +- .../java/com/netifi/broker/BrokerClient.java | 158 +-- .../java/com/netifi/broker/BrokerFactory.java | 935 ++++++++++++++++++ .../java/com/netifi/broker/BrokerService.java | 18 +- .../netifi/broker/DefaultBrokerService.java | 73 +- .../netifi/broker/DefaultBuilderConfig.java | 8 +- .../broker/DefaultRoutingBrokerService.java | 73 ++ .../com/netifi/broker/InstanceInfoAware.java | 28 + .../netifi/broker/RoutingBrokerService.java | 48 + .../rsocket/WeightedReconnectingRSocket.java | 41 +- .../broker/DefaultBuilderConfigTest.java | 11 +- .../BrokerClientIntegrationTest.java | 53 +- .../WeightedReconnectingRSocketTest.java | 16 +- .../testCompileClasspath.lockfile~merged | 35 - .../dependency-locks/protobuf.lockfile~merged | 3 - .../testCompileClasspath.lockfile~merged | 35 - netifi-common/build.gradle | 2 +- .../broker/influx/BrokerInfluxBridge.java | 40 +- .../BrokerMeterRegistrySupplier.java | 14 +- .../prometheus/BrokerPrometheusBridge.java | 41 +- netifi-spring-boot-autoconfigure/build.gradle | 6 - .../boot/BrokerClientAutoConfiguration.java | 252 +++-- ...rokerClientMessagingAutoConfiguration.java | 84 +- .../boot/BrokerClientMessagingProperties.java | 15 +- .../netifi/spring/boot/NetifiBootstrap.java | 70 ++ .../boot/support/BrokerClientConfigurer.java | 8 +- .../boot/support/BrokerServiceConfigurer.java | 24 + .../BrokerClientSpringIntegrationTest.java | 12 +- .../ClientConfigurationIntegrationTest.java | 14 +- ...geHandler.java => MessageHandlerTest.java} | 4 +- .../test/SpringMessagingIntegrationTest.java | 7 +- .../spring/boot/test/TestApplication.java | 35 - .../boot/test/TestIdlServiceServer.java | 15 +- .../test/resources/META-INF/spring.factories | 5 + netifi-spring-boot-starter/build.gradle | 1 + netifi-spring-core/build.gradle | 8 - .../BrokerClientApplicationEventListener.java | 8 +- ...ntBeanDefinitionRegistryPostProcessor.java | 6 +- .../annotation/BrokerClientStaticFactory.java | 12 +- .../RpcBrokerClientFactorySupport.java | 4 +- .../config/BrokerClientConfiguration.java | 10 +- .../spring/core/TestIdlServiceServer.java | 15 +- .../spring/core/TestableConfiguration.java | 7 + netifi-spring-messaging/build.gradle | 6 - ...ClientRequesterMethodArgumentResolver.java | 58 +- ...essagingRSocketRequesterClientFactory.java | 23 +- .../spring/messaging/MessagingRouter.java | 335 +++++++ .../MetricsAwareRSocketRequester.java | 98 +- .../RSocketRequesterStaticFactory.java | 85 +- .../spring/core/TestIdlServiceServer.java | 4 + .../dependency-locks/compile.lockfile~merged | 3 - .../broker/tracing/BrokerTracerSupplier.java | 6 +- .../tracing/BrokerZipkinHttpBridge.java | 25 +- settings.gradle | 11 + 60 files changed, 2260 insertions(+), 708 deletions(-) create mode 100644 netifi-broker-client/src/main/java/com/netifi/broker/BrokerFactory.java create mode 100644 netifi-broker-client/src/main/java/com/netifi/broker/DefaultRoutingBrokerService.java create mode 100644 netifi-broker-client/src/main/java/com/netifi/broker/InstanceInfoAware.java create mode 100644 netifi-broker-client/src/main/java/com/netifi/broker/RoutingBrokerService.java delete mode 100644 netifi-broker-info-idl/gradle/dependency-locks/testCompileClasspath.lockfile~merged delete mode 100644 netifi-broker-mgmt-idl/gradle/dependency-locks/protobuf.lockfile~merged delete mode 100644 netifi-broker-mgmt-idl/gradle/dependency-locks/testCompileClasspath.lockfile~merged create mode 100644 netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/NetifiBootstrap.java create mode 100644 netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/support/BrokerServiceConfigurer.java rename netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/{MessageHandler.java => MessageHandlerTest.java} (93%) delete mode 100644 netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/TestApplication.java create mode 100644 netifi-spring-boot-autoconfigure/src/test/resources/META-INF/spring.factories create mode 100644 netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/MessagingRouter.java delete mode 100644 netifi-tracing-idl/gradle/dependency-locks/compile.lockfile~merged diff --git a/build.gradle b/build.gradle index e188fde2..af798628 100644 --- a/build.gradle +++ b/build.gradle @@ -5,23 +5,16 @@ buildscript { } plugins { - id 'com.gradle.build-scan' version '2.0.2' // declare before any other plugin id 'com.google.osdetector' version '1.4.0' id "com.github.hierynomus.license" version '0.15.0' id 'com.github.sherter.google-java-format' version '0.8' apply false - id 'me.champeau.gradle.jmh' version '0.4.7' apply false + id 'me.champeau.gradle.jmh' version '0.5.0' apply false id 'io.morethan.jmhreport' version '0.6.2.1' apply false id 'io.spring.dependency-management' version '1.0.8.RELEASE' apply false id 'com.google.protobuf' version '0.8.8' apply false id 'com.palantir.git-version' version '0.12.0-rc2' } -//buildScan { licenseAgreementUrl = 'https://gradle.com/terms-of-service'; licenseAgree = 'yes' } -buildScan { - termsOfServiceUrl = 'https://gradle.com/terms-of-service' - termsOfServiceAgree = 'yes' -} - // TODO: make this a Gradle plugin someday def details = versionDetails() def versionSuffix = "" @@ -65,9 +58,9 @@ subprojects { targetCompatibility = 1.8 repositories { - - mavenCentral() maven { url 'https://oss.jfrog.org/oss-snapshot-local' } + mavenCentral() + jcenter() maven { url 'https://nexus.netifi.com/repository/jcenter/' credentials { diff --git a/dependency-management.gradle b/dependency-management.gradle index f69e869c..49c545b8 100644 --- a/dependency-management.gradle +++ b/dependency-management.gradle @@ -1,5 +1,7 @@ apply plugin: 'io.spring.dependency-management' +ext["rsocket.version"] = rsocketVersion + dependencyManagement { imports { mavenBom "io.rsocket:rsocket-bom:${rsocketVersion}" @@ -11,6 +13,7 @@ dependencyManagement { mavenBom "software.amazon.awssdk:bom:${awssdkVersion}" mavenBom "io.rsocket:rsocket-bom:${rsocketVersion}" mavenBom "com.google.protobuf:protobuf-bom:${protobufVersion}" + mavenBom "org.springframework.boot:spring-boot-dependencies:${springBootDependenciesVersion}" } dependencies { diff --git a/gradle.properties b/gradle.properties index c10d4c1c..aa866a3a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -28,7 +28,7 @@ postgresqlVersion=42.2.5 protobufVersion=3.7.1 reactorBomVersion=Dysprosium-RELEASE roaringbitmapVersion=0.7.42 -rsocketRpcVersion=0.3.0-feature-prioritization-SNAPSHOT +rsocketRpcVersion=0.3.0-feature-routing-SNAPSHOT rsocketVersion=1.0.0-RC6-bugfix-prioritization-SNAPSHOT rxjava2JdbcVersion=0.2.4 slf4jVersion=1.7.25 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 87b738cbd051603d91cc39de6cb000dd98fe6b02..5c2d1cf016b3885f6930543d57b744ea8c220a1a 100644 GIT binary patch delta 3320 zcmai0c|2768`iN!wwN(!Oxeo5?`tVU3{m#%jC~noTx!q_nHtNnR`zAgWC@krB#b55 znJk4YA);()+(!K-w|npJuix)IpYu7-^SqzuJ>T~|?;j_-ma(;-@!<_I_B>B@4FVej z11CRtM@$8afpkN^v*te{ycR9yTldxXJbmio?@}x{9}zaw&=aQt(a^ZXN9S3i8a+Z% zGc@&(5}jplZjJKk2wNlTp(mbeKL5J9Gjo==yT{-eVKj?*rT1%bQ@%#Xce~~1f{19^ zoD75QEoSzDVh@!9qG4yl`;9=Ysp?rRX=(8$VDRz=R+oA3>jLxjW-H!-2biNSYuy)U z7-B-qC5l;>qjMTg!DbWPY}h7qxi6xp)_T)_O2+*&NDg?v;RyY@5XtWHx%(ImQ_3E% zA%$s3xrxE0Fk>DhG!pG)4}I!pWJl~QtV_3Jl2W4PuWWssMq^UpGatK+4CING9pB#5 z_NDc)aonVrZuXsr5!RcE#?aXFZQjt2VMd)-p00K$EheT?H!m_D2Mdqq;0moaO=C&y zgJnvzgUn!wkx^{r049pU#gsIMhl`%{MDNl;}JRbneC zSTB=5f;o9=2Rt24_lt&%%f~m{Ts)zu8H9j`INrgMp>l-|k%Kj%U`OXL1J2e+CJHJxreHLD_#o*ZeuXE4uGDQAJS_PpEGt7hmd7psmLEBL^h zD#JbHiklZEXkk9(6uF$ErsUu^jg7c~1oRS&CuTq*Xg_cOvGw~FZ&1#p(6|jz9lJnP zSIJ)sX_W2$PSksX&}*_ejz+t*X)xK|JcakaMRGd%c*R)cQcT|?sM^#{fdjh5_I$iK zBX_d;wz+cf>b}r!i3yo6eaua)d`|Mi_|Q3mAz5Qn?#~xgE9In<;TwYN^~mtaYy#WU z*ffWtxwlk&!e@UfqQ$bn23RDFV3o-H_WM}44yQpYw;JuRf$at#XX-qmuVnKqg-Bo# zJjZE39)!{i$qJh?oJzVzWFDlSW;{Wf`Z)33Y$Fh^+qasrsEJsfy9yhyTFe?Lej&3n zEAS(D8WCt(ew(SGD z-J#7@l?KI*ZbS)AVQ23qV&{c=$@zUp0@6=kZp+5by+gnAWdB||7e=!yJ|WTpG0OC7 zKlKWFv6#(>nrEq@d1i-#L9SVxTDNb1DaY%2$=@)`k&3s8wz$M*;THa&!2Isj%6CQS zY>A4HtmWY3@9e@F)mCHJQzBz~Lt(wcJE{!CAr=wxn4|5n(jslTy)~IF?tNK zD^2#hTM0d6MDg>`9;s5*(4W1V8y}F8OT6Xap{`=h1XVKO3zrBh=;JnIs*RB>@7t5T zwV=G^T)L=(9P7tS={6`tEBBBm^u~_!-#m75G*h}y_Jj7|STtiY_LDR5UUHI@awWmB zDn6q9{2M-EHaTm53ln%ENJ$HpLwRcL>7^hUrM=}&`qmWTgtr{Ul*Lqcd_9S0xZ1s>F2dVd(s)3&$`gxFAu6jXYIS ze#M~w@=X@lm)sFI4EEiqKh7JxN=_?+}D=iHCc&S2<^VPZ6 zYKXZgvi(Yne9}k6o=ezgquABVB77}x$nKXh`@LjH&lQPqm_;MTL>4RGO|E#_7AS4@43rz=ij?gcMZalnd-JK4ILhL)Ee(3G zN}g99HmhxoBjHR~y@b>-7{f+`p zIZ<^8%d;wCA#xfwSc6$DNVPjAX6FCkb|MQ|6hFyz9UhoLF0^xUd#*^2Ofn zOJgmwDyb1=Z8T)ArRy|VQOM+BrhZ>W_ELJ6u(d^JTu|j%*6g8JKZ-ewoj)sXJCdS= zHOo?HscL;Z`H18}%WnE1&o42KZ+=fg(*VN>t>kRkcd{mP9NF6;MnzH&m2WsD)sX~h zbhv|Ux$w2avQwoI`IKiGMLrL;Z>R}Y_0K*L=63V z)ut+5tM74Glzb?92kbu5@3M#1Hi7K3$c)?TL$}`aKf0hC3`r!>Xy3!f{ z`}Y#@$`|mG1JlKzVE!vD04aX}x#hV*+AC>bQ|%XJ1<&;=0?uX!RM?CIB=+!tgkB-w zu*HF--^U4#nG1mXz0v^0@|UCs1lt}!1zTaTwoe+k?sPym`pyB-F25ivXx)#1|1%|e zJ7Vpujkk#Lu%U{v6xiQ5LW2`~QXrR`ja@*L=b0ejT977v%C)0WAik0gV7U z6a-7##p#p>>>3a{^Z}e3Z~?A|foBFU12bqaEE*0vqdCCVLFq%{;F%$Dkb6i8;Qo!C z&;zkU(!i5zbSMd)zQzg8(kU^HPQ^flVIzR)<^jwbwget09YD?zV*rx+mx@0IN{#S< zsB|8Ve>>sJI7sHE!@=(((ttqL0ks%C4M^r5!0H?rJ;MV|jtT)1cMl{|9xo_Okp@Ka ze^CzbCPf?IDFWLlE`V1FDDpZ0C@7~VMZt%!6%SFtxz{!Tb1UfBDEg~49x!4|2#_L! zX=6UXeh28_?VY*suC^Sy!?XXp?9-G{ zEbF`ELqycMcTK-$-pw|Jox9S^<_NX$7{PI7aX1p5N>aOyj&D01H#;3?=q^!=_mq@k zUHheWO_|CDYA~8r<-%q8&Gm$uPSx4S`reKPnv?Nif4kS)^smTg&m@kLYT87txGxGxw+Qc zTAi=`vzavOlyLrgf2A~;1~Gx$jcb|fkhfctRt6CjRooL|#wr)(*8D4n;2cBe>p9_T zCeJf!IgCH0h1m)UPLk3hZz120oe5YH$oXjSMHcPv@#wX;OP5bBSJMavm2}5Q8(V&# zXGA!+dAwOiXuQ)|+XwF2HW1@_MPm3*v{M86V_~+xk1K7cI7mxBKU5#bofCjZqqjs$ z(sipv#Ul%KJ)h?ua}a3Dg(6yaxeJ(HD-&`AT9kZJVLJTz?WIfgao$bYwEhXh+&GA= zkpI03HVxtWc*H!~z~9%DC;;Qej=WppOD!i1$MO1`&8LW%IWd2sbnS7j+<0b`v1%qx!owUU+ZIHJFp1yH9BFvUYI^up=ZYX$K_YM|Bn2fCG3sq#(EpRB$|A9~9*^M%Sq)EAjr0&W`hHyz96Z9h*odHK|Ju$JQ0c zO9oayZQv;2b{pLJo`T)C%yS@sAKO*WC%22XDmrdRTd;uFr*sb_{GDl=*Y`l*;>lNWh=XCbn#V}C&jmw3>t zNH(fnG%j@AI$TSggf(e3DxrpHjnpeKExsb|hC`kxjD4HUSmu)&aJNt&DtCWh#51*} zS!qfplP(f0`hJ)VHrXFD_uB7ia4#%U)3S8lGY9^(T1)M8xQxP*3w4&QJr~O`$A&N5 z_taom$34zt+reJDV?oZ*qr5ERUH7#~xm7)D(u#q#m`~~-F+TZ6Q*L)s_#T3GZUuZM zhCH9!{qXnD)9jln$|GDeDPqo=+D6#vQkAjdHtT>{VxU#AQJW-je=UWN5*R>v5vWF6 zK_6z?#thq>&%@fu5epvO$rfx`v9GojdOLGFaQ2V8?Ri z(?L2JBK(;G)bIF7r5T6Ahzst5k4j#hvhl3a`@Ksfyj3^Cx}zGE)vm$ecB$?~2`S&e zE)Nx6TiDO*JO6UmWWc+zLDmnII+)ROEvW3_{*%Fjs8Q^k4+Z&cJ0lp=@p*N!fw0>L zPSWrxar=HPDCwZnmN%orA-K2142{bJ0el>N{KM(xoHJu_HWSQihq^y%SEmj>CsBjl zj6)jxqm7NwiVHh-xQ`ex^02-y_ZO`A`P(1UwLK5G_T8=uI8@e%Kh31Xay z>H$7OG8cQ%>c_RjXhRA|Yh=93MnM)V0JlD#yP-1YNx}5`sg}-vE%slfve&}e$*L>+ zSAq_CMc5SYx6N)5h%-)?JOAhiVM5`TWT7?<9 zKKxMMb9GXHpQ1ajAr?!hxcauobJLf{IpvJ=9ny}FwdGCYmwgj?0qhIG{5zbTTVc2b zo+3h|{F_Yg96k{?rVn`m`%d??#avI-eh^XnTH2r*o>5n>`UuIsuCIeN5Br62W!Yy#8)0uWcVG%-QnMHczpWoe zftoSf-WJq~x8`|ws<-9{Va9@s#SoH3uw`>4!~uyB-(lV)SD9f(TPNa!o7JLL%!a)@gUmedno%~}$ z#zZLYah$5mf@Z2}a(oDDM^$qq>*nb;?aVn?D`($Om=?j+T%S?eSgR1t=zzwGw|kvM zt~WiOO&UVW=7N=8ERxM<4?Wbj4bPIP4z3=hjp(uuT}ne*E9ct0)Lsk?bG=1nNo=oB z0JEoKzAw45q-lB!IbJKsY=Lpru48qY6ql!Z#J13ywC&7??l&AtxiowZ|Cg(k*UE#@ zrJm|m^EV_6jz}f($PrOb`S;imdEwtu`#cCu3aMXBgUUH4t2j_qu=KmOO645(v(_DL z^G5PF%RR0@X5D{(V%x5L{xD1Sa>^wR+$0j(DeVfwk;tp3<@i$~qOsvx^uUy!zV8G0~0`$f?VV=?vm zOwYnZB>UV_b#sh6ibtN`5I+l%mTE9T%*J!xaz}cWisUNLg@>nEiKv4hgmv`5C)GIDbBOgq{?5K-!=>z{CLJ$wIBkL-~yV{}~e*^#eZ1f%)RR;DgcM zfOqnA#42!t$D;@!QT3n50ve1d0$Zl^m}ABc){bz2HDhq#o&{ZLlQ=*lO9Alv7y_uW z`bTL2KkVsP<{%6$`1yeL}DmCZuxPZRJp*( z*Kk1M23@g@UjhQ6PEZ{58CL@Aqv>cB0|#ltT;SR`95{}ptMe0@zz&v<>j{GNDt-bE zn5EFw?u0e)Ee+J0^aq@C>E_j>A%MyU^@?Rcohe{^TCd{d<=ub5$bWAh BROKERCLIENT = @@ -71,9 +77,27 @@ public class BrokerClient implements Closeable { private final String group; private final String destination; private final Tags tags; - private final BrokerService brokerService; - private MonoProcessor onClose; - private RequestHandlingRSocket requestHandlingRSocket; + private final RoutingBrokerService brokerService; + private final Mono onClose; + private final MutableRouter router; + private RoutingServerRSocket routingServerRSocket; + + private BrokerClient(RoutingBrokerService routingBrokerService) { + brokerService = routingBrokerService; + tags = routingBrokerService.tags(); + destination = + routingBrokerService + .tags() + .stream() + .filter(tag -> tag.getKey().equals("com" + ".netifi.destination")) + .findFirst() + .map(Tag::getValue) + .orElse(null); + group = routingBrokerService.groupName(); + accesskey = routingBrokerService.accessKey(); + onClose = routingBrokerService.onClose(); + router = routingBrokerService.router(); + } private BrokerClient( long accessKey, @@ -88,10 +112,11 @@ private BrokerClient( long tickPeriodSeconds, long ackTimeoutSeconds, int missedAcks, - List seedAddresses, + List seedAddresses, Function addressSelector, Function clientTransportFactory, - RequestHandlingRSocket responder, + MutableRouter router, + RoutingServerRSocket responder, boolean responderRequiresUnwrapping, int poolSize, Supplier tracerSupplier, @@ -101,28 +126,41 @@ private BrokerClient( this.destination = destination; this.tags = tags; this.onClose = MonoProcessor.create(); - this.requestHandlingRSocket = responder; + this.router = router; + this.routingServerRSocket = responder; + + if (discoveryStrategy == null) { + discoveryStrategy = + () -> + Mono.just( + seedAddresses + .stream() + .map(isa -> HostAndPort.fromParts(isa.getHostName(), isa.getPort())) + .collect(Collectors.toList())); + } + this.brokerService = - new DefaultBrokerService( - seedAddresses, - requestHandlingRSocket, - responderRequiresUnwrapping, - inetAddress, - group, - addressSelector, - clientTransportFactory, - poolSize, - keepalive, - tickPeriodSeconds, - ackTimeoutSeconds, - missedAcks, - accessKey, - accessToken, - connectionIdSeed, - additionalFlags, - tags, - tracerSupplier.get(), - discoveryStrategy); + new DefaultRoutingBrokerService( + router, + new DefaultBrokerService( + routingServerRSocket, + responderRequiresUnwrapping, + inetAddress, + group, + tags, + connectionIdSeed, + addressSelector, + clientTransportFactory, + discoveryStrategy, + keepalive, + Duration.ofSeconds(tickPeriodSeconds), + Duration.ofSeconds(ackTimeoutSeconds), + missedAcks, + accessKey, + accessToken, + additionalFlags, + poolSize, + tracerSupplier.get())); } public String getGroup() { @@ -150,19 +188,23 @@ public static CustomizableBuilder customizable() { return new CustomizableBuilder(); } + public static > BrokerClient from( + RoutingBrokerService routingBrokerService) { + return new BrokerClient(routingBrokerService); + } + private static String defaultDestination() { return UUID.randomUUID().toString(); } @Override public void dispose() { - requestHandlingRSocket.dispose(); - onClose.onComplete(); + routingServerRSocket.dispose(); } @Override public boolean isDisposed() { - return onClose.isTerminated(); + return routingServerRSocket.isDisposed(); } @Override @@ -176,9 +218,9 @@ public Mono onClose() { * @param service the RSocketRpcService instance * @return current BrokerClient builder instance */ - public BrokerClient addService(RSocketRpcService service) { + public BrokerClient addService(SelfRegistrable service) { Objects.requireNonNull(service); - requestHandlingRSocket.addService(service); + service.selfRegister(router); return this; } @@ -318,11 +360,12 @@ public abstract static class CommonBuilder> { InetAddress inetAddress = DefaultBuilderConfig.getLocalAddress(); String host = DefaultBuilderConfig.getHost(); Integer port = DefaultBuilderConfig.getPort(); - List seedAddresses = DefaultBuilderConfig.getSeedAddress(); + List seedAddresses = DefaultBuilderConfig.getSeedAddress(); String netifiKey; - List socketAddresses; + List socketAddresses; DiscoveryStrategy discoveryStrategy = null; - RequestHandlingRSocket responder = new RequestHandlingRSocket(); // DEFAULT + MutableRouter router = new SimpleRouter(); // DEFAULT + Function responderBuilder = RoutingServerRSocket::new; boolean responderRequiresUnwrapping = true; // DEFAULT public SELF discoveryStrategy(DiscoveryStrategy discoveryStrategy) { @@ -433,11 +476,8 @@ public SELF port(int port) { } public SELF seedAddresses(Collection addresses) { - if (addresses instanceof List) { - this.seedAddresses = (List) addresses; - } else { - this.seedAddresses = new ArrayList<>(addresses); - } + this.seedAddresses = + addresses.stream().map(sa -> (InetSocketAddress) sa).collect(Collectors.toList()); return (SELF) this; } @@ -486,8 +526,14 @@ public SELF localAddress(InetAddress address) { return (SELF) this; } - public SELF requestHandler(RequestHandlingRSocket responder, boolean requiresUnwrapping) { - this.responder = responder; + public SELF router(MutableRouter router) { + this.router = router; + return (SELF) this; + } + + public SELF requestHandler( + Function responder, boolean requiresUnwrapping) { + this.responderBuilder = responder; this.responderRequiresUnwrapping = requiresUnwrapping; return (SELF) this; } @@ -635,7 +681,8 @@ public BrokerClient build() { socketAddresses, BrokerAddressSelectors.WEBSOCKET_ADDRESS, clientTransportFactory, - responder, + router, + responderBuilder.apply(router), responderRequiresUnwrapping, poolSize, tracerSupplier, @@ -728,7 +775,8 @@ public BrokerClient build() { socketAddresses, BrokerAddressSelectors.TCP_ADDRESS, clientTransportFactory, - responder, + router, + responderBuilder.apply(router), responderRequiresUnwrapping, poolSize, tracerSupplier, @@ -779,7 +827,8 @@ public BrokerClient build() { socketAddresses, addressSelector, clientTransportFactory, - responder, + router, + responderBuilder.apply(router), responderRequiresUnwrapping, poolSize, tracerSupplier, @@ -796,7 +845,7 @@ public static class Builder { private InetAddress inetAddress = DefaultBuilderConfig.getLocalAddress(); private String host = DefaultBuilderConfig.getHost(); private Integer port = DefaultBuilderConfig.getPort(); - private List seedAddresses = DefaultBuilderConfig.getSeedAddress(); + private List seedAddresses = DefaultBuilderConfig.getSeedAddress(); private Long accessKey = DefaultBuilderConfig.getAccessKey(); private String group = DefaultBuilderConfig.getGroup(); private String destination = DefaultBuilderConfig.getDestination(); @@ -904,11 +953,8 @@ public Builder discoveryStrategy(DiscoveryStrategy discoveryStrategy) { } public Builder seedAddresses(Collection addresses) { - if (addresses instanceof List) { - this.seedAddresses = (List) addresses; - } else { - this.seedAddresses = new ArrayList<>(addresses); - } + this.seedAddresses = + addresses.stream().map(sa -> (InetSocketAddress) sa).collect(Collectors.toList()); return this; } @@ -1090,7 +1136,7 @@ public BrokerClient build() { } } - List socketAddresses = null; + List socketAddresses = null; if (discoveryStrategy == null) { if (seedAddresses == null) { Objects.requireNonNull(host, "host is required"); @@ -1106,10 +1152,11 @@ public BrokerClient build() { String netifiKey = accessKey + group; - List _s = socketAddresses; + List _s = socketAddresses; return BROKERCLIENT.computeIfAbsent( netifiKey, _k -> { + SimpleRouter router = new SimpleRouter(); BrokerClient brokerClient = new BrokerClient( accessKey, @@ -1127,7 +1174,8 @@ public BrokerClient build() { _s, addressSelector, clientTransportFactory, - new RequestHandlingRSocket(), + router, + new RoutingServerRSocket(router), true, poolSize, tracerSupplier, diff --git a/netifi-broker-client/src/main/java/com/netifi/broker/BrokerFactory.java b/netifi-broker-client/src/main/java/com/netifi/broker/BrokerFactory.java new file mode 100644 index 00000000..a1f1429e --- /dev/null +++ b/netifi-broker-client/src/main/java/com/netifi/broker/BrokerFactory.java @@ -0,0 +1,935 @@ +/* + * Copyright 2019 The Netifi Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.netifi.broker; + +import com.netifi.broker.discovery.DiscoveryStrategy; +import com.netifi.broker.discovery.StaticListDiscoveryConfig; +import com.netifi.broker.discovery.StaticListDiscoveryStrategy; +import com.netifi.broker.frames.DestinationSetupFlyweight; +import com.netifi.broker.info.Broker; +import com.netifi.broker.rsocket.transport.BrokerAddressSelectors; +import com.netifi.common.net.HostAndPort; +import com.netifi.common.tags.Tag; +import com.netifi.common.tags.Tags; +import io.netty.buffer.Unpooled; +import io.netty.handler.ssl.OpenSsl; +import io.netty.handler.ssl.SslContext; +import io.netty.handler.ssl.SslContextBuilder; +import io.netty.handler.ssl.SslProvider; +import io.netty.handler.ssl.util.InsecureTrustManagerFactory; +import io.netty.util.CharsetUtil; +import io.opentracing.Tracer; +import io.rsocket.AbstractRSocket; +import io.rsocket.RSocket; +import io.rsocket.ipc.MutableRouter; +import io.rsocket.ipc.RoutingServerRSocket; +import io.rsocket.ipc.routing.SimpleRouter; +import io.rsocket.transport.ClientTransport; +import io.rsocket.transport.netty.client.TcpClientTransport; +import io.rsocket.transport.netty.client.WebsocketClientTransport; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.SocketAddress; +import java.time.Duration; +import java.util.Arrays; +import java.util.Base64; +import java.util.Objects; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.Supplier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import reactor.core.Exceptions; +import reactor.core.publisher.Mono; +import reactor.netty.tcp.TcpClient; + +public final class BrokerFactory { + + private static final Logger logger = LoggerFactory.getLogger(BrokerFactory.class); + private static final ConcurrentHashMap BROKERCLIENT = + new ConcurrentHashMap<>(); + private static final String DEFAULT_DESTINATION = defaultDestination(); + + private BrokerFactory() {} + + public static ClientBuilder connect() { + return new ClientBuilder(); + } + + private static String defaultDestination() { + return UUID.randomUUID().toString(); + } + + public interface KeepAliveConfig { + Duration tickPeriod(); + + Duration acknowledgeTimeout(); + + int missedAcknowledges(); + + static Builder builder() { + return new Builder(); + } + + static KeepAliveConfig noKeepAlive() { + return NoKeepAliveConfig.INSTANCE; + } + + abstract class BaseBuilder { + abstract KeepAliveConfig build(); + } + + class Builder extends BaseBuilder { + Duration tickPeriod = Duration.ofSeconds(DefaultBuilderConfig.getTickPeriodSeconds()); + Duration acknowledgeTimeout = Duration.ofSeconds(DefaultBuilderConfig.getAckTimeoutSeconds()); + int missedAcknowledges = DefaultBuilderConfig.getMissedAcks(); + + public Builder tickPeriod(Duration tickPeriod) { + this.tickPeriod = tickPeriod; + return this; + } + + public Builder acknowledgeTimeout(Duration acknowledgeTimeout) { + this.acknowledgeTimeout = acknowledgeTimeout; + return this; + } + + public Builder missedAcknowledges(int missedAcknowledges) { + this.missedAcknowledges = missedAcknowledges; + return this; + } + + KeepAliveConfig build() { + return new KeepAliveConfig() { + @Override + public Duration tickPeriod() { + return tickPeriod; + } + + @Override + public Duration acknowledgeTimeout() { + return acknowledgeTimeout; + } + + @Override + public int missedAcknowledges() { + return missedAcknowledges; + } + }; + } + } + + class NoKeepAliveBuilder extends BaseBuilder { + + @Override + KeepAliveConfig build() { + return NoKeepAliveConfig.INSTANCE; + } + } + + final class NoKeepAliveConfig implements KeepAliveConfig { + static final NoKeepAliveConfig INSTANCE = new NoKeepAliveConfig(); + + private NoKeepAliveConfig() {} + + @Override + public Duration tickPeriod() { + return Duration.ofMillis(-1); + } + + @Override + public Duration acknowledgeTimeout() { + return Duration.ofMillis(-1); + } + + @Override + public int missedAcknowledges() { + return -1; + } + } + + interface Spec { + void noKeepAlive(); + + Builder configure(); + } + + class DefaultSpec implements Spec { + + BaseBuilder builder; + + DefaultSpec() { + if (DefaultBuilderConfig.getKeepAlive()) { + configure(); + } else { + noKeepAlive(); + } + } + + @Override + public void noKeepAlive() { + builder = new NoKeepAliveBuilder(); + } + + @Override + public Builder configure() { + Builder builder = new Builder(); + this.builder = builder; + return builder; + } + } + } + + public interface SslConfig { + + Supplier sslContextProvider(); + + static SslConfig custom(Supplier sslContextSupplier) { + return () -> sslContextSupplier; + } + + static NoSslConfig noSslConfig() { + return NoSslConfig.INSTANCE; + } + + static SslConfig defaultSslConfig() { + return DefaultSslConfig.INSTANCE; + } + + final class NoSslConfig implements SslConfig { + static final NoSslConfig INSTANCE = new NoSslConfig(); + + private NoSslConfig() {} + + @Override + public Supplier sslContextProvider() { + return null; + } + } + + final class DefaultSslConfig implements SslConfig { + + static final DefaultSslConfig INSTANCE = new DefaultSslConfig(); + + private DefaultSslConfig() {} + + @Override + public Supplier sslContextProvider() { + return SUPPLIER_INSTANCE; + } + + static final Supplier SUPPLIER_INSTANCE = + () -> { + final SslProvider sslProvider; + if (OpenSsl.isAvailable()) { + logger.info("Native SSL provider is available; will use native provider."); + sslProvider = SslProvider.OPENSSL_REFCNT; + } else { + logger.info("Native SSL provider not available; will use JDK SSL provider."); + sslProvider = SslProvider.JDK; + } + try { + return SslContextBuilder.forClient() + .trustManager(InsecureTrustManagerFactory.INSTANCE) + .sslProvider(sslProvider) + .build(); + } catch (Throwable e) { + throw Exceptions.propagate(e); + } + }; + } + + interface Spec { + void unsecured(); + + void secured(); + + void secured(Supplier sslContextSupplier); + } + + class DefaultSpec implements Spec { + + SslConfig sslConfig; + + DefaultSpec() { + if (DefaultBuilderConfig.isSslDisabled()) { + unsecured(); + } else { + secured(); + } + } + + @Override + public void unsecured() { + sslConfig = new NoSslConfig(); + } + + @Override + public void secured() { + sslConfig = new DefaultSslConfig(); + } + + @Override + public void secured(Supplier sslContextSupplier) { + sslConfig = () -> sslContextSupplier; + } + } + } + + public interface DiscoveryConfig { + + DiscoveryStrategy discoveryStrategy(); + + static DiscoveryConfig staticDiscovery(int port, String... hosts) { + return () -> new StaticListDiscoveryStrategy(new StaticListDiscoveryConfig(port, hosts)); + } + + static DiscoveryConfig staticDiscovery(HostAndPort... addresses) { + return () -> (DiscoveryStrategy) () -> Mono.just(Arrays.asList(addresses)); + } + + static DiscoveryConfig custom(DiscoveryStrategy discoveryStrategy) { + return () -> discoveryStrategy; + } + + interface Spec { + void simple(int port, String... hosts); + + void simple(HostAndPort... addresses); + + void custom(DiscoveryStrategy discoveryStrategy); + } + + class DefaultSpec implements Spec { + + DiscoveryConfig config; + + @Override + public void simple(int port, String... hosts) { + config = staticDiscovery(port, hosts); + } + + @Override + public void simple(HostAndPort... addresses) { + config = staticDiscovery(addresses); + } + + @Override + public void custom(DiscoveryStrategy discoveryStrategy) { + config = DiscoveryConfig.custom(discoveryStrategy); + } + } + } + + public interface AuthenticationConfig { + long accessKey(); + + byte[] accessToken(); + + static AuthenticationConfig simple(long accessKey, String bast64EncodedAccessToken) { + return simple(accessKey, Base64.getDecoder().decode(bast64EncodedAccessToken)); + } + + static AuthenticationConfig simple(long accessKey, byte[] accessToken) { + return new AuthenticationConfig() { + @Override + public long accessKey() { + return accessKey; + } + + @Override + public byte[] accessToken() { + return accessToken; + } + }; + } + + static AuthenticationConfig jwt(String jwtTokenString) { + return new JwtAuthenticationConfig(jwtTokenString.getBytes(CharsetUtil.UTF_8)); + } + + static AuthenticationConfig jwt(byte[] jwtToken) { + return new JwtAuthenticationConfig(jwtToken); + } + + interface Spec { + JwtSpec jwt(); + + SimpleSpec simple(); + } + + interface SimpleSpec { + SimpleSpec key(long accessKey); + + SimpleSpec token(String bast64EncodedAccessToken); + + SimpleSpec token(byte[] accessToken); + } + + interface JwtSpec { + + JwtSpec token(String jwtTokenString); + + JwtSpec token(byte[] jwtToken); + } + + class DefaultSpec implements Spec { + + BaseSpec baseSpec; + + DefaultSpec() { + if ((DefaultBuilderConfig.getAdditionalConnectionFlags() + & DestinationSetupFlyweight.FLAG_ALTERNATIVE_AUTHENTICATION) + == DestinationSetupFlyweight.FLAG_ALTERNATIVE_AUTHENTICATION) { + jwt(); + } else { + simple(); + } + } + + @Override + public JwtSpec jwt() { + DefaultJwtSpec jwtSpec = new DefaultJwtSpec(); + baseSpec = jwtSpec; + return jwtSpec; + } + + @Override + public SimpleSpec simple() { + DefaultSimpleSpec simpleSpec = new DefaultSimpleSpec(); + baseSpec = simpleSpec; + return simpleSpec; + } + } + + abstract class BaseSpec { + long accessKey; + byte[] accessToken; + + abstract AuthenticationConfig build(); + } + + class DefaultSimpleSpec extends BaseSpec implements SimpleSpec { + + DefaultSimpleSpec() { + Long key = DefaultBuilderConfig.getAccessKey(); + if (key != null) { + key(key); + } + + String token = DefaultBuilderConfig.getAccessToken(); + if (token != null) { + token(token); + } + } + + @Override + public SimpleSpec key(long accessKey) { + this.accessKey = accessKey; + return this; + } + + @Override + public SimpleSpec token(String bast64EncodedAccessToken) { + return token(Base64.getDecoder().decode(bast64EncodedAccessToken)); + } + + @Override + public SimpleSpec token(byte[] accessToken) { + this.accessToken = accessToken; + return this; + } + + @Override + AuthenticationConfig build() { + return AuthenticationConfig.simple(accessKey, accessToken); + } + } + + class DefaultJwtSpec extends BaseSpec implements JwtSpec { + + DefaultJwtSpec() { + token(DefaultBuilderConfig.getAccessToken()); + } + + @Override + public JwtSpec token(String bast64EncodedAccessToken) { + return token(Base64.getDecoder().decode(bast64EncodedAccessToken)); + } + + @Override + public JwtSpec token(byte[] accessToken) { + this.accessToken = accessToken; + return this; + } + + @Override + AuthenticationConfig build() { + return AuthenticationConfig.jwt(accessToken); + } + } + + final class JwtAuthenticationConfig implements AuthenticationConfig { + + private final byte[] jwtToken; + + JwtAuthenticationConfig(byte[] jwtToken) { + this.jwtToken = jwtToken; + } + + @Override + public long accessKey() { + return DestinationSetupFlyweight.JWT_AUTHENTICATION; + } + + @Override + public byte[] accessToken() { + return jwtToken; + } + } + } + + public interface DestinationInfoConfig { + String group(); + + Tags tags(); + + InetAddress inetAddress(); + + boolean isPublic(); + + static Builder builder() { + return new Builder(); + } + + class Builder { + + private String group = DefaultBuilderConfig.getGroup(); + private String destination = DefaultBuilderConfig.getDestination(); + private Tags tags = DefaultBuilderConfig.getTags(); + private InetAddress localINetAddress = DefaultBuilderConfig.getLocalAddress(); + private boolean isPublic = + (DefaultBuilderConfig.getAdditionalConnectionFlags() + & DestinationSetupFlyweight.FLAG_ENABLE_PUBLIC_ACCESS) + == DestinationSetupFlyweight.FLAG_ENABLE_PUBLIC_ACCESS; + + public Builder asPublicDestination() { + isPublic = true; + return this; + } + + public Builder asPrivateDestination() { + isPublic = false; + return this; + } + + public Builder groupName(String group) { + this.group = group; + return this; + } + + public Builder localAddress(InetAddress localINetAddress) { + this.localINetAddress = localINetAddress; + return this; + } + + public Builder destinationTag(String destination) { + this.destination = destination; + return this; + } + + public Builder tag(String key, String value) { + this.tags = tags.and(key, value); + return this; + } + + public Builder tags(String... tags) { + this.tags = this.tags.and(tags); + return this; + } + + public Builder tags(Iterable tags) { + this.tags = this.tags.and(tags); + return this; + } + + DestinationInfoConfig build() { + Tags tags; + if (destination != null && !destination.isEmpty()) { + tags = this.tags.and("com.netifi.destination", destination); + } else { + tags = this.tags; + } + + return new DestinationInfoConfig() { + @Override + public String group() { + return group; + } + + @Override + public Tags tags() { + return tags; + } + + @Override + public InetAddress inetAddress() { + return localINetAddress; + } + + @Override + public boolean isPublic() { + return isPublic; + } + }; + } + } + } + + public interface ConnectionConfig { + + Function clientTransportFactory(); + + Function brokerAddressSelector(); + + String connectionName(); + + static Builder builder() { + return new Builder(); + } + + static WebSocketBuilder ws() { + return new WebSocketBuilder(); + } + + static TcpBuilder tcp() { + return new TcpBuilder(); + } + + interface Spec { + TcpBuilder tcp(); + + WebSocketBuilder ws(); + + Builder custom(); + } + + class DefaultSpec implements Spec { + + BaseBuilder baseBuilder; + + @Override + public TcpBuilder tcp() { + TcpBuilder tcpBuilder = ConnectionConfig.tcp(); + if (DefaultBuilderConfig.isSslDisabled()) { + tcpBuilder.ssl(SslConfig.Spec::unsecured); + } else { + tcpBuilder.ssl(SslConfig.Spec::secured); + } + baseBuilder = tcpBuilder; + return tcpBuilder; + } + + @Override + public WebSocketBuilder ws() { + WebSocketBuilder webSocketBuilder = ConnectionConfig.ws(); + if (DefaultBuilderConfig.isSslDisabled()) { + webSocketBuilder.ssl(SslConfig.Spec::unsecured); + } else { + webSocketBuilder.ssl(SslConfig.Spec::secured); + } + baseBuilder = webSocketBuilder; + return webSocketBuilder; + } + + @Override + public Builder custom() { + Builder builder = ConnectionConfig.builder(); + baseBuilder = builder; + return builder; + } + } + + abstract class BaseBuilder> { + String connectionName; + + public BaseBuilder() { + connectionName = DefaultBuilderConfig.getConnectionId(); + + if (connectionName == null || connectionName.isEmpty()) { + connectionName = UUID.randomUUID().toString(); + } + } + + public SELF withConnectionName(String connectionName) { + this.connectionName = connectionName; + return (SELF) this; + } + + abstract ConnectionConfig build(); + } + + abstract class TcpBasedBuilder> extends BaseBuilder { + + Consumer specBuilder = __ -> {}; + + public SELF ssl(Consumer specBuilder) { + this.specBuilder = Objects.requireNonNull(specBuilder); + return (SELF) this; + } + + static ConnectionConfig tcpBased( + Function transportFactory, + Function brokerAddressSelector, + String connectionName, + Consumer sslBuilder) { + SslConfig.DefaultSpec spec = new SslConfig.DefaultSpec(); + sslBuilder.accept(spec); + SslConfig sslConfig = spec.sslConfig; + + if (sslConfig instanceof SslConfig.NoSslConfig) { + return new ConnectionConfig() { + @Override + public Function clientTransportFactory() { + return address -> { + TcpClient client = TcpClient.create().addressSupplier(() -> address); + return transportFactory.apply(client); + }; + } + + @Override + public Function brokerAddressSelector() { + return brokerAddressSelector; + } + + @Override + public String connectionName() { + return connectionName; + } + }; + + } else { + final SslContext sslContext = sslConfig.sslContextProvider().get(); + return new ConnectionConfig() { + @Override + public Function clientTransportFactory() { + return address -> { + TcpClient client = + TcpClient.create() + .addressSupplier(() -> address) + .secure(sslContextSpec -> sslContextSpec.sslContext(sslContext)); + return transportFactory.apply(client); + }; + } + + @Override + public Function brokerAddressSelector() { + return BrokerAddressSelectors.TCP_ADDRESS; + } + + @Override + public String connectionName() { + return connectionName; + } + }; + } + } + } + + class TcpBuilder extends TcpBasedBuilder { + + ConnectionConfig build() { + return tcpBased( + TcpClientTransport::create, + BrokerAddressSelectors.TCP_ADDRESS, + connectionName, + specBuilder); + } + } + + class WebSocketBuilder extends TcpBasedBuilder { + + ConnectionConfig build() { + return tcpBased( + WebsocketClientTransport::create, + BrokerAddressSelectors.WEBSOCKET_ADDRESS, + connectionName, + specBuilder); + } + } + + class Builder extends BaseBuilder { + Function clientTransportFactory; + Function brokerAddressSelector; + + public Builder withTransportFactory( + Function clientTransportFactory) { + this.clientTransportFactory = clientTransportFactory; + return this; + } + + public Builder withBrokerAddressSelector( + Function brokerAddressSelector) { + this.brokerAddressSelector = brokerAddressSelector; + return this; + } + + @Override + public ConnectionConfig build() { + return new ConnectionConfig() { + @Override + public Function clientTransportFactory() { + return clientTransportFactory; + } + + @Override + public Function brokerAddressSelector() { + return brokerAddressSelector; + } + + @Override + public String connectionName() { + return connectionName; + } + }; + } + } + } + + public static final class ClientBuilder { + + private AuthenticationConfig.DefaultSpec authenticationSpec = + new AuthenticationConfig.DefaultSpec(); + private DestinationInfoConfig.Builder destinationInfoConfigBuilder = + DestinationInfoConfig.builder(); + private ConnectionConfig.DefaultSpec connectionSpec = new ConnectionConfig.DefaultSpec(); + private KeepAliveConfig.DefaultSpec keepAliveConfigSpec = new KeepAliveConfig.DefaultSpec(); + private DiscoveryConfig.DefaultSpec discoveryConfigSpec = new DiscoveryConfig.DefaultSpec(); + private int poolSize = DefaultBuilderConfig.getPoolSize(); + private Tracer tracer; + + private Consumer authenticationBuilder = (__) -> {}; + private Consumer destinationInfoBuilder = (__) -> {}; + private Consumer keepAliveBuilder = (__) -> {}; + private Consumer connectionBuilder = (__) -> {}; + private Consumer discoveryBuilder = (__) -> {}; + + public ClientBuilder authentication(Consumer authenticationBuilder) { + this.authenticationBuilder = + this.authenticationBuilder.andThen(Objects.requireNonNull(authenticationBuilder)); + return this; + } + + public ClientBuilder destinationInfo( + Consumer destinationInfoBuilder) { + this.destinationInfoBuilder = + this.destinationInfoBuilder.andThen(Objects.requireNonNull(destinationInfoBuilder)); + return this; + } + + public ClientBuilder keepAlive(Consumer keepAliveBuilder) { + this.keepAliveBuilder = + this.keepAliveBuilder.andThen(Objects.requireNonNull(keepAliveBuilder)); + return this; + } + + public ClientBuilder connection(Consumer connectionBuilder) { + this.connectionBuilder = + this.connectionBuilder.andThen(Objects.requireNonNull(connectionBuilder)); + return this; + } + + public ClientBuilder discoveryStrategy(Consumer discoveryBuilder) { + this.discoveryBuilder = + this.discoveryBuilder.andThen(Objects.requireNonNull(discoveryBuilder)); + return this; + } + + public ClientBuilder poolSize(int poolSize) { + this.poolSize = poolSize; + return this; + } + + public ClientBuilder tracer(Tracer tracer) { + this.tracer = tracer; + return this; + } + + public BrokerService toService() { + return toService(new AbstractRSocket() {}, false); + } + + public RoutingBrokerService toRoutingService() { + return toRoutingService(new SimpleRouter()); + } + + public RoutingBrokerService toRoutingService(MutableRouter router) { + DefaultBrokerService brokerService = + (DefaultBrokerService) toService(new RoutingServerRSocket(router), true); + return new DefaultRoutingBrokerService(router, brokerService); + } + + public BrokerService toService(RSocket rSocket, boolean responderRequiresUnwrapping) { + destinationInfoBuilder.accept(destinationInfoConfigBuilder); + DestinationInfoConfig destinationInfoConfig = destinationInfoConfigBuilder.build(); + + connectionBuilder.accept(connectionSpec); + ConnectionConfig connectionConfig = connectionSpec.baseBuilder.build(); + + discoveryBuilder.accept(discoveryConfigSpec); + DiscoveryConfig discoveryConfig = discoveryConfigSpec.config; + + keepAliveBuilder.accept(keepAliveConfigSpec); + KeepAliveConfig keepAliveConfig = keepAliveConfigSpec.builder.build(); + + authenticationBuilder.accept(authenticationSpec); + AuthenticationConfig authenticationConfig = authenticationSpec.baseSpec.build(); + + short additionalFlags = DefaultBuilderConfig.getAdditionalConnectionFlags(); + + if (destinationInfoConfig.isPublic()) { + additionalFlags |= DestinationSetupFlyweight.FLAG_ENABLE_PUBLIC_ACCESS; + } + + if (authenticationConfig instanceof AuthenticationConfig.JwtAuthenticationConfig) { + additionalFlags |= DestinationSetupFlyweight.FLAG_ALTERNATIVE_AUTHENTICATION; + } + + return new DefaultBrokerService( + rSocket, + responderRequiresUnwrapping, + destinationInfoConfig.inetAddress(), + destinationInfoConfig.group(), + destinationInfoConfig.tags(), + connectionConfig.connectionName(), + connectionConfig.brokerAddressSelector(), + connectionConfig.clientTransportFactory(), + discoveryConfig.discoveryStrategy(), + keepAliveConfig instanceof KeepAliveConfig.NoKeepAliveConfig, + keepAliveConfig.tickPeriod(), + keepAliveConfig.acknowledgeTimeout(), + keepAliveConfig.missedAcknowledges(), + authenticationConfig.accessKey(), + Unpooled.wrappedBuffer(authenticationConfig.accessToken()), + additionalFlags, + poolSize, + tracer); + } + } +} diff --git a/netifi-broker-client/src/main/java/com/netifi/broker/BrokerService.java b/netifi-broker-client/src/main/java/com/netifi/broker/BrokerService.java index 4c80c209..38e83983 100644 --- a/netifi-broker-client/src/main/java/com/netifi/broker/BrokerService.java +++ b/netifi-broker-client/src/main/java/com/netifi/broker/BrokerService.java @@ -26,8 +26,14 @@ import io.rsocket.Payload; import io.rsocket.RSocket; import io.rsocket.util.ByteBufPayload; +import reactor.core.Disposable; +import reactor.core.publisher.Mono; + +public interface BrokerService extends Disposable, InstanceInfoAware { + default BrokerSocket group(CharSequence group) { + return group(group, Tags.empty()); + } -interface BrokerService { default BrokerSocket group(CharSequence group, Tags tags) { return new DefaultBrokerSocket( payload -> { @@ -42,6 +48,10 @@ default BrokerSocket group(CharSequence group, Tags tags) { this::selectRSocket); } + default BrokerSocket broadcast(CharSequence group) { + return broadcast(group, Tags.empty()); + } + default BrokerSocket broadcast(CharSequence group, Tags tags) { return new DefaultBrokerSocket( payload -> { @@ -56,6 +66,10 @@ default BrokerSocket broadcast(CharSequence group, Tags tags) { this::selectRSocket); } + default BrokerSocket shard(CharSequence group, ByteBuf shardKey) { + return shard(group, shardKey, Tags.empty()); + } + default BrokerSocket shard(CharSequence group, ByteBuf shardKey, Tags tags) { return new DefaultBrokerSocket( payload -> { @@ -72,4 +86,6 @@ default BrokerSocket shard(CharSequence group, ByteBuf shardKey, Tags tags) { } RSocket selectRSocket(); + + Mono onClose(); } diff --git a/netifi-broker-client/src/main/java/com/netifi/broker/DefaultBrokerService.java b/netifi-broker-client/src/main/java/com/netifi/broker/DefaultBrokerService.java index 07da2c06..afc6731a 100644 --- a/netifi-broker-client/src/main/java/com/netifi/broker/DefaultBrokerService.java +++ b/netifi-broker-client/src/main/java/com/netifi/broker/DefaultBrokerService.java @@ -38,7 +38,6 @@ import io.opentracing.Tracer; import io.rsocket.Payload; import io.rsocket.RSocket; -import io.rsocket.ResponderRSocket; import io.rsocket.transport.ClientTransport; import io.rsocket.util.ByteBufPayload; import java.net.InetAddress; @@ -60,7 +59,12 @@ import reactor.core.publisher.Mono; import reactor.core.publisher.MonoProcessor; -public class DefaultBrokerService implements BrokerService, Disposable { +public class DefaultBrokerService implements BrokerService, Disposable, InstanceInfoAware { + static { + // Set the Java DNS cache to 60 seconds + java.security.Security.setProperty("networkaddress.cache.ttl", "60"); + } + private static final Logger logger = LoggerFactory.getLogger(DefaultBrokerService.class); private static final double EXP_FACTOR = 4.0; private static final double DEFAULT_LOWER_QUANTILE = 0.5; @@ -77,8 +81,8 @@ public class DefaultBrokerService implements BrokerService, Disposable { private final InetAddress localInetAddress; private final String group; private final boolean keepalive; - private final long tickPeriodSeconds; - private final long ackTimeoutSeconds; + private final Duration tickPeriod; + private final Duration ackTimeout; private final int missedAcks; private final long accessKey; private final ByteBuf accessToken; @@ -100,37 +104,27 @@ public class DefaultBrokerService implements BrokerService, Disposable { private volatile Disposable disposable; public DefaultBrokerService( - List seedAddresses, - ResponderRSocket requestHandlingRSocket, + RSocket requestHandlingRSocket, boolean responderRequiresUnwrapping, InetAddress localInetAddress, String group, + Tags tags, + String connectionName, Function addressSelector, Function clientTransportFactory, - int poolSize, + DiscoveryStrategy discoveryStrategy, boolean keepalive, - long tickPeriodSeconds, - long ackTimeoutSeconds, + Duration tickPeriod, + Duration ackTimeout, int missedAcks, long accessKey, ByteBuf accessToken, - String connectionIdSeed, short additionalSetupFlags, - Tags tags, - Tracer tracer, - DiscoveryStrategy discoveryStrategy) { + int poolSize, + Tracer tracer) { this.discoveryStrategy = discoveryStrategy; - - if (discoveryStrategy == null) { - if (seedAddresses.isEmpty()) { - throw new IllegalStateException("seedAddress is empty"); - } else { - this.seedAddresses = seedAddresses; - } - } else { - this.seedAddresses = new CopyOnWriteArrayList<>(); - } + this.seedAddresses = new CopyOnWriteArrayList<>(); Objects.requireNonNull(accessToken); if (accessToken.readableBytes() == 0) { @@ -153,21 +147,19 @@ public DefaultBrokerService( this.selectRefreshTimeout = System.currentTimeMillis(); this.selectRefreshTimeoutDuration = 10_000; this.keepalive = keepalive; - this.tickPeriodSeconds = tickPeriodSeconds; - this.ackTimeoutSeconds = ackTimeoutSeconds; + this.tickPeriod = tickPeriod; + this.ackTimeout = ackTimeout; this.missedAcks = missedAcks; this.accessKey = accessKey; this.accessToken = accessToken; - this.connectionIdSeed = connectionIdSeed; + this.connectionIdSeed = connectionName; this.additionalSetupFlags = additionalSetupFlags; this.tags = tags; this.setupMetadata = new ArrayList<>(); this.onClose = MonoProcessor.create(); - if (discoveryStrategy != null) { - logger.info("discovery strategy found using " + discoveryStrategy.getClass()); - useDiscoveryStrategy(); - } + logger.info("discovery strategy found using " + discoveryStrategy.getClass()); + useDiscoveryStrategy(); this.client = new BrokerInfoServiceClient(group("com.netifi.broker.brokerServices", Tags.empty())); @@ -430,8 +422,8 @@ private WeightedReconnectingRSocket createWeightedReconnectingRSocket() { this::isDisposed, this::selectClientTransportSupplier, keepalive, - tickPeriodSeconds, - ackTimeoutSeconds, + tickPeriod, + ackTimeout, missedAcks, accessKey, accessToken, @@ -550,6 +542,23 @@ public RSocket selectRSocket() { return rSocket; } + public Tags tags() { + return tags; + } + + public long accessKey() { + return accessKey; + } + + public String groupName() { + return group; + } + + @Override + public Mono onClose() { + return onClose; + } + private static double algorithmicWeight( final WeightedRSocket socket, final Quantile lowerQuantile, final Quantile higherQuantile) { if (socket == null || socket.availability() == 0.0) { diff --git a/netifi-broker-client/src/main/java/com/netifi/broker/DefaultBuilderConfig.java b/netifi-broker-client/src/main/java/com/netifi/broker/DefaultBuilderConfig.java index 37bd0cba..5c3869b5 100644 --- a/netifi-broker-client/src/main/java/com/netifi/broker/DefaultBuilderConfig.java +++ b/netifi-broker-client/src/main/java/com/netifi/broker/DefaultBuilderConfig.java @@ -20,7 +20,6 @@ import com.typesafe.config.*; import java.net.InetAddress; import java.net.InetSocketAddress; -import java.net.SocketAddress; import java.net.UnknownHostException; import java.util.ArrayList; import java.util.List; @@ -29,7 +28,8 @@ import java.util.stream.Stream; /** - * Gets current default configuration for {@link BrokerClient.Builder}. Can be overriden with System + * Gets current default configuration for {@link BrokerFactory}. Can be overridden with + * System * properties, or if the application provides a config file. The builder will over-ride these values * if they are based directly in to the builder. Otherwise it will these values a default. */ @@ -293,8 +293,8 @@ static boolean getExportSystemMetrics() { return exportSystemMetrics; } - static List getSeedAddress() { - List seedAddresses = null; + static List getSeedAddress() { + List seedAddresses = null; try { String s = conf.getString("netifi.client.seedAddresses"); if (s != null) { diff --git a/netifi-broker-client/src/main/java/com/netifi/broker/DefaultRoutingBrokerService.java b/netifi-broker-client/src/main/java/com/netifi/broker/DefaultRoutingBrokerService.java new file mode 100644 index 00000000..b2aee753 --- /dev/null +++ b/netifi-broker-client/src/main/java/com/netifi/broker/DefaultRoutingBrokerService.java @@ -0,0 +1,73 @@ +/* + * Copyright 2019 The Netifi Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.netifi.broker; + +import com.netifi.common.tags.Tags; +import io.rsocket.RSocket; +import io.rsocket.ipc.MutableRouter; +import reactor.core.publisher.Mono; + +class DefaultRoutingBrokerService implements RoutingBrokerService, InstanceInfoAware { + + private final MutableRouter router; + private final DefaultBrokerService brokerService; + + public DefaultRoutingBrokerService(MutableRouter router, DefaultBrokerService brokerService) { + this.router = router; + this.brokerService = brokerService; + } + + @Override + public String groupName() { + return brokerService.groupName(); + } + + @Override + public Tags tags() { + return brokerService.tags(); + } + + @Override + public long accessKey() { + return brokerService.accessKey(); + } + + @Override + public MutableRouter router() { + return router; + } + + @Override + public RSocket selectRSocket() { + return brokerService.selectRSocket(); + } + + @Override + public Mono onClose() { + return brokerService.onClose(); + } + + @Override + public void dispose() { + brokerService.dispose(); + } + + @Override + public boolean isDisposed() { + return brokerService.isDisposed(); + } +} diff --git a/netifi-broker-client/src/main/java/com/netifi/broker/InstanceInfoAware.java b/netifi-broker-client/src/main/java/com/netifi/broker/InstanceInfoAware.java new file mode 100644 index 00000000..67ccba66 --- /dev/null +++ b/netifi-broker-client/src/main/java/com/netifi/broker/InstanceInfoAware.java @@ -0,0 +1,28 @@ +/* + * Copyright 2019 The Netifi Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.netifi.broker; + +import com.netifi.common.tags.Tags; + +public interface InstanceInfoAware { + + String groupName(); + + Tags tags(); + + long accessKey(); +} diff --git a/netifi-broker-client/src/main/java/com/netifi/broker/RoutingBrokerService.java b/netifi-broker-client/src/main/java/com/netifi/broker/RoutingBrokerService.java new file mode 100644 index 00000000..f7357d35 --- /dev/null +++ b/netifi-broker-client/src/main/java/com/netifi/broker/RoutingBrokerService.java @@ -0,0 +1,48 @@ +/* + * Copyright 2019 The Netifi Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.netifi.broker; + +import io.rsocket.Payload; +import io.rsocket.ipc.MutableRouter; +import io.rsocket.ipc.util.IPCChannelFunction; +import io.rsocket.ipc.util.IPCFunction; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +public interface RoutingBrokerService> + extends BrokerService { + MutableRouter router(); + + default SELF withFireAndForgetHandler(String route, IPCFunction> handler) { + router().withFireAndForgetRoute(route, handler); + return (SELF) this; + } + + default SELF withRequestResponseHandler(String route, IPCFunction> handler) { + router().withRequestResponseRoute(route, handler); + return (SELF) this; + } + + default SELF withRequestStreamHandler(String route, IPCFunction> handler) { + router().withRequestStreamRoute(route, handler); + return (SELF) this; + } + + default SELF withRequestChannelHandler(String route, IPCChannelFunction handler) { + router().withRequestChannelRoute(route, handler); + return (SELF) this; + } +} diff --git a/netifi-broker-client/src/main/java/com/netifi/broker/rsocket/WeightedReconnectingRSocket.java b/netifi-broker-client/src/main/java/com/netifi/broker/rsocket/WeightedReconnectingRSocket.java index 013cd75f..90a24de0 100644 --- a/netifi-broker-client/src/main/java/com/netifi/broker/rsocket/WeightedReconnectingRSocket.java +++ b/netifi-broker-client/src/main/java/com/netifi/broker/rsocket/WeightedReconnectingRSocket.java @@ -62,8 +62,8 @@ public class WeightedReconnectingRSocket implements WeightedRSocket { private final Supplier setupPayloadSupplier; private final BooleanSupplier running; private final boolean keepalive; - private final long tickPeriodSeconds; - private final long ackTimeoutSeconds; + private final Duration tickPeriod; + private final Duration ackTimeout; private final int missedAcks; private final RSocket requestHandlingRSocket; private final long accessKey; @@ -91,8 +91,8 @@ public class WeightedReconnectingRSocket implements WeightedRSocket { final BooleanSupplier running, final Supplier transportSupplier, final boolean keepalive, - final long tickPeriodSeconds, - final long ackTimeoutSeconds, + final Duration tickPeriod, + final Duration ackTimeout, final int missedAcks, final long accessKey, final ByteBuf accessToken, @@ -121,8 +121,8 @@ public class WeightedReconnectingRSocket implements WeightedRSocket { this.keepalive = keepalive; this.accessKey = accessKey; this.accessToken = accessToken; - this.tickPeriodSeconds = tickPeriodSeconds; - this.ackTimeoutSeconds = ackTimeoutSeconds; + this.tickPeriod = tickPeriod; + this.ackTimeout = ackTimeout; this.missedAcks = missedAcks; } @@ -132,8 +132,8 @@ public static WeightedReconnectingRSocket newInstance( final BooleanSupplier running, final Supplier transportSupplier, final boolean keepalive, - final long tickPeriodSeconds, - final long ackTimeoutSeconds, + final Duration tickPeriod, + final Duration ackTimeout, final int missedAcks, final long accessKey, final ByteBuf accessToken, @@ -147,8 +147,8 @@ public static WeightedReconnectingRSocket newInstance( running, transportSupplier, keepalive, - tickPeriodSeconds, - ackTimeoutSeconds, + tickPeriod, + ackTimeout, missedAcks, accessKey, accessToken, @@ -197,18 +197,9 @@ private ClientRSocketFactory getClientFactory() { ClientRSocketFactory connect = RSocketFactory.connect().frameDecoder(PayloadDecoder.ZERO_COPY); if (keepalive) { - connect = - connect - .keepAlive() - .keepAliveTickPeriod(Duration.ofSeconds(tickPeriodSeconds)) - .keepAliveAckTimeout(Duration.ofSeconds(ackTimeoutSeconds)) - .keepAliveMissedAcks(missedAcks); + connect = connect.keepAlive(tickPeriod, ackTimeout, missedAcks); } else { - connect - .keepAlive() - .keepAliveTickPeriod(Duration.ofSeconds(0)) - .keepAliveAckTimeout(Duration.ofSeconds(0)) - .keepAliveMissedAcks(missedAcks); + connect = connect.keepAlive(Duration.ofSeconds(0), Duration.ofSeconds(0), missedAcks); } return connect.setupPayload(setupPayloadSupplier.get()); @@ -635,10 +626,10 @@ public String toString() { + running + ", keepalive=" + keepalive - + ", tickPeriodSeconds=" - + tickPeriodSeconds - + ", ackTimeoutSeconds=" - + ackTimeoutSeconds + + ", tickPeriodMillis=" + + tickPeriod.toMillis() + + ", ackTimeoutMillis=" + + ackTimeout.toMillis() + ", missedAcks=" + missedAcks + ", accessKey=" diff --git a/netifi-broker-client/src/test/java/com/netifi/broker/DefaultBuilderConfigTest.java b/netifi-broker-client/src/test/java/com/netifi/broker/DefaultBuilderConfigTest.java index 34fdae54..a7858e80 100644 --- a/netifi-broker-client/src/test/java/com/netifi/broker/DefaultBuilderConfigTest.java +++ b/netifi-broker-client/src/test/java/com/netifi/broker/DefaultBuilderConfigTest.java @@ -18,7 +18,6 @@ import com.netifi.common.tags.Tag; import com.netifi.common.tags.Tags; import java.net.InetSocketAddress; -import java.net.SocketAddress; import java.util.List; import java.util.Optional; import org.junit.Assert; @@ -31,7 +30,7 @@ public class DefaultBuilderConfigTest { @Test public void testShouldFindSingleSeedAddress() { System.setProperty("netifi.client.seedAddresses", "localhost:8001"); - List seedAddress = DefaultBuilderConfig.getSeedAddress(); + List seedAddress = DefaultBuilderConfig.getSeedAddress(); Assert.assertNotNull(seedAddress); Assert.assertEquals(1, seedAddress.size()); @@ -43,7 +42,7 @@ public void testShouldFindSingleSeedAddress() { public void testShouldFindMultipleSeedAddresses() { System.setProperty( "netifi.client.seedAddresses", "localhost:8001,localhost:8002,localhost:8003"); - List seedAddress = DefaultBuilderConfig.getSeedAddress(); + List seedAddress = DefaultBuilderConfig.getSeedAddress(); Assert.assertNotNull(seedAddress); Assert.assertEquals(3, seedAddress.size()); @@ -54,13 +53,13 @@ public void testShouldFindMultipleSeedAddresses() { @Test(expected = IllegalStateException.class) public void testShouldThrowExceptionForAddressMissingPort() { System.setProperty("netifi.client.seedAddresses", "localhost:8001,localhost,localhost:8003"); - List seedAddress = DefaultBuilderConfig.getSeedAddress(); + List seedAddress = DefaultBuilderConfig.getSeedAddress(); } @Test(expected = IllegalStateException.class) public void testShouldThrowExceptionForInvalidAddress() { System.setProperty("netifi.client.seedAddresses", "no way im valid"); - List seedAddress = DefaultBuilderConfig.getSeedAddress(); + List seedAddress = DefaultBuilderConfig.getSeedAddress(); } @Test @@ -75,7 +74,7 @@ public void testShouldParseTagsSuccessfully() { @Test public void testShouldReturnNull() { - List seedAddress = DefaultBuilderConfig.getSeedAddress(); + List seedAddress = DefaultBuilderConfig.getSeedAddress(); Assert.assertNull(seedAddress); } diff --git a/netifi-broker-client/src/test/java/com/netifi/broker/integration/BrokerClientIntegrationTest.java b/netifi-broker-client/src/test/java/com/netifi/broker/integration/BrokerClientIntegrationTest.java index fb8ef979..c3f5db40 100644 --- a/netifi-broker-client/src/test/java/com/netifi/broker/integration/BrokerClientIntegrationTest.java +++ b/netifi-broker-client/src/test/java/com/netifi/broker/integration/BrokerClientIntegrationTest.java @@ -16,14 +16,14 @@ package com.netifi.broker.integration; import com.google.protobuf.Empty; -import com.netifi.broker.BrokerClient; +import com.netifi.broker.BrokerFactory; +import com.netifi.broker.RoutingBrokerService; import com.netifi.broker.rsocket.BrokerSocket; import com.netifi.broker.testing.protobuf.SimpleRequest; import com.netifi.broker.testing.protobuf.SimpleResponse; import com.netifi.broker.testing.protobuf.SimpleService; import com.netifi.broker.testing.protobuf.SimpleServiceClient; import com.netifi.broker.testing.protobuf.SimpleServiceServer; -import com.netifi.common.tags.Tags; import io.netty.buffer.ByteBuf; import java.time.Duration; import java.util.Optional; @@ -48,39 +48,36 @@ public class BrokerClientIntegrationTest { private static final String host = "localhost"; private static final int port = 8001; private static final int server_port = 8001; - private static BrokerClient server; - private static BrokerClient brokerClient; + private static RoutingBrokerService server; + private static RoutingBrokerService brokerClient; private static BrokerSocket brokerSocket; @BeforeClass public static void setup() { server = - BrokerClient.tcp() - .keepalive(false) - .group("test.server") - .destination("server") - .accessKey(accessKey) - .accessToken(accessToken) - .host(host) - .port(server_port) - .build(); + BrokerFactory.connect() + .destinationInfo(spec -> spec.groupName("test.server").destinationTag("server")) + .keepAlive(spec -> spec.noKeepAlive()) + .authentication(spec -> spec.simple().key(accessKey).token(accessToken)) + .connection(spec -> spec.tcp()) + .discoveryStrategy(spec -> spec.simple(port, host)) + .toRoutingService(); brokerClient = - BrokerClient.tcp() - .keepalive(false) - .group("test.brokerClient") - .destination("brokerClient") - .accessKey(accessKey) - .accessToken(accessToken) - .host(host) - .port(port) - .build(); - - server.addService( - new SimpleServiceServer( - new DefaultSimpleService(), Optional.empty(), Optional.empty(), Optional.empty())); - - brokerSocket = brokerClient.groupServiceSocket("test.server", Tags.empty()); + BrokerFactory.connect() + .keepAlive(spec -> spec.noKeepAlive()) + .connection(spec -> spec.tcp()) + .destinationInfo( + spec -> spec.groupName("test.brokerClient").destinationTag("brokerClient")) + .authentication(spec -> spec.simple().key(accessKey).token(accessToken)) + .discoveryStrategy(spec -> spec.simple(port, host)) + .toRoutingService(); + + new SimpleServiceServer( + new DefaultSimpleService(), Optional.empty(), Optional.empty(), Optional.empty()) + .selfRegister(server.router()); + + brokerSocket = brokerClient.group("test.server"); } @Test diff --git a/netifi-broker-client/src/test/java/com/netifi/broker/rsocket/WeightedReconnectingRSocketTest.java b/netifi-broker-client/src/test/java/com/netifi/broker/rsocket/WeightedReconnectingRSocketTest.java index b9af9263..f8bc978e 100644 --- a/netifi-broker-client/src/test/java/com/netifi/broker/rsocket/WeightedReconnectingRSocketTest.java +++ b/netifi-broker-client/src/test/java/com/netifi/broker/rsocket/WeightedReconnectingRSocketTest.java @@ -39,8 +39,8 @@ public void testShouldWaitForSocketWhenNotPresent() { () -> true, Mockito.mock(Supplier.class), false, - 0, - 0, + Duration.ZERO, + Duration.ZERO, 0, 0, Unpooled.EMPTY_BUFFER, @@ -66,8 +66,8 @@ public void testShouldSetRSocketAndReturnSocket() { () -> true, Mockito.mock(Supplier.class), false, - 0, - 0, + Duration.ZERO, + Duration.ZERO, 0, 0, Unpooled.EMPTY_BUFFER, @@ -109,8 +109,8 @@ public void testShouldEmitNewRSocketAfterSubscribing() throws Exception { () -> true, Mockito.mock(Supplier.class), false, - 0, - 0, + Duration.ZERO, + Duration.ZERO, 0, 0, Unpooled.EMPTY_BUFFER, @@ -140,8 +140,8 @@ public void testShouldWaitAfterRSocketCloses() { () -> true, Mockito.mock(Supplier.class), false, - 0, - 0, + Duration.ZERO, + Duration.ZERO, 0, 0, Unpooled.EMPTY_BUFFER, diff --git a/netifi-broker-info-idl/gradle/dependency-locks/testCompileClasspath.lockfile~merged b/netifi-broker-info-idl/gradle/dependency-locks/testCompileClasspath.lockfile~merged deleted file mode 100644 index 597c5914..00000000 --- a/netifi-broker-info-idl/gradle/dependency-locks/testCompileClasspath.lockfile~merged +++ /dev/null @@ -1,35 +0,0 @@ -# This is a Gradle generated file for dependency locking. -# Manual edits can break the build and are not advised. -# This file is expected to be part of source control. -com.google.protobuf:protobuf-java:3.6.1 -io.netty:netty-buffer:4.1.31.Final -io.netty:netty-codec-http2:4.1.31.Final -io.netty:netty-codec-http:4.1.31.Final -io.netty:netty-codec-socks:4.1.31.Final -io.netty:netty-codec:4.1.31.Final -io.netty:netty-common:4.1.31.Final -io.netty:netty-handler-proxy:4.1.31.Final -io.netty:netty-handler:4.1.31.Final -io.netty:netty-resolver:4.1.31.Final -io.netty:netty-transport-native-epoll:4.1.31.Final -io.netty:netty-transport-native-unix-common:4.1.31.Final -io.netty:netty-transport:4.1.31.Final -io.projectreactor.netty:reactor-netty:0.8.5.RELEASE -io.projectreactor:reactor-core:3.2.6.RELEASE -io.projectreactor:reactor-test:3.2.6.RELEASE -io.rsocket:rsocket-core:0.11.17.2 -io.rsocket:rsocket-transport-local:0.11.17.2 -io.rsocket:rsocket-transport-netty:0.11.17.2 -javax.inject:javax.inject:1 -junit:junit:4.12 -net.bytebuddy:byte-buddy-agent:1.9.7 -net.bytebuddy:byte-buddy:1.9.7 -org.apache.logging.log4j:log4j-api:2.11.2 -org.apache.logging.log4j:log4j-core:2.11.2 -org.apache.logging.log4j:log4j-slf4j-impl:2.11.2 -org.hamcrest:hamcrest-core:1.3 -org.hdrhistogram:HdrHistogram:2.1.10 -org.mockito:mockito-core:2.25.0 -org.objenesis:objenesis:2.6 -org.reactivestreams:reactive-streams:1.0.2 -org.slf4j:slf4j-api:1.7.25 diff --git a/netifi-broker-mgmt-idl/gradle/dependency-locks/protobuf.lockfile~merged b/netifi-broker-mgmt-idl/gradle/dependency-locks/protobuf.lockfile~merged deleted file mode 100644 index 656c5dbc..00000000 --- a/netifi-broker-mgmt-idl/gradle/dependency-locks/protobuf.lockfile~merged +++ /dev/null @@ -1,3 +0,0 @@ -# This is a Gradle generated file for dependency locking. -# Manual edits can break the build and are not advised. -# This file is expected to be part of source control. diff --git a/netifi-broker-mgmt-idl/gradle/dependency-locks/testCompileClasspath.lockfile~merged b/netifi-broker-mgmt-idl/gradle/dependency-locks/testCompileClasspath.lockfile~merged deleted file mode 100644 index 597c5914..00000000 --- a/netifi-broker-mgmt-idl/gradle/dependency-locks/testCompileClasspath.lockfile~merged +++ /dev/null @@ -1,35 +0,0 @@ -# This is a Gradle generated file for dependency locking. -# Manual edits can break the build and are not advised. -# This file is expected to be part of source control. -com.google.protobuf:protobuf-java:3.6.1 -io.netty:netty-buffer:4.1.31.Final -io.netty:netty-codec-http2:4.1.31.Final -io.netty:netty-codec-http:4.1.31.Final -io.netty:netty-codec-socks:4.1.31.Final -io.netty:netty-codec:4.1.31.Final -io.netty:netty-common:4.1.31.Final -io.netty:netty-handler-proxy:4.1.31.Final -io.netty:netty-handler:4.1.31.Final -io.netty:netty-resolver:4.1.31.Final -io.netty:netty-transport-native-epoll:4.1.31.Final -io.netty:netty-transport-native-unix-common:4.1.31.Final -io.netty:netty-transport:4.1.31.Final -io.projectreactor.netty:reactor-netty:0.8.5.RELEASE -io.projectreactor:reactor-core:3.2.6.RELEASE -io.projectreactor:reactor-test:3.2.6.RELEASE -io.rsocket:rsocket-core:0.11.17.2 -io.rsocket:rsocket-transport-local:0.11.17.2 -io.rsocket:rsocket-transport-netty:0.11.17.2 -javax.inject:javax.inject:1 -junit:junit:4.12 -net.bytebuddy:byte-buddy-agent:1.9.7 -net.bytebuddy:byte-buddy:1.9.7 -org.apache.logging.log4j:log4j-api:2.11.2 -org.apache.logging.log4j:log4j-core:2.11.2 -org.apache.logging.log4j:log4j-slf4j-impl:2.11.2 -org.hamcrest:hamcrest-core:1.3 -org.hdrhistogram:HdrHistogram:2.1.10 -org.mockito:mockito-core:2.25.0 -org.objenesis:objenesis:2.6 -org.reactivestreams:reactive-streams:1.0.2 -org.slf4j:slf4j-api:1.7.25 diff --git a/netifi-common/build.gradle b/netifi-common/build.gradle index cb208183..f1e92f54 100644 --- a/netifi-common/build.gradle +++ b/netifi-common/build.gradle @@ -11,7 +11,7 @@ dependencies { testCompile 'junit:junit' testCompile 'javax.inject:javax.inject' testCompile 'io.projectreactor:reactor-test' - testCompile "com.google.protobuf:protobuf-java" + testCompile 'com.google.protobuf:protobuf-java' testCompile 'org.hdrhistogram:HdrHistogram' testCompile 'org.apache.logging.log4j:log4j-api' testCompile 'org.apache.logging.log4j:log4j-core' diff --git a/netifi-metrics-influx/src/main/java/com/netifi/broker/influx/BrokerInfluxBridge.java b/netifi-metrics-influx/src/main/java/com/netifi/broker/influx/BrokerInfluxBridge.java index 92b4720f..699aab07 100644 --- a/netifi-metrics-influx/src/main/java/com/netifi/broker/influx/BrokerInfluxBridge.java +++ b/netifi-metrics-influx/src/main/java/com/netifi/broker/influx/BrokerInfluxBridge.java @@ -16,13 +16,25 @@ package com.netifi.broker.influx; import com.google.common.util.concurrent.AtomicDouble; -import com.netifi.broker.BrokerClient; -import io.micrometer.core.instrument.*; +import com.netifi.broker.BrokerFactory; +import com.netifi.broker.RoutingBrokerService; +import io.micrometer.core.instrument.Clock; +import io.micrometer.core.instrument.Counter; +import io.micrometer.core.instrument.DistributionSummary; import io.micrometer.core.instrument.Meter; +import io.micrometer.core.instrument.Tag; +import io.micrometer.core.instrument.Timer; import io.micrometer.influx.InfluxConfig; import io.micrometer.influx.InfluxMeterRegistry; import io.netty.buffer.ByteBuf; -import io.rsocket.rpc.metrics.om.*; +import io.rsocket.rpc.metrics.om.MeterId; +import io.rsocket.rpc.metrics.om.MeterMeasurement; +import io.rsocket.rpc.metrics.om.MeterTag; +import io.rsocket.rpc.metrics.om.MeterType; +import io.rsocket.rpc.metrics.om.MetricsSnapshot; +import io.rsocket.rpc.metrics.om.MetricsSnapshotHandler; +import io.rsocket.rpc.metrics.om.MetricsSnapshotHandlerServer; +import io.rsocket.rpc.metrics.om.Skew; import java.time.Duration; import java.util.List; import java.util.Optional; @@ -73,15 +85,13 @@ public static void main(String... args) { logger.info("broker port - {}", brokerPort); logger.info("access key - {}", accessKey); - BrokerClient brokerClient = - BrokerClient.tcp() - .accessKey(accessKey) - .accessToken(accessToken) - .group(group) - .host(brokerHost) - .port(brokerPort) - .destination("standaloneInfluxBridge") - .build(); + RoutingBrokerService brokerClient = + BrokerFactory.connect() + .connection(spec -> spec.tcp()) + .authentication(spec -> spec.simple().key(accessKey).token(accessToken)) + .destinationInfo(spec -> spec.groupName(group).destinationTag("standaloneInfluxBridge")) + .discoveryStrategy(spec -> spec.simple(brokerPort, brokerHost)) + .toRoutingService(); InfluxConfig config = new InfluxConfig() { @@ -116,8 +126,7 @@ public String retentionDuration() { }; AtomicLong influxThreadCount = new AtomicLong(); - brokerClient.addService( - new MetricsSnapshotHandlerServer( + new MetricsSnapshotHandlerServer( new BrokerInfluxBridge( Optional.empty(), new InfluxMeterRegistry( @@ -131,7 +140,8 @@ public String retentionDuration() { })), Optional.empty(), Optional.empty(), - Optional.empty())); + Optional.empty()) + .selfRegister(brokerClient.router()); brokerClient.onClose().block(); } diff --git a/netifi-metrics-micrometer/src/main/java/com/netifi/broker/micrometer/BrokerMeterRegistrySupplier.java b/netifi-metrics-micrometer/src/main/java/com/netifi/broker/micrometer/BrokerMeterRegistrySupplier.java index 36e90804..92666ce6 100644 --- a/netifi-metrics-micrometer/src/main/java/com/netifi/broker/micrometer/BrokerMeterRegistrySupplier.java +++ b/netifi-metrics-micrometer/src/main/java/com/netifi/broker/micrometer/BrokerMeterRegistrySupplier.java @@ -16,7 +16,7 @@ package com.netifi.broker.micrometer; import com.netflix.spectator.atlas.AtlasConfig; -import com.netifi.broker.BrokerClient; +import com.netifi.broker.BrokerService; import io.micrometer.atlas.AtlasMeterRegistry; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Tag; @@ -37,13 +37,12 @@ public class BrokerMeterRegistrySupplier implements Supplier { @Inject public BrokerMeterRegistrySupplier( - BrokerClient netifi, + BrokerService netifi, Optional metricsGroup, Optional stepInMillis, Optional export) { Objects.requireNonNull(netifi, "must provide a BrokerClient instance"); - BrokerSocket brokerSocket = netifi.groupServiceSocket(metricsGroup.orElse("com.netifi.broker.metrics"), com.netifi.common.tags.Tags - .empty()); + BrokerSocket brokerSocket = netifi.group(metricsGroup.orElse("com.netifi.broker.metrics")); MetricsSnapshotHandlerClient client = new MetricsSnapshotHandlerClient(brokerSocket); @@ -70,8 +69,7 @@ public Duration step() { }); List tags = - netifi - .getTags() + netifi.tags() .stream() .map(tag -> Tag.of(tag.getKey(), tag.getValue())) .collect(Collectors.toList()); @@ -79,8 +77,8 @@ public Duration step() { .config() .commonTags( Tags.of( - "accessKey", String.valueOf(netifi.getAccesskey()), - "group", netifi.getGroupName()) + "accessKey", String.valueOf(netifi.accessKey()), + "group", netifi.groupName()) .and(tags)); new BrokerOperatingSystemMetrics(registry, Collections.EMPTY_LIST); diff --git a/netifi-metrics-prometheus/src/main/java/com/netifi/broker/prometheus/BrokerPrometheusBridge.java b/netifi-metrics-prometheus/src/main/java/com/netifi/broker/prometheus/BrokerPrometheusBridge.java index 9437942d..175f6359 100644 --- a/netifi-metrics-prometheus/src/main/java/com/netifi/broker/prometheus/BrokerPrometheusBridge.java +++ b/netifi-metrics-prometheus/src/main/java/com/netifi/broker/prometheus/BrokerPrometheusBridge.java @@ -15,16 +15,28 @@ */ package com.netifi.broker.prometheus; -import com.netifi.broker.BrokerClient; -import io.micrometer.core.instrument.*; +import com.netifi.broker.BrokerFactory; +import com.netifi.broker.RoutingBrokerService; +import io.micrometer.core.instrument.Counter; +import io.micrometer.core.instrument.DistributionSummary; import io.micrometer.core.instrument.Meter; +import io.micrometer.core.instrument.Tag; +import io.micrometer.core.instrument.Tags; +import io.micrometer.core.instrument.Timer; import io.micrometer.core.instrument.distribution.DistributionStatisticConfig; import io.micrometer.prometheus.PrometheusConfig; import io.micrometer.prometheus.PrometheusMeterRegistry; import io.netty.buffer.ByteBuf; import io.netty.handler.codec.http.HttpResponseStatus; import io.prometheus.client.exporter.common.TextFormat; -import io.rsocket.rpc.metrics.om.*; +import io.rsocket.rpc.metrics.om.MeterId; +import io.rsocket.rpc.metrics.om.MeterMeasurement; +import io.rsocket.rpc.metrics.om.MeterTag; +import io.rsocket.rpc.metrics.om.MeterType; +import io.rsocket.rpc.metrics.om.MetricsSnapshot; +import io.rsocket.rpc.metrics.om.MetricsSnapshotHandler; +import io.rsocket.rpc.metrics.om.MetricsSnapshotHandlerServer; +import io.rsocket.rpc.metrics.om.Skew; import java.time.Duration; import java.util.List; import java.util.Optional; @@ -86,18 +98,16 @@ public static void main(String... args) { logger.info("broker port - {}", brokerPort); logger.info("access key - {}", accessKey); - BrokerClient brokerClient = - BrokerClient.tcp() - .accessKey(accessKey) - .accessToken(accessToken) - .group(group) - .host(brokerHost) - .port(brokerPort) - .destination("standalonePrometheusBridge") - .build(); + RoutingBrokerService brokerClient = + BrokerFactory.connect() + .connection(spec -> spec.tcp()) + .authentication(spec -> spec.simple().key(accessKey).token(accessToken)) + .destinationInfo( + spec -> spec.groupName(group).destinationTag("standalonePrometheusBridge")) + .discoveryStrategy(spec -> spec.simple(brokerPort, brokerHost)) + .toRoutingService(); - brokerClient.addService( - new MetricsSnapshotHandlerServer( + new MetricsSnapshotHandlerServer( new BrokerPrometheusBridge( Optional.empty(), new PrometheusMeterRegistry(PrometheusConfig.DEFAULT), @@ -106,7 +116,8 @@ public static void main(String... args) { Optional.ofNullable(metricsUrl)), Optional.empty(), Optional.empty(), - Optional.empty())); + Optional.empty()) + .selfRegister(brokerClient.router()); brokerClient.onClose().block(); } diff --git a/netifi-spring-boot-autoconfigure/build.gradle b/netifi-spring-boot-autoconfigure/build.gradle index c5a825e1..ac150cda 100644 --- a/netifi-spring-boot-autoconfigure/build.gradle +++ b/netifi-spring-boot-autoconfigure/build.gradle @@ -4,12 +4,6 @@ plugins { description = 'Netifi Spring Boot Autoconfigure' -dependencyManagement { - imports { - mavenBom "org.springframework.boot:spring-boot-dependencies:${springBootDependenciesVersion}" - } -} - dependencies { compile project(':netifi-spring-core') compile project(':netifi-spring-messaging') diff --git a/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientAutoConfiguration.java b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientAutoConfiguration.java index f8ad09b6..5626de9c 100644 --- a/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientAutoConfiguration.java +++ b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientAutoConfiguration.java @@ -16,23 +16,23 @@ package com.netifi.spring.boot; import com.netifi.broker.BrokerClient; +import com.netifi.broker.BrokerFactory; +import com.netifi.broker.BrokerService; +import com.netifi.broker.RoutingBrokerService; import com.netifi.broker.discovery.*; import com.netifi.broker.micrometer.BrokerMeterRegistrySupplier; -import com.netifi.broker.rsocket.transport.BrokerAddressSelectors; import com.netifi.broker.tracing.BrokerTracerSupplier; import com.netifi.common.tags.Tag; import com.netifi.common.tags.Tags; -import com.netifi.spring.boot.support.BrokerClientConfigurer; +import com.netifi.spring.boot.support.BrokerServiceConfigurer; import com.netifi.spring.core.BrokerClientTagSupplier; import com.netifi.spring.core.config.BrokerClientConfiguration; import io.micrometer.core.instrument.MeterRegistry; -import io.netty.handler.ssl.OpenSsl; -import io.netty.handler.ssl.SslContextBuilder; -import io.netty.handler.ssl.SslProvider; -import io.netty.handler.ssl.util.InsecureTrustManagerFactory; import io.opentracing.Tracer; -import io.rsocket.transport.netty.client.TcpClientTransport; -import io.rsocket.transport.netty.client.WebsocketClientTransport; +import io.rsocket.ipc.MutableRouter; +import io.rsocket.ipc.Router; +import io.rsocket.ipc.routing.SimpleRouter; +import java.time.Duration; import java.util.List; import java.util.Optional; import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor; @@ -52,24 +52,23 @@ import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.core.annotation.Order; import org.springframework.util.StringUtils; -import reactor.core.Exceptions; -import reactor.netty.tcp.TcpClient; @Configuration @EnableConfigurationProperties(BrokerClientProperties.class) @AutoConfigureBefore(BrokerClientConfiguration.class) public class BrokerClientAutoConfiguration { - static BrokerClient configureBrokerClient(List configurers) { - BrokerClient.CustomizableBuilder builder = BrokerClient.customizable(); + static RoutingBrokerService configureBrokerClient( + MutableRouter router, List configurers) { + BrokerFactory.ClientBuilder clientBuilder = BrokerFactory.connect(); AnnotationAwareOrderComparator.sort(configurers); - for (BrokerClientConfigurer configurer : configurers) { - builder = configurer.configure(builder); + for (BrokerServiceConfigurer configurer : configurers) { + configurer.configure(clientBuilder); } - return builder.build(); + return clientBuilder.toRoutingService(router); } @Bean(name = "internalScanClassPathBeanDefinitionRegistryPostProcessor") @@ -79,7 +78,7 @@ public BeanDefinitionRegistryPostProcessor scanClassPathBeanDefinitionRegistryPo @Bean @Order(Ordered.HIGHEST_PRECEDENCE) - public BrokerClientConfigurer propertiesBasedBrokerClientConfigurer( + public BrokerServiceConfigurer propertiesBasedBrokerClientConfigurer( BrokerClientTagSupplier brokerClientTagSupplier, BrokerClientProperties brokerClientProperties) { return builder -> { @@ -88,23 +87,19 @@ public BrokerClientConfigurer propertiesBasedBrokerClientConfigurer( BrokerClientProperties.BrokerProperties broker = brokerClientProperties.getBroker(); BrokerClientProperties.DiscoveryProperties discovery = brokerClientProperties.getDiscovery(); BrokerClientProperties.KeepAliveProperties keepalive = brokerClientProperties.getKeepalive(); - - if (!StringUtils.isEmpty(brokerClientProperties.getDestination())) { - builder.destination(brokerClientProperties.getDestination()); - } - BrokerClientProperties.ConnectionType connectionType; + DiscoveryStrategy discoveryStrategy; if (!StringUtils.isEmpty(broker.getHostname())) { // support the legacy usecase first - builder.host(broker.getHostname()); - builder.port(broker.getPort()); + discoveryStrategy = + new StaticListDiscoveryStrategy( + new StaticListDiscoveryConfig(broker.getPort(), broker.getHostname())); connectionType = broker.getConnectionType(); } else if (!StringUtils.isEmpty(discovery.getEnvironment())) { // if not legacy, then we're propbably using the new discovery api. - DiscoveryStrategy discoveryStrategy; switch (discovery.getEnvironment()) { case "static": BrokerClientProperties.DiscoveryProperties.StaticProperties staticProperties = @@ -150,120 +145,97 @@ public BrokerClientConfigurer propertiesBasedBrokerClientConfigurer( throw new RuntimeException( "unsupported discovery strategy " + discovery.getEnvironment()); } - builder.discoveryStrategy(discoveryStrategy); + } else { throw new RuntimeException("discovery not configured and required"); } - - Tags tags = Tags.empty(); - if (brokerClientProperties.getTags() != null && !brokerClientProperties.getTags().isEmpty()) { - for (String t : brokerClientProperties.getTags()) { - String[] split = t.split(":"); - Tag tag = Tag.of(split[0], split[1]); - tags = tags.and(tag); - } - } - - Tags suppliedTags = brokerClientTagSupplier.get(); - - if (suppliedTags != null) { - tags = tags.and(suppliedTags); - } - - boolean sslDisabled = ssl.isDisabled(); - - if (connectionType == BrokerClientProperties.ConnectionType.TCP) { - builder.addressSelector(BrokerAddressSelectors.TCP_ADDRESS); - builder.clientTransportFactory( - address -> { - if (sslDisabled) { - TcpClient client = TcpClient.create().addressSupplier(() -> address); - return TcpClientTransport.create(client); - } else { - TcpClient client = - TcpClient.create() - .addressSupplier(() -> address) - .secure( - spec -> { - final SslProvider sslProvider; - if (OpenSsl.isAvailable()) { - sslProvider = SslProvider.OPENSSL_REFCNT; - } else { - sslProvider = SslProvider.JDK; - } - - try { - spec.sslContext( - SslContextBuilder.forClient() - .trustManager(InsecureTrustManagerFactory.INSTANCE) - .sslProvider(sslProvider) - .build()); - } catch (Exception sslException) { - throw Exceptions.propagate(sslException); - } - }); - - return TcpClientTransport.create(client); - } - }); - } else if (connectionType == BrokerClientProperties.ConnectionType.WS) { - builder.addressSelector(BrokerAddressSelectors.WEBSOCKET_ADDRESS); - builder.tags(tags); - builder.clientTransportFactory( - address -> { - if (sslDisabled) { - TcpClient client = TcpClient.create().addressSupplier(() -> address); - return WebsocketClientTransport.create(client); - } else { - TcpClient client = - TcpClient.create() - .addressSupplier(() -> address) - .secure( - spec -> { - final SslProvider sslProvider; - if (OpenSsl.isAvailable()) { - sslProvider = SslProvider.OPENSSL_REFCNT; - } else { - sslProvider = SslProvider.JDK; - } - - try { - spec.sslContext( - SslContextBuilder.forClient() - .trustManager(InsecureTrustManagerFactory.INSTANCE) - .sslProvider(sslProvider) - .build()); - } catch (Exception sslException) { - throw Exceptions.propagate(sslException); - } - }); - return WebsocketClientTransport.create(client); - } - }); - } - - return builder - .keepalive(keepalive.isEnabled()) - .ackTimeoutSeconds(keepalive.getAckTimeoutSeconds()) - .tickPeriodSeconds(keepalive.getTickPeriodSeconds()) - .missedAcks(keepalive.getMissedAcks()) - .accessKey(access.getKey()) - .accessToken(access.getToken()) - .group(brokerClientProperties.getGroup()) - .isPublic(brokerClientProperties.isPublic()) + builder + .discoveryStrategy(spec -> spec.custom(discoveryStrategy)) + .connection( + spec -> { + boolean sslDisabled = ssl.isDisabled(); + BrokerFactory.ConnectionConfig.TcpBasedBuilder tcpSpec = null; + switch (connectionType) { + case TCP: + tcpSpec = spec.tcp(); + break; + case WS: + tcpSpec = spec.ws(); + break; + } + + if (tcpSpec != null) { + tcpSpec.ssl( + sslSpec -> { + if (sslDisabled) { + sslSpec.unsecured(); + } else { + sslSpec.secured(); + } + }); + } + }) + .destinationInfo( + spec -> { + if (!StringUtils.isEmpty(brokerClientProperties.getDestination())) { + spec.destinationTag(brokerClientProperties.getDestination()); + } + + Tags tags = Tags.empty(); + if (brokerClientProperties.getTags() != null + && !brokerClientProperties.getTags().isEmpty()) { + for (String t : brokerClientProperties.getTags()) { + String[] split = t.split(":"); + Tag tag = Tag.of(split[0], split[1]); + tags = tags.and(tag); + } + } + + Tags suppliedTags = brokerClientTagSupplier.get(); + + if (suppliedTags != null) { + tags = tags.and(suppliedTags); + } + if (brokerClientProperties.isPublic()) { + spec.asPublicDestination(); + } else { + spec.asPrivateDestination(); + } + + spec.tags(tags).groupName(brokerClientProperties.getGroup()); + }) + .keepAlive( + spec -> { + if (keepalive.isEnabled()) { + spec.configure() + .acknowledgeTimeout(Duration.ofSeconds(keepalive.getAckTimeoutSeconds())) + .tickPeriod(Duration.ofSeconds(keepalive.getTickPeriodSeconds())) + .missedAcknowledges(keepalive.getMissedAcks()); + } + }) + .authentication(spec -> spec.simple().token(access.getToken()).key(access.getKey())) .poolSize(brokerClientProperties.getPoolSize()); }; } @Configuration @ConditionalOnMissingBean(BrokerClientTagSupplier.class) - public static class BrokerTagSupplierConfiguations { + public static class BrokerTagSupplierConfigurations { @Bean public BrokerClientTagSupplier brokerClientTagSupplier() { return Tags::empty; } } + @Configuration + @ConditionalOnMissingBean(Router.class) + public static class RouterConfiguration { + @Bean + public MutableRouter mutableRouter() { + return new SimpleRouter(); + } + } + @Configuration @ConditionalOnMissingBean(MeterRegistry.class) @ConditionalOnClass(BrokerMeterRegistrySupplier.class) @@ -271,7 +243,7 @@ public static class MetricsConfigurations { @Bean public MeterRegistry meterRegistry( - BrokerClient brokerClient, BrokerClientProperties properties) { + BrokerService brokerClient, BrokerClientProperties properties) { return new BrokerMeterRegistrySupplier( brokerClient, Optional.of(properties.getMetrics().getGroup()), @@ -287,7 +259,7 @@ public MeterRegistry meterRegistry( public static class TracingConfigurations { @Bean - public Tracer tracer(BrokerClient brokerClient, BrokerClientProperties properties) { + public Tracer tracer(BrokerService brokerClient, BrokerClientProperties properties) { return new BrokerTracerSupplier(brokerClient, Optional.of(properties.getTracing().getGroup())) .get(); } @@ -295,14 +267,15 @@ public Tracer tracer(BrokerClient brokerClient, BrokerClientProperties propertie @Configuration @ConditionalOnNotWebApplication - @ConditionalOnMissingBean(BrokerClient.class) + @ConditionalOnMissingBean({BrokerService.class}) public static class NonWebBrokerClientConfiguration { @Bean - public BrokerClient brokerClient( - List configurers, + public RoutingBrokerService routingBrokerService( + MutableRouter router, + List configurers, ConfigurableApplicationContext context) { - BrokerClient brokerClient = configureBrokerClient(configurers); + RoutingBrokerService brokerClient = configureBrokerClient(router, configurers); startDaemonAwaitThread(brokerClient); @@ -318,9 +291,9 @@ public BrokerClient brokerClient( return brokerClient; } - private void startDaemonAwaitThread(BrokerClient brokerClient) { + private void startDaemonAwaitThread(BrokerService brokerClient) { Thread awaitThread = - new Thread("broker-client-thread") { + new Thread("broker-service-thread") { @Override public void run() { @@ -331,16 +304,27 @@ public void run() { awaitThread.setDaemon(false); awaitThread.start(); } + + @Bean + public BrokerClient routingBrokerService(RoutingBrokerService routingBrokerService) { + return BrokerClient.from(routingBrokerService); + } } @Configuration @ConditionalOnWebApplication - @ConditionalOnMissingBean(BrokerClient.class) + @ConditionalOnMissingBean({BrokerService.class}) public static class WebBrokerClientConfiguration { @Bean - public BrokerClient brokerClient(List configurers) { - return configureBrokerClient(configurers); + public RoutingBrokerService routingBrokerService( + MutableRouter router, List configurers) { + return configureBrokerClient(router, configurers); + } + + @Bean + public BrokerClient routingBrokerService(RoutingBrokerService routingBrokerService) { + return BrokerClient.from(routingBrokerService); } } } diff --git a/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientMessagingAutoConfiguration.java b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientMessagingAutoConfiguration.java index 51412f11..c7c0988e 100644 --- a/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientMessagingAutoConfiguration.java +++ b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientMessagingAutoConfiguration.java @@ -16,34 +16,34 @@ package com.netifi.spring.boot; -import com.netifi.broker.BrokerClient; +import com.netifi.broker.BrokerService; import com.netifi.spring.messaging.BrokerClientRequesterMethodArgumentResolver; import com.netifi.spring.messaging.MessagingRSocketRequesterClientFactory; +import com.netifi.spring.messaging.MessagingRouter; import io.micrometer.core.instrument.MeterRegistry; -import io.netty.buffer.ByteBufAllocator; -import io.netty.buffer.Unpooled; import io.opentracing.Tracer; import io.rsocket.AbstractRSocket; -import io.rsocket.ConnectionSetupPayload; import io.rsocket.RSocket; import io.rsocket.RSocketFactory; -import io.rsocket.frame.SetupFrameFlyweight; +import io.rsocket.ipc.MutableRouter; import io.rsocket.transport.netty.server.TcpServerTransport; -import java.time.Duration; import java.util.Optional; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.rsocket.RSocketProperties; import org.springframework.boot.autoconfigure.rsocket.RSocketStrategiesAutoConfiguration; import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.boot.rsocket.context.RSocketServerBootstrap; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.messaging.rsocket.MessageHandlerAcceptor; import org.springframework.messaging.rsocket.RSocketRequester; -import org.springframework.messaging.rsocket.RSocketRequesterMethodArgumentResolver; import org.springframework.messaging.rsocket.RSocketStrategies; +import org.springframework.messaging.rsocket.annotation.support.RSocketMessageHandler; +import org.springframework.messaging.rsocket.annotation.support.RSocketRequesterMethodArgumentResolver; +import org.springframework.util.MimeTypeUtils; /** * {@link EnableAutoConfiguration Auto-configuration} for Spring RSocket support in Spring @@ -61,62 +61,60 @@ public class BrokerClientMessagingAutoConfiguration { private static final RSocket STUB_RSOCKET = new AbstractRSocket() {}; @Bean - @ConditionalOnMissingBean - public MessageHandlerAcceptor messageHandlerAcceptor( + public MutableRouter messagingCustomizer( + RSocketProperties rSocketProperties, BrokerClientProperties brokerClientProperties, BrokerClientMessagingProperties properties, DefaultListableBeanFactory factory, RSocketStrategies rSocketStrategies, - BrokerClient brokerClient) { - BrokerClientProperties.KeepAliveProperties keepalive = brokerClientProperties.getKeepalive(); - Duration tickPeriod = Duration.ofSeconds(keepalive.getTickPeriodSeconds()); - Duration ackTimeout = Duration.ofSeconds(keepalive.getAckTimeoutSeconds()); - int missedAcks = keepalive.getMissedAcks(); + RSocketMessageHandler handler) { + return new MessagingRouter( + MimeTypeUtils.ALL, + MimeTypeUtils.ALL, + rSocketStrategies.metadataExtractor(), + handler, + rSocketStrategies.routeMatcher(), + rSocketStrategies); + } - ConnectionSetupPayload connectionSetupPayload = - // FIXME: hardcoded mime for responder - ConnectionSetupPayload.create( - SetupFrameFlyweight.encode( - ByteBufAllocator.DEFAULT, - false, - (int) tickPeriod.toMillis(), - (int) (ackTimeout.toMillis() + tickPeriod.toMillis() * missedAcks), - Unpooled.EMPTY_BUFFER, - "text/plain", - "text/plain", - Unpooled.EMPTY_BUFFER, - Unpooled.EMPTY_BUFFER)); - MessageHandlerAcceptor acceptor = new MessageHandlerAcceptor(); - acceptor.setRSocketStrategies(rSocketStrategies); - acceptor + @Bean + @ConditionalOnMissingBean + public RSocketServerBootstrap messageHandlerAcceptor( + BrokerClientMessagingProperties properties, + DefaultListableBeanFactory factory, + RSocketStrategies rSocketStrategies, + RSocketMessageHandler handler, + BrokerService brokerClient, + Optional registry, + Optional tracer) { + RSocketServerBootstrap bootstrap = new NetifiBootstrap(brokerClient); + + handler .getArgumentResolverConfigurer() .getCustomResolvers() .removeIf(r -> r instanceof RSocketRequesterMethodArgumentResolver); - acceptor + handler .getArgumentResolverConfigurer() .addCustomResolver( new BrokerClientRequesterMethodArgumentResolver( - properties.getName(), brokerClient, factory, rSocketStrategies)); - - brokerClient.addNamedRSocket( - properties.getName(), acceptor.apply(connectionSetupPayload, STUB_RSOCKET)); + brokerClient, + factory, + rSocketStrategies, + registry.orElse(null), + tracer.orElse(null))); - return acceptor; + return bootstrap; } @Bean public MessagingRSocketRequesterClientFactory messagingRSocketRequesterClientFactory( BrokerClientMessagingProperties properties, - BrokerClient brokerClient, + BrokerService brokerClient, RSocketStrategies rSocketStrategies, Optional registry, Optional tracer) { return new MessagingRSocketRequesterClientFactory( - properties.getName(), - brokerClient, - registry.orElse(null), - tracer.orElse(null), - rSocketStrategies); + brokerClient, registry.orElse(null), tracer.orElse(null), rSocketStrategies); } } diff --git a/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientMessagingProperties.java b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientMessagingProperties.java index 2b01234f..97df5b74 100644 --- a/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientMessagingProperties.java +++ b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientMessagingProperties.java @@ -15,8 +15,6 @@ */ package com.netifi.spring.boot; -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.validation.annotation.Validated; @@ -26,15 +24,4 @@ */ @ConfigurationProperties("netifi.client.messaging") @Validated -public class BrokerClientMessagingProperties { - - @NotEmpty @NotNull private String name = "spring-messaging"; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } -} +public class BrokerClientMessagingProperties {} diff --git a/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/NetifiBootstrap.java b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/NetifiBootstrap.java new file mode 100644 index 00000000..68529430 --- /dev/null +++ b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/NetifiBootstrap.java @@ -0,0 +1,70 @@ +/* + * Copyright 2019 The Netifi Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.netifi.spring.boot; + +import com.netifi.broker.BrokerService; +import java.net.InetSocketAddress; +import org.springframework.boot.rsocket.context.RSocketServerBootstrap; +import org.springframework.boot.rsocket.context.RSocketServerInitializedEvent; +import org.springframework.boot.rsocket.server.RSocketServer; +import org.springframework.boot.rsocket.server.RSocketServerException; +import org.springframework.context.ApplicationEventPublisher; + +public class NetifiBootstrap extends RSocketServerBootstrap { + + private final BrokerService brokerClient; + private ApplicationEventPublisher eventPublisher; + + public NetifiBootstrap(BrokerService client) { + super((__) -> null, (setup, sendingSocket) -> null); + brokerClient = client; + } + + @Override + public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) { + this.eventPublisher = applicationEventPublisher; + } + + @Override + public void start() { + this.eventPublisher.publishEvent( + new RSocketServerInitializedEvent( + new RSocketServer() { + @Override + public void start() throws RSocketServerException {} + + @Override + public void stop() throws RSocketServerException { + brokerClient.dispose(); + } + + @Override + public InetSocketAddress address() { + return InetSocketAddress.createUnresolved("localhost", 0); + } + })); + } + + @Override + public void stop() { + this.brokerClient.dispose(); + } + + @Override + public boolean isRunning() { + return !brokerClient.isDisposed(); + } +} diff --git a/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/support/BrokerClientConfigurer.java b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/support/BrokerClientConfigurer.java index 5bc067d6..1fb7c039 100644 --- a/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/support/BrokerClientConfigurer.java +++ b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/support/BrokerClientConfigurer.java @@ -16,9 +16,15 @@ package com.netifi.spring.boot.support; import com.netifi.broker.BrokerClient; +import com.netifi.broker.BrokerFactory; @FunctionalInterface -public interface BrokerClientConfigurer { +@Deprecated +public interface BrokerClientConfigurer extends BrokerServiceConfigurer { BrokerClient.CustomizableBuilder configure(BrokerClient.CustomizableBuilder builder); + + default void configure(BrokerFactory.ClientBuilder builder) { + // FIXME + } } diff --git a/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/support/BrokerServiceConfigurer.java b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/support/BrokerServiceConfigurer.java new file mode 100644 index 00000000..5b065ed4 --- /dev/null +++ b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/support/BrokerServiceConfigurer.java @@ -0,0 +1,24 @@ +/* + * Copyright 2019 The Netifi Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.netifi.spring.boot.support; + +import com.netifi.broker.BrokerFactory; + +@FunctionalInterface +public interface BrokerServiceConfigurer { + + void configure(BrokerFactory.ClientBuilder builder); +} diff --git a/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/BrokerClientSpringIntegrationTest.java b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/BrokerClientSpringIntegrationTest.java index 71993379..5e580981 100644 --- a/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/BrokerClientSpringIntegrationTest.java +++ b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/BrokerClientSpringIntegrationTest.java @@ -18,7 +18,6 @@ import com.netifi.broker.info.BrokerInfoService; import com.netifi.broker.info.BrokerInfoServiceClient; import com.netifi.spring.DefaultExternalIdlClient; -import com.netifi.spring.boot.BrokerClientAutoConfiguration; import com.netifi.spring.core.BroadcastAwareClientFactory; import com.netifi.spring.core.DestinationAwareClientFactory; import com.netifi.spring.core.GroupAwareClientFactory; @@ -26,7 +25,6 @@ import com.netifi.spring.core.annotation.BrokerClient; import com.netifi.spring.core.annotation.Destination; import com.netifi.spring.core.annotation.Group; -import com.netifi.spring.core.config.BrokerClientConfiguration; import io.rsocket.rpc.metrics.om.MetricsSnapshotHandler; import io.rsocket.rpc.metrics.om.MetricsSnapshotHandlerClient; import org.junit.jupiter.api.Assertions; @@ -35,13 +33,11 @@ import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Primary; -import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit.jupiter.SpringExtension; @ExtendWith(SpringExtension.class) @@ -87,6 +83,8 @@ public class BrokerClientSpringIntegrationTest { @Autowired com.netifi.broker.BrokerClient brokerClient; + @Autowired com.netifi.broker.BrokerService brokerService; + @Autowired ConfigurableApplicationContext context; @Test @@ -114,5 +112,11 @@ static class TestConfiguration { public com.netifi.broker.BrokerClient mockedBrokerClient() { return Mockito.mock(com.netifi.broker.BrokerClient.class); } + + @Bean + @Primary + public com.netifi.broker.RoutingBrokerService mockedRoutingBrokerService() { + return Mockito.mock(com.netifi.broker.RoutingBrokerService.class); + } } } diff --git a/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/ClientConfigurationIntegrationTest.java b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/ClientConfigurationIntegrationTest.java index ad4daa00..a140bc4e 100644 --- a/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/ClientConfigurationIntegrationTest.java +++ b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/ClientConfigurationIntegrationTest.java @@ -18,9 +18,7 @@ import static org.mockito.ArgumentMatchers.any; import com.netifi.broker.BrokerClient; -import com.netifi.spring.boot.BrokerClientAutoConfiguration; import com.netifi.spring.boot.support.BrokerClientConfigurer; -import com.netifi.spring.core.config.BrokerClientConfiguration; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -30,19 +28,21 @@ import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; import org.springframework.test.context.junit.jupiter.SpringExtension; @ExtendWith(SpringExtension.class) -@SpringBootTest +@SpringBootTest(classes = { + com.netifi.spring.boot.BrokerClientAutoConfiguration.class, + com.netifi.spring.boot.BrokerClientMessagingAutoConfiguration.class, + com.netifi.spring.core.config.BrokerClientConfiguration.class +}) public class ClientConfigurationIntegrationTest { @Autowired @Qualifier("mock2") BrokerClientConfigurer configurer; - @Autowired - BrokerClient brokerClient; + @Autowired BrokerClient brokerClient; @Test public void testThatConfigurerWorks() { @@ -56,7 +56,7 @@ public void testThatConfigurerWorks() { } @org.springframework.boot.test.context.TestConfiguration -// @ComponentScan + // @ComponentScan static class TestConfiguration { @Bean diff --git a/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/MessageHandler.java b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/MessageHandlerTest.java similarity index 93% rename from netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/MessageHandler.java rename to netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/MessageHandlerTest.java index 022146b3..1a9ecb58 100644 --- a/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/MessageHandler.java +++ b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/MessageHandlerTest.java @@ -22,10 +22,10 @@ @Controller @MessageMapping("test") -public class MessageHandler { +public class MessageHandlerTest { @MessageMapping("process") public Mono process(@Payload Mono data) { - return Mono.just("Echo: " + data); + return data.map(m -> "Echo: " + m); } } diff --git a/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/SpringMessagingIntegrationTest.java b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/SpringMessagingIntegrationTest.java index 55111375..ce4d4871 100644 --- a/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/SpringMessagingIntegrationTest.java +++ b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/SpringMessagingIntegrationTest.java @@ -29,7 +29,7 @@ public class SpringMessagingIntegrationTest { public static GenericContainer redis = - new GenericContainer("netifi/broker:1.6.4") + new GenericContainer("netifi/broker:1.6.10") .withExposedPorts(8001, 7001, 6001, 8101) .withEnv( "BROKER_SERVER_OPTS", @@ -50,7 +50,8 @@ public class SpringMessagingIntegrationTest { @Test public void tests() { Assert.assertNotNull(requester.rsocket()); - - requester.route("test.process").data("test").retrieveMono(String.class).log().block(); + Assert.assertEquals( + "Echo: test", + requester.route("test.process").data("test").retrieveMono(String.class).log().block()); } } diff --git a/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/TestApplication.java b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/TestApplication.java deleted file mode 100644 index 2f32858b..00000000 --- a/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/TestApplication.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2019 The Netifi Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.netifi.spring.boot.test; - -import com.netifi.spring.boot.BrokerClientAutoConfiguration; -import com.netifi.spring.boot.BrokerClientMessagingAutoConfiguration; -import com.netifi.spring.core.config.BrokerClientConfiguration; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.ImportAutoConfiguration; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -@ImportAutoConfiguration({ - BrokerClientMessagingAutoConfiguration.class, - BrokerClientAutoConfiguration.class, - BrokerClientConfiguration.class, -}) -public class TestApplication { - public static void main(String[] args) { - SpringApplication.run(TestApplication.class, args); - } -} diff --git a/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/TestIdlServiceServer.java b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/TestIdlServiceServer.java index 327144f8..f52ef3bc 100644 --- a/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/TestIdlServiceServer.java +++ b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/TestIdlServiceServer.java @@ -15,14 +15,8 @@ */ package com.netifi.spring.boot.test; -import java.util.Map; - -import io.rsocket.Payload; -import io.rsocket.ipc.util.IPCChannelFunction; -import io.rsocket.ipc.util.IPCFunction; +import io.rsocket.ipc.MutableRouter; import io.rsocket.rpc.AbstractRSocketService; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; @javax.annotation.Generated( value = "by RSocket RPC proto compiler (version 0.2.2)", @@ -39,10 +33,5 @@ public Class getServiceClass() { } @Override - public void selfRegister(Map>> fireAndForgetRegistry, - Map>> requestResponseRegistry, - Map>> requestStreamRegistry, - Map requestChannelRegistry) { - - } + public void selfRegister(MutableRouter router) {} } diff --git a/netifi-spring-boot-autoconfigure/src/test/resources/META-INF/spring.factories b/netifi-spring-boot-autoconfigure/src/test/resources/META-INF/spring.factories new file mode 100644 index 00000000..181bad26 --- /dev/null +++ b/netifi-spring-boot-autoconfigure/src/test/resources/META-INF/spring.factories @@ -0,0 +1,5 @@ +# Auto Configure +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ + com.netifi.spring.boot.BrokerClientAutoConfiguration,\ + com.netifi.spring.boot.BrokerClientMessagingAutoConfiguration,\ + com.netifi.spring.core.config.BrokerClientConfiguration \ No newline at end of file diff --git a/netifi-spring-boot-starter/build.gradle b/netifi-spring-boot-starter/build.gradle index d34fe877..f3175f5a 100644 --- a/netifi-spring-boot-starter/build.gradle +++ b/netifi-spring-boot-starter/build.gradle @@ -7,6 +7,7 @@ description = 'Netifi Spring Boot Starter' dependencies { compile project(':netifi-spring-boot-autoconfigure') compile project(':netifi-spring-core') + compile project(':netifi-spring-messaging') compile 'org.springframework.boot:spring-boot-starter' } diff --git a/netifi-spring-core/build.gradle b/netifi-spring-core/build.gradle index 4563680e..28c1626d 100644 --- a/netifi-spring-core/build.gradle +++ b/netifi-spring-core/build.gradle @@ -4,14 +4,6 @@ plugins { description = 'Netifi Spring Core' -dependencyManagement { - imports { - mavenBom "org.springframework.boot:spring-boot-dependencies:${springBootDependenciesVersion}" - mavenBom "io.netty:netty-bom:${nettyVersion}" - mavenBom "io.projectreactor:reactor-bom:${reactorBomVersion}" - } -} - dependencies { compile project(':netifi-common') compile project(':netifi-broker-client') diff --git a/netifi-spring-core/src/main/java/com/netifi/spring/core/BrokerClientApplicationEventListener.java b/netifi-spring-core/src/main/java/com/netifi/spring/core/BrokerClientApplicationEventListener.java index 72f9e3fc..52413160 100644 --- a/netifi-spring-core/src/main/java/com/netifi/spring/core/BrokerClientApplicationEventListener.java +++ b/netifi-spring-core/src/main/java/com/netifi/spring/core/BrokerClientApplicationEventListener.java @@ -15,7 +15,7 @@ */ package com.netifi.spring.core; -import com.netifi.broker.BrokerClient; +import com.netifi.broker.RoutingBrokerService; import io.rsocket.rpc.RSocketRpcService; import java.util.Map; import org.springframework.context.ApplicationContext; @@ -23,9 +23,9 @@ import org.springframework.context.event.EventListener; public class BrokerClientApplicationEventListener { - private final BrokerClient brokerClient; + private final RoutingBrokerService brokerClient; - public BrokerClientApplicationEventListener(BrokerClient brokerClient) { + public BrokerClientApplicationEventListener(RoutingBrokerService brokerClient) { this.brokerClient = brokerClient; } @@ -35,6 +35,6 @@ public void onApplicationEvent(ContextRefreshedEvent event) { Map rSocketServiceMap = context.getBeansOfType(RSocketRpcService.class); - rSocketServiceMap.values().forEach(brokerClient::addService); + rSocketServiceMap.values().forEach(s -> s.selfRegister(brokerClient.router())); } } diff --git a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClientBeanDefinitionRegistryPostProcessor.java b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClientBeanDefinitionRegistryPostProcessor.java index 24f55806..04d93bb7 100644 --- a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClientBeanDefinitionRegistryPostProcessor.java +++ b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClientBeanDefinitionRegistryPostProcessor.java @@ -204,12 +204,12 @@ private static Class resolveClass(BeanDefinition beanDefinition) private static ResolvableType resolveResolvableType(BeanDefinition beanDefinition) { if (beanDefinition instanceof RootBeanDefinition) { - return ((RootBeanDefinition) beanDefinition).getResolvableType(); + return ResolvableType.forClass(((RootBeanDefinition) beanDefinition).getTargetType()); } else if (beanDefinition instanceof GenericBeanDefinition) { return ResolvableType.forClass(((GenericBeanDefinition) beanDefinition).getBeanClass()); + } else { + return beanDefinition.getResolvableType(); } - - throw new IllegalArgumentException("Impossible to resolve bean type"); } private static boolean findRealImplementationAndMarkAsPrimary( diff --git a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClientStaticFactory.java b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClientStaticFactory.java index dac66236..636a683f 100644 --- a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClientStaticFactory.java +++ b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClientStaticFactory.java @@ -49,7 +49,7 @@ public class BrokerClientStaticFactory { /** * Creates an instance of the correct Netifi Broker client for injection into a annotated field. * - * @return an instance of a {@link com.netifi.broker.BrokerClient} client + * @return an instance of a {@link com.netifi.broker.BrokerService} client */ public static Object getBeanInstance( final DefaultListableBeanFactory beanFactory, @@ -234,7 +234,7 @@ private static String getBeanName(BrokerClient brokerClientAnnotation, Class } static T createBrokerClient( - com.netifi.broker.BrokerClient brokerClient, + com.netifi.broker.BrokerService brokerClient, BrokerClient.Type routeType, String group, String destination, @@ -272,7 +272,7 @@ static T createBrokerClient( } public static BrokerSocket createBrokerRSocket( - com.netifi.broker.BrokerClient brokerClient, + com.netifi.broker.BrokerService brokerClient, BrokerClient.Type routeType, String group, String destination, @@ -281,14 +281,14 @@ public static BrokerSocket createBrokerRSocket( switch (routeType) { case BROADCAST: - brokerSocket = brokerClient.broadcastServiceSocket(group, tags); + brokerSocket = brokerClient.broadcast(group, tags); break; case GROUP: - brokerSocket = brokerClient.groupServiceSocket(group, tags); + brokerSocket = brokerClient.group(group, tags); break; case DESTINATION: brokerSocket = - brokerClient.groupServiceSocket( + brokerClient.group( group, StringUtils.isEmpty(destination) ? tags diff --git a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/RpcBrokerClientFactorySupport.java b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/RpcBrokerClientFactorySupport.java index 292fc87f..8dee60cd 100644 --- a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/RpcBrokerClientFactorySupport.java +++ b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/RpcBrokerClientFactorySupport.java @@ -8,12 +8,12 @@ public class RpcBrokerClientFactorySupport implements BrokerClientFactorySupport { - private final com.netifi.broker.BrokerClient brokerClient; + private final com.netifi.broker.BrokerService brokerClient; private final Tracer tracer; private final MeterRegistry meterRegistry; public RpcBrokerClientFactorySupport( - com.netifi.broker.BrokerClient client, MeterRegistry registry, Tracer tracer) { + com.netifi.broker.BrokerService client, MeterRegistry registry, Tracer tracer) { brokerClient = client; this.tracer = tracer; meterRegistry = registry; diff --git a/netifi-spring-core/src/main/java/com/netifi/spring/core/config/BrokerClientConfiguration.java b/netifi-spring-core/src/main/java/com/netifi/spring/core/config/BrokerClientConfiguration.java index 1d45417b..58f74ce9 100644 --- a/netifi-spring-core/src/main/java/com/netifi/spring/core/config/BrokerClientConfiguration.java +++ b/netifi-spring-core/src/main/java/com/netifi/spring/core/config/BrokerClientConfiguration.java @@ -15,7 +15,8 @@ */ package com.netifi.spring.core.config; -import com.netifi.broker.BrokerClient; +import com.netifi.broker.BrokerService; +import com.netifi.broker.RoutingBrokerService; import com.netifi.broker.info.BrokerInfoService; import com.netifi.broker.info.BrokerInfoServiceClient; import com.netifi.broker.info.BrokerInfoServiceServer; @@ -36,16 +37,15 @@ import org.springframework.context.annotation.AnnotatedBeanDefinitionReader; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.core.annotation.Order; @Configuration public class BrokerClientConfiguration implements ApplicationContextAware { @Bean public RpcBrokerClientFactorySupport rpcBrokerClientFactorySupport( - BrokerClient brokerClient, Optional registry, Optional tracer) { + BrokerService brokerService, Optional registry, Optional tracer) { return new RpcBrokerClientFactorySupport( - brokerClient, registry.orElse(null), tracer.orElse(null)); + brokerService, registry.orElse(null), tracer.orElse(null)); } @Bean(name = "internalBrokerClientBeanDefinitionRegistryPostProcessor") @@ -56,7 +56,7 @@ public RpcBrokerClientFactorySupport rpcBrokerClientFactorySupport( @Bean public BrokerClientApplicationEventListener brokerClientApplicationEventListener( - BrokerClient brokerClient) { + RoutingBrokerService brokerClient) { return new BrokerClientApplicationEventListener(brokerClient); } diff --git a/netifi-spring-core/src/test/java/com/netifi/spring/core/TestIdlServiceServer.java b/netifi-spring-core/src/test/java/com/netifi/spring/core/TestIdlServiceServer.java index b20f6344..69b5957b 100644 --- a/netifi-spring-core/src/test/java/com/netifi/spring/core/TestIdlServiceServer.java +++ b/netifi-spring-core/src/test/java/com/netifi/spring/core/TestIdlServiceServer.java @@ -15,14 +15,8 @@ */ package com.netifi.spring.core; -import java.util.Map; - -import io.rsocket.Payload; -import io.rsocket.ipc.util.IPCChannelFunction; -import io.rsocket.ipc.util.IPCFunction; +import io.rsocket.ipc.MutableRouter; import io.rsocket.rpc.AbstractRSocketService; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; @javax.annotation.Generated( value = "by RSocket RPC proto compiler (version 0.2.10)", @@ -39,10 +33,5 @@ public Class getServiceClass() { } @Override - public void selfRegister(Map>> fireAndForgetRegistry, - Map>> requestResponseRegistry, - Map>> requestStreamRegistry, - Map requestChannelRegistry) { - - } + public void selfRegister(MutableRouter router) {} } diff --git a/netifi-spring-core/src/test/java/com/netifi/spring/core/TestableConfiguration.java b/netifi-spring-core/src/test/java/com/netifi/spring/core/TestableConfiguration.java index 385f0378..9b9ffe2d 100644 --- a/netifi-spring-core/src/test/java/com/netifi/spring/core/TestableConfiguration.java +++ b/netifi-spring-core/src/test/java/com/netifi/spring/core/TestableConfiguration.java @@ -16,6 +16,7 @@ package com.netifi.spring.core; import com.netifi.broker.BrokerClient; +import com.netifi.broker.RoutingBrokerService; import com.netifi.spring.core.config.EnableBrokerClient; import org.mockito.Mockito; import org.springframework.context.annotation.Bean; @@ -30,6 +31,12 @@ public BrokerClient brokerClient() { return Mockito.mock(BrokerClient.class); } + @Bean + public RoutingBrokerService routingBrokerService() { + return Mockito.mock(RoutingBrokerService.class); + } + + @Bean public TestIdlImpl testIdlImpl() { return new TestIdlImpl(); diff --git a/netifi-spring-messaging/build.gradle b/netifi-spring-messaging/build.gradle index 06f75503..0a2eb58e 100644 --- a/netifi-spring-messaging/build.gradle +++ b/netifi-spring-messaging/build.gradle @@ -4,12 +4,6 @@ plugins { description = 'Netifi Spring Core' -dependencyManagement { - imports { - mavenBom "org.springframework.boot:spring-boot-dependencies:${springBootDependenciesVersion}" - } -} - dependencies { compile project(":netifi-spring-core") diff --git a/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/BrokerClientRequesterMethodArgumentResolver.java b/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/BrokerClientRequesterMethodArgumentResolver.java index db7d9830..689ec02e 100644 --- a/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/BrokerClientRequesterMethodArgumentResolver.java +++ b/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/BrokerClientRequesterMethodArgumentResolver.java @@ -1,17 +1,17 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2019 The Netifi Authors * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * https://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.netifi.spring.messaging; @@ -21,7 +21,9 @@ import static com.netifi.spring.messaging.RSocketRequesterStaticFactory.resolveBrokerClientRSocket; import static org.springframework.core.annotation.AnnotatedElementUtils.getMergedAnnotation; -import com.netifi.broker.BrokerClient; +import com.netifi.broker.BrokerService; +import io.micrometer.core.instrument.MeterRegistry; +import io.opentracing.Tracer; import io.rsocket.RSocket; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.core.MethodParameter; @@ -32,29 +34,25 @@ import org.springframework.util.Assert; import reactor.core.publisher.Mono; -/** - * Resolves arguments of type {@link RSocket} that can be used for making requests to the remote - * peer. - * - * @author Rossen Stoyanchev - * @since 5.2 - */ public class BrokerClientRequesterMethodArgumentResolver implements HandlerMethodArgumentResolver { - private final String rSocketName; - private final BrokerClient brokerClient; + private final BrokerService brokerClient; private final DefaultListableBeanFactory listableBeanFactory; private final RSocketStrategies rSocketStrategies; + private final MeterRegistry registry; + private final Tracer tracer; public BrokerClientRequesterMethodArgumentResolver( - String rSocketName, - BrokerClient client, + BrokerService client, DefaultListableBeanFactory factory, - RSocketStrategies strategies) { - this.rSocketName = rSocketName; - brokerClient = client; - listableBeanFactory = factory; - rSocketStrategies = strategies; + RSocketStrategies strategies, + MeterRegistry registry, + Tracer tracer) { + this.brokerClient = client; + this.listableBeanFactory = factory; + this.rSocketStrategies = strategies; + this.registry = registry; + this.tracer = tracer; } @Override @@ -77,15 +75,15 @@ public Mono resolveArgument(MethodParameter parameter, Message messag if (RSocketRequester.class.equals(type)) { return Mono.just( createRSocketRequester( - rSocketName, brokerClient, brokerClientAnnotation, resolveTags(listableBeanFactory, brokerClientAnnotation), - rSocketStrategies)); + rSocketStrategies, + registry, + tracer)); } else if (RSocket.class.isAssignableFrom(type)) { return Mono.just( resolveBrokerClientRSocket( - rSocketName, brokerClient, brokerClientAnnotation.type(), brokerClientAnnotation.group(), diff --git a/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/MessagingRSocketRequesterClientFactory.java b/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/MessagingRSocketRequesterClientFactory.java index e4c5b457..85efb460 100644 --- a/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/MessagingRSocketRequesterClientFactory.java +++ b/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/MessagingRSocketRequesterClientFactory.java @@ -1,3 +1,18 @@ +/* + * Copyright 2019 The Netifi Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.netifi.spring.messaging; import static com.netifi.spring.messaging.RSocketRequesterStaticFactory.createRSocketRequester; @@ -12,19 +27,16 @@ public class MessagingRSocketRequesterClientFactory implements BrokerClientFactorySupport { - private final String rSocketName; - private final com.netifi.broker.BrokerClient brokerClient; + private final com.netifi.broker.BrokerService brokerClient; private final Tracer tracer; private final MeterRegistry meterRegistry; private final RSocketStrategies rSocketStrategies; public MessagingRSocketRequesterClientFactory( - String rSocketName, - com.netifi.broker.BrokerClient brokerClient, + com.netifi.broker.BrokerService brokerClient, MeterRegistry meterRegistry, Tracer tracer, RSocketStrategies strategies) { - this.rSocketName = rSocketName; this.brokerClient = brokerClient; this.tracer = tracer; this.meterRegistry = meterRegistry; @@ -42,7 +54,6 @@ public T lookup( Class tClass, BrokerClient.Type type, String methodGroup, Tags methodTags) { return (T) createRSocketRequester( - rSocketName, brokerClient, type, methodGroup, diff --git a/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/MessagingRouter.java b/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/MessagingRouter.java new file mode 100644 index 00000000..b6e280ef --- /dev/null +++ b/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/MessagingRouter.java @@ -0,0 +1,335 @@ +/* + * Copyright 2019 The Netifi Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.netifi.spring.messaging; + +import io.rsocket.ConnectionSetupPayload; +import io.rsocket.Payload; +import io.rsocket.frame.FrameType; +import io.rsocket.ipc.MutableRouter; +import io.rsocket.ipc.util.IPCChannelFunction; +import io.rsocket.ipc.util.IPCFunction; +import java.util.Map; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.Function; +import org.springframework.core.io.buffer.DataBuffer; +import org.springframework.core.io.buffer.DataBufferUtils; +import org.springframework.core.io.buffer.NettyDataBuffer; +import org.springframework.lang.Nullable; +import org.springframework.messaging.Message; +import org.springframework.messaging.MessageHeaders; +import org.springframework.messaging.ReactiveMessageHandler; +import org.springframework.messaging.handler.DestinationPatternsMessageCondition; +import org.springframework.messaging.handler.invocation.reactive.HandlerMethodReturnValueHandler; +import org.springframework.messaging.rsocket.MetadataExtractor; +import org.springframework.messaging.rsocket.PayloadUtils; +import org.springframework.messaging.rsocket.RSocketStrategies; +import org.springframework.messaging.rsocket.annotation.support.RSocketFrameTypeMessageCondition; +import org.springframework.messaging.rsocket.annotation.support.RSocketPayloadReturnValueHandler; +import org.springframework.messaging.support.MessageBuilder; +import org.springframework.messaging.support.MessageHeaderAccessor; +import org.springframework.util.Assert; +import org.springframework.util.MimeType; +import org.springframework.util.RouteMatcher; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; +import reactor.core.publisher.MonoProcessor; + +public class MessagingRouter implements MutableRouter { + + private final MimeType dataMimeType; + + private final MimeType metadataMimeType; + + private final MetadataExtractor metadataExtractor; + + private final ReactiveMessageHandler messageHandler; + + private final RouteMatcher routeMatcher; + + private final RSocketStrategies strategies; + + public MessagingRouter( + MimeType dataMimeType, + MimeType metadataMimeType, + MetadataExtractor metadataExtractor, + ReactiveMessageHandler messageHandler, + RouteMatcher routeMatcher, + RSocketStrategies strategies) { + + Assert.notNull(dataMimeType, "'dataMimeType' is required"); + Assert.notNull(metadataMimeType, "'metadataMimeType' is required"); + Assert.notNull(metadataExtractor, "MetadataExtractor is required"); + Assert.notNull(messageHandler, "ReactiveMessageHandler is required"); + Assert.notNull(routeMatcher, "RouteMatcher is required"); + Assert.notNull(strategies, "RSocketStrategies is required"); + + this.dataMimeType = dataMimeType; + this.metadataMimeType = metadataMimeType; + this.metadataExtractor = metadataExtractor; + this.messageHandler = messageHandler; + this.routeMatcher = routeMatcher; + this.strategies = strategies; + } + + /** + * Wrap the {@link ConnectionSetupPayload} with a {@link Message} and delegate to {@link + * #handle(Payload, FrameType)} for handling. + * + * @param payload the connection payload + * @return completion handle for success or error + */ + public Mono handleConnectionSetupPayload(ConnectionSetupPayload payload) { + // frameDecoder does not apply to connectionSetupPayload + // so retain here since handle expects it.. + payload.retain(); + return handle(payload, FrameType.SETUP); + } + + @Override + public IPCFunction> routeFireAndForget(String route) { + return (payload, decoded) -> + decoded.isComposite() + ? this.handle(payload.retain(), FrameType.REQUEST_FNF) + : this.handle(payload.retain(), route, FrameType.REQUEST_FNF); + } + + @Override + public IPCFunction> routeRequestResponse(String route) { + return (payload, decoded) -> + decoded.isComposite() + ? handleAndReply(payload, FrameType.REQUEST_RESPONSE, Flux.just(payload.retain())) + .next() + : handleAndReply( + payload, route, FrameType.REQUEST_RESPONSE, Flux.just(payload.retain())) + .next(); + } + + @Override + public IPCFunction> routeRequestStream(String route) { + return (payload, decoded) -> + decoded.isComposite() + ? handleAndReply(payload, FrameType.REQUEST_STREAM, Flux.just(payload.retain())) + : handleAndReply(payload, route, FrameType.REQUEST_STREAM, Flux.just(payload.retain())); + } + + @Override + public IPCChannelFunction routeRequestChannel(String route) { + return (source, payload, decoded) -> + decoded.isComposite() + ? handleAndReply(payload, FrameType.REQUEST_CHANNEL, source) + : handleAndReply(payload, route, FrameType.REQUEST_CHANNEL, source); + } + + @Override + public MessagingRouter withFireAndForgetRoute(String route, IPCFunction> function) { + return null; + } + + @Override + public MessagingRouter withRequestResponseRoute( + String route, IPCFunction> function) { + return null; + } + + @Override + public MessagingRouter withRequestStreamRoute(String route, IPCFunction> function) { + return null; + } + + @Override + public MessagingRouter withRequestChannelRoute(String route, IPCChannelFunction function) { + return null; + } + + // @Override + // public Mono fireAndForget(Payload payload) { + // return handle(payload, FrameType.REQUEST_FNF); + // } + // + // @Override + // public Mono requestResponse(Payload payload) { + // return handleAndReply(payload, FrameType.REQUEST_RESPONSE, Flux.just(payload)).next(); + // } + // + // @Override + // public Flux requestStream(Payload payload) { + // return handleAndReply(payload, FrameType.REQUEST_STREAM, Flux.just(payload)); + // } + // + // @Override + // public Flux requestChannel(Publisher payloads) { + // return Flux.from(payloads) + // .switchOnFirst((signal, innerFlux) -> { + // Payload firstPayload = signal.get(); + // return firstPayload == null ? innerFlux : + // handleAndReply(firstPayload, FrameType.REQUEST_CHANNEL, innerFlux); + // }); + // } + // + // @Override + // public Mono metadataPush(Payload payload) { + // // Not very useful until createHeaders does more with metadata + // return handle(payload, FrameType.METADATA_PUSH); + // } + + private Mono handle(Payload payload, FrameType frameType) { + MessageHeaders headers = createHeaders(payload, frameType, null); + DataBuffer dataBuffer = retainDataAndReleasePayload(payload); + int refCount = refCount(dataBuffer); + Message message = MessageBuilder.createMessage(dataBuffer, headers); + return Mono.defer(() -> this.messageHandler.handleMessage(message)) + .doFinally( + s -> { + if (refCount(dataBuffer) == refCount) { + DataBufferUtils.release(dataBuffer); + } + }); + } + + private Mono handle(Payload payload, String route, FrameType frameType) { + MessageHeaders headers = createHeaders(route, frameType, null); + DataBuffer dataBuffer = retainDataAndReleasePayload(payload); + int refCount = refCount(dataBuffer); + Message message = MessageBuilder.createMessage(dataBuffer, headers); + return Mono.defer(() -> this.messageHandler.handleMessage(message)) + .doFinally( + s -> { + if (refCount(dataBuffer) == refCount) { + DataBufferUtils.release(dataBuffer); + } + }); + } + + private int refCount(DataBuffer dataBuffer) { + return dataBuffer instanceof NettyDataBuffer + ? ((NettyDataBuffer) dataBuffer).getNativeBuffer().refCnt() + : 1; + } + + private Flux handleAndReply( + Payload firstPayload, FrameType frameType, Flux payloads) { + MonoProcessor> replyMono = MonoProcessor.create(); + MessageHeaders headers = createHeaders(firstPayload, frameType, replyMono); + + AtomicBoolean read = new AtomicBoolean(); + Flux buffers = + payloads.map(this::retainDataAndReleasePayload).doOnSubscribe(s -> read.set(true)); + Message> message = MessageBuilder.createMessage(buffers, headers); + + return Mono.defer(() -> this.messageHandler.handleMessage(message)) + .doFinally( + s -> { + // Subscription should have happened by now due to ChannelSendOperator + if (!read.get()) { + buffers.subscribe(DataBufferUtils::release); + } + }) + .thenMany( + Flux.defer( + () -> + replyMono.isTerminated() + ? replyMono.flatMapMany(Function.identity()) + : Mono.error( + new IllegalStateException( + "Something went wrong: reply Mono not set")))); + } + + private Flux handleAndReply( + Payload firstPayload, String route, FrameType frameType, Flux payloads) { + MonoProcessor> replyMono = MonoProcessor.create(); + MessageHeaders headers = createHeaders(route, frameType, replyMono); + + AtomicBoolean read = new AtomicBoolean(); + Flux buffers = + payloads.map(this::retainDataAndReleasePayload).doOnSubscribe(s -> read.set(true)); + Message> message = MessageBuilder.createMessage(buffers, headers); + + return Mono.defer(() -> this.messageHandler.handleMessage(message)) + .doFinally( + s -> { + // Subscription should have happened by now due to ChannelSendOperator + if (!read.get()) { + buffers.subscribe(DataBufferUtils::release); + } + }) + .thenMany( + Flux.defer( + () -> + replyMono.isTerminated() + ? replyMono.flatMapMany(Function.identity()) + : Mono.error( + new IllegalStateException( + "Something went wrong: reply Mono not set")))); + } + + private DataBuffer retainDataAndReleasePayload(Payload payload) { + return PayloadUtils.retainDataAndReleasePayload(payload, this.strategies.dataBufferFactory()); + } + + private MessageHeaders createHeaders( + Payload payload, FrameType frameType, @Nullable MonoProcessor replyMono) { + + MessageHeaderAccessor headers = new MessageHeaderAccessor(); + headers.setLeaveMutable(true); + + Map metadataValues = + this.metadataExtractor.extract(payload, this.metadataMimeType); + + metadataValues.putIfAbsent(MetadataExtractor.ROUTE_KEY, ""); + for (Map.Entry entry : metadataValues.entrySet()) { + if (entry.getKey().equals(MetadataExtractor.ROUTE_KEY)) { + RouteMatcher.Route route = this.routeMatcher.parseRoute((String) entry.getValue()); + headers.setHeader(DestinationPatternsMessageCondition.LOOKUP_DESTINATION_HEADER, route); + } else { + headers.setHeader(entry.getKey(), entry.getValue()); + } + } + + headers.setContentType(this.dataMimeType); + headers.setHeader(RSocketFrameTypeMessageCondition.FRAME_TYPE_HEADER, frameType); + if (replyMono != null) { + headers.setHeader(RSocketPayloadReturnValueHandler.RESPONSE_HEADER, replyMono); + } + headers.setHeader( + HandlerMethodReturnValueHandler.DATA_BUFFER_FACTORY_HEADER, + this.strategies.dataBufferFactory()); + + return headers.getMessageHeaders(); + } + + private MessageHeaders createHeaders( + String route, FrameType frameType, @Nullable MonoProcessor replyMono) { + + MessageHeaderAccessor headers = new MessageHeaderAccessor(); + headers.setLeaveMutable(true); + + headers.setHeader( + DestinationPatternsMessageCondition.LOOKUP_DESTINATION_HEADER, + this.routeMatcher.parseRoute(route)); + + headers.setContentType(this.dataMimeType); + headers.setHeader(RSocketFrameTypeMessageCondition.FRAME_TYPE_HEADER, frameType); + if (replyMono != null) { + headers.setHeader(RSocketPayloadReturnValueHandler.RESPONSE_HEADER, replyMono); + } + headers.setHeader( + HandlerMethodReturnValueHandler.DATA_BUFFER_FACTORY_HEADER, + this.strategies.dataBufferFactory()); + + return headers.getMessageHeaders(); + } +} diff --git a/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/MetricsAwareRSocketRequester.java b/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/MetricsAwareRSocketRequester.java index ec0aabd4..2c2a204d 100644 --- a/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/MetricsAwareRSocketRequester.java +++ b/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/MetricsAwareRSocketRequester.java @@ -1,12 +1,29 @@ +/* + * Copyright 2019 The Netifi Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.netifi.spring.messaging; import io.micrometer.core.instrument.MeterRegistry; import io.opentracing.Tracer; import io.rsocket.RSocket; import io.rsocket.rpc.metrics.Metrics; -import org.reactivestreams.Publisher; +import java.util.function.Consumer; import org.springframework.core.ParameterizedTypeReference; import org.springframework.messaging.rsocket.RSocketRequester; +import org.springframework.messaging.rsocket.RSocketStrategies; +import org.springframework.util.MimeType; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -17,7 +34,10 @@ public class MetricsAwareRSocketRequester implements RSocketRequester { private final Tracer tracer; public MetricsAwareRSocketRequester( - RSocketRequester requester, MeterRegistry meterRegistry, Tracer tracer) { + RSocketRequester requester, + RSocketStrategies rSocketStrategies, + MeterRegistry meterRegistry, + Tracer tracer) { this.rSocketRequester = requester; this.registry = meterRegistry; this.tracer = tracer; @@ -29,8 +49,24 @@ public RSocket rsocket() { } @Override - public RequestSpec route(String route) { - return new MetricsAwareRequestSpec(rSocketRequester.route(route), route, registry, tracer); + public MimeType dataMimeType() { + return rSocketRequester.dataMimeType(); + } + + @Override + public MimeType metadataMimeType() { + return rSocketRequester.metadataMimeType(); + } + + @Override + public RequestSpec route(String route, Object... routeVars) { + return new MetricsAwareRequestSpec( + rSocketRequester.route(route, routeVars), route, registry, tracer); + } + + @Override + public RequestSpec metadata(Object metadata, MimeType mimeType) { + return null; } private static final class MetricsAwareRequestSpec implements RequestSpec { @@ -49,40 +85,36 @@ private MetricsAwareRequestSpec( } @Override - public ResponseSpec data(Object data) { - return requestSpec.data(data); + public RequestSpec metadata(Consumer> configurer) { + return null; } @Override - public > ResponseSpec data(P publisher, Class dataType) { - return requestSpec.data(publisher, dataType); + public RetrieveSpec data(Object data) { + requestSpec.data(data); + return this; } @Override - public > ResponseSpec data( - P publisher, ParameterizedTypeReference dataTypeRef) { - return requestSpec.data(publisher, dataTypeRef); + public RetrieveSpec data(Object producer, Class elementClass) { + requestSpec.data(producer, elementClass); + return this; } - } - private static final class MetricsAwareResponseSepc implements ResponseSpec { - - private final ResponseSpec responseSpec; - private final String route; - private final MeterRegistry registry; - private final Tracer tracer; + @Override + public RetrieveSpec data(Object producer, ParameterizedTypeReference elementTypeRef) { + requestSpec.data(producer, elementTypeRef); + return this; + } - private MetricsAwareResponseSepc( - ResponseSpec spec, String route, MeterRegistry registry, Tracer tracer) { - this.responseSpec = spec; - this.route = route; - this.registry = registry; - this.tracer = tracer; + @Override + public RequestSpec metadata(Object metadata, MimeType mimeType) { + return requestSpec; } @Override public Mono send() { - return responseSpec + return requestSpec .send() .transform( Metrics.timed( @@ -91,9 +123,9 @@ public Mono send() { @Override public Mono retrieveMono(Class dataType) { - return responseSpec + return requestSpec .retrieveMono(dataType) - .transform( + .transform( Metrics.timed( registry, "rsocket.spring.client", @@ -107,9 +139,9 @@ public Mono retrieveMono(Class dataType) { @Override public Mono retrieveMono(ParameterizedTypeReference dataTypeRef) { - return responseSpec + return requestSpec .retrieveMono(dataTypeRef) - .transform( + .transform( Metrics.timed( registry, "rsocket.spring.client", @@ -123,9 +155,9 @@ public Mono retrieveMono(ParameterizedTypeReference dataTypeRef) { @Override public Flux retrieveFlux(Class dataType) { - return responseSpec + return requestSpec .retrieveFlux(dataType) - .transform( + .transform( Metrics.timed( registry, "rsocket.spring.client", @@ -139,9 +171,9 @@ public Flux retrieveFlux(Class dataType) { @Override public Flux retrieveFlux(ParameterizedTypeReference dataTypeRef) { - return responseSpec + return requestSpec .retrieveFlux(dataTypeRef) - .transform( + .transform( Metrics.timed( registry, "rsocket.spring.client", diff --git a/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/RSocketRequesterStaticFactory.java b/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/RSocketRequesterStaticFactory.java index 84c37c97..0610dfc7 100644 --- a/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/RSocketRequesterStaticFactory.java +++ b/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/RSocketRequesterStaticFactory.java @@ -1,38 +1,69 @@ +/* + * Copyright 2019 The Netifi Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.netifi.spring.messaging; -import com.netifi.broker.BrokerClient; +import com.netifi.broker.BrokerService; import com.netifi.broker.rsocket.BrokerSocket; -import com.netifi.broker.rsocket.NamedRSocketClientWrapper; import com.netifi.common.tags.Tags; import com.netifi.spring.core.annotation.BrokerClientStaticFactory; import io.micrometer.core.instrument.MeterRegistry; import io.opentracing.Tracer; import org.springframework.messaging.rsocket.RSocketRequester; import org.springframework.messaging.rsocket.RSocketStrategies; +import org.springframework.util.MimeTypeUtils; class RSocketRequesterStaticFactory { static RSocketRequester createRSocketRequester( - String rSocketName, - BrokerClient brokerClient, + BrokerService brokerClient, com.netifi.spring.core.annotation.BrokerClient brokerClientAnnotation, Tags tags, - RSocketStrategies rSocketStrategies) { - return RSocketRequester.create( + RSocketStrategies rSocketStrategies, + MeterRegistry meterRegistry, + Tracer tracer) { + if (meterRegistry != null && tracer != null) { + return new MetricsAwareRSocketRequester( + RSocketRequester.wrap( + resolveBrokerClientRSocket( + brokerClient, + brokerClientAnnotation.type(), + brokerClientAnnotation.group(), + brokerClientAnnotation.destination(), + tags), + MimeTypeUtils.ALL, + MimeTypeUtils.ALL, + rSocketStrategies), + rSocketStrategies, + meterRegistry, + tracer); + } + return RSocketRequester.wrap( resolveBrokerClientRSocket( - rSocketName, brokerClient, brokerClientAnnotation.type(), brokerClientAnnotation.group(), brokerClientAnnotation.destination(), tags), - null, + MimeTypeUtils.ALL, + MimeTypeUtils.ALL, rSocketStrategies); } static RSocketRequester createRSocketRequester( - String rSocketName, - BrokerClient brokerClient, + BrokerService brokerClient, com.netifi.spring.core.annotation.BrokerClient.Type routingType, String group, String destination, @@ -41,26 +72,32 @@ static RSocketRequester createRSocketRequester( MeterRegistry meterRegistry, Tracer tracer) { - return new MetricsAwareRSocketRequester( - RSocketRequester.wrap( - resolveBrokerClientRSocket( - rSocketName, brokerClient, routingType, group, destination, tags), - null, - rSocketStrategies), - meterRegistry, - tracer); + if (meterRegistry != null && tracer != null) { + return new MetricsAwareRSocketRequester( + RSocketRequester.wrap( + resolveBrokerClientRSocket(brokerClient, routingType, group, destination, tags), + MimeTypeUtils.ALL, + MimeTypeUtils.ALL, + rSocketStrategies), + rSocketStrategies, + meterRegistry, + tracer); + } else { + return RSocketRequester.wrap( + resolveBrokerClientRSocket(brokerClient, routingType, group, destination, tags), + MimeTypeUtils.ALL, + MimeTypeUtils.ALL, + rSocketStrategies); + } } static BrokerSocket resolveBrokerClientRSocket( - String rSocketName, - BrokerClient brokerClient, + BrokerService brokerClient, com.netifi.spring.core.annotation.BrokerClient.Type routingType, String group, String destination, Tags tags) { - return NamedRSocketClientWrapper.wrap( - rSocketName, - BrokerClientStaticFactory.createBrokerRSocket( - brokerClient, routingType, group, destination, tags)); + return BrokerClientStaticFactory.createBrokerRSocket( + brokerClient, routingType, group, destination, tags); } } diff --git a/netifi-spring-messaging/src/test/java/com/netifi/spring/core/TestIdlServiceServer.java b/netifi-spring-messaging/src/test/java/com/netifi/spring/core/TestIdlServiceServer.java index 7f4945b7..69b5957b 100644 --- a/netifi-spring-messaging/src/test/java/com/netifi/spring/core/TestIdlServiceServer.java +++ b/netifi-spring-messaging/src/test/java/com/netifi/spring/core/TestIdlServiceServer.java @@ -15,6 +15,7 @@ */ package com.netifi.spring.core; +import io.rsocket.ipc.MutableRouter; import io.rsocket.rpc.AbstractRSocketService; @javax.annotation.Generated( @@ -30,4 +31,7 @@ public class TestIdlServiceServer extends AbstractRSocketService { public Class getServiceClass() { return TestIdl.class; } + + @Override + public void selfRegister(MutableRouter router) {} } diff --git a/netifi-tracing-idl/gradle/dependency-locks/compile.lockfile~merged b/netifi-tracing-idl/gradle/dependency-locks/compile.lockfile~merged deleted file mode 100644 index 656c5dbc..00000000 --- a/netifi-tracing-idl/gradle/dependency-locks/compile.lockfile~merged +++ /dev/null @@ -1,3 +0,0 @@ -# This is a Gradle generated file for dependency locking. -# Manual edits can break the build and are not advised. -# This file is expected to be part of source control. diff --git a/netifi-tracing-openzipkin/src/main/java/com/netifi/broker/tracing/BrokerTracerSupplier.java b/netifi-tracing-openzipkin/src/main/java/com/netifi/broker/tracing/BrokerTracerSupplier.java index 0ed7057e..7e815aba 100644 --- a/netifi-tracing-openzipkin/src/main/java/com/netifi/broker/tracing/BrokerTracerSupplier.java +++ b/netifi-tracing-openzipkin/src/main/java/com/netifi/broker/tracing/BrokerTracerSupplier.java @@ -17,7 +17,7 @@ import brave.Tracing; import brave.opentracing.BraveTracer; -import com.netifi.broker.BrokerClient; +import com.netifi.broker.BrokerService; import com.netifi.broker.rsocket.BrokerSocket; import io.opentracing.Tracer; import java.util.Optional; @@ -30,7 +30,7 @@ public class BrokerTracerSupplier implements Supplier { private final Tracer tracer; @Inject - public BrokerTracerSupplier(BrokerClient brokerClient, Optional tracingGroup) { + public BrokerTracerSupplier(BrokerService brokerClient, Optional tracingGroup) { BrokerSocket brokerSocket = brokerClient.group(tracingGroup.orElse("com.netifi.broker.tracing")); @@ -38,7 +38,7 @@ public BrokerTracerSupplier(BrokerClient brokerClient, Optional tracingG new BrokerTracingServiceClient(brokerSocket); BrokerReporter reporter = new BrokerReporter( - brokerTracingServiceClient, brokerClient.getGroupName(), brokerClient.getTags()); + brokerTracingServiceClient, brokerClient.groupName(), brokerClient.tags()); Tracing tracing = Tracing.newBuilder().spanReporter(reporter).build(); diff --git a/netifi-tracing-openzipkin/src/main/java/com/netifi/broker/tracing/BrokerZipkinHttpBridge.java b/netifi-tracing-openzipkin/src/main/java/com/netifi/broker/tracing/BrokerZipkinHttpBridge.java index afc38d8c..e746598f 100644 --- a/netifi-tracing-openzipkin/src/main/java/com/netifi/broker/tracing/BrokerZipkinHttpBridge.java +++ b/netifi-tracing-openzipkin/src/main/java/com/netifi/broker/tracing/BrokerZipkinHttpBridge.java @@ -16,7 +16,8 @@ package com.netifi.broker.tracing; import com.google.protobuf.InvalidProtocolBufferException; -import com.netifi.broker.BrokerClient; +import com.netifi.broker.BrokerFactory; +import com.netifi.broker.RoutingBrokerService; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelOption; import java.time.Duration; @@ -75,22 +76,20 @@ public static void main(String... args) { logger.info("zipkin spans url - {}", zipkinSpansUrl); logger.info("access key - {}", accessKey); - BrokerClient brokerClient = - BrokerClient.tcp() - .accessKey(accessKey) - .accessToken(accessToken) - .group(group) - .host(brokerHost) - .port(brokerPort) - .destination("standaloneZipkinBridge") - .build(); + RoutingBrokerService brokerClient = + BrokerFactory.connect() + .authentication(spec -> spec.simple().key(accessKey).token(accessToken)) + .connection(spec -> spec.tcp()) + .destinationInfo(spec -> spec.groupName(group).destinationTag("standaloneZipkinBridge")) + .discoveryStrategy(spec -> spec.simple(brokerPort, brokerHost)) + .toRoutingService(); - brokerClient.addService( - new BrokerTracingServiceServer( + new BrokerTracingServiceServer( new BrokerZipkinHttpBridge(zipkinHost, zipkinPort, zipkinSpansUrl), Optional.empty(), Optional.empty(), - Optional.empty())); + Optional.empty()) + .selfRegister(brokerClient.router()); brokerClient.onClose().block(); } diff --git a/settings.gradle b/settings.gradle index 648038f4..62e1b778 100644 --- a/settings.gradle +++ b/settings.gradle @@ -10,6 +10,10 @@ // } //} +plugins { + id 'com.gradle.enterprise' version '3.1' +} + rootProject.name = 'netifi-java' include 'netifi-bom' @@ -30,3 +34,10 @@ include 'netifi-spring-core' include 'netifi-spring-messaging' include 'netifi-spring-boot-starter' include 'netifi-spring-boot-autoconfigure' + +gradleEnterprise { + buildScan { + termsOfServiceUrl = 'https://gradle.com/terms-of-service' + termsOfServiceAgree = 'yes' + } +} From a5e761201b1a1013c0b09a1115b11dae7fc93920 Mon Sep 17 00:00:00 2001 From: Oleh Dokuka Date: Wed, 8 Jan 2020 17:58:51 +0200 Subject: [PATCH 9/9] provides tests fixes --- .../java/com/netifi/broker/BrokerFactory.java | 8 +-- .../netifi/broker/DefaultBuilderConfig.java | 3 +- .../boot/BrokerClientAutoConfiguration.java | 46 ++++++++--------- .../boot/DefaultRoutingAutoConfiguration.java | 34 +++++++++++++ .../BrokerClientMessagingProperties.java | 2 +- .../BrokerMessagingAutoConfiguration.java} | 40 +++------------ .../MessagingRoutingAutoConfiguration.java | 51 +++++++++++++++++++ .../boot/{ => messaging}/NetifiBootstrap.java | 2 +- .../main/resources/META-INF/spring.factories | 4 +- .../ClientConfigurationIntegrationTest.java | 31 ++++++++--- .../spring/boot/test/TestApplication.java | 26 ++++++++++ .../test/resources/META-INF/spring.factories | 4 +- .../core/BrokerClientFactorySupport.java | 15 ++++++ .../annotation/BaseBrokerClientFactory.java | 15 ++++++ .../spring/core/annotation/BrokerClient.java | 20 ++++---- ...ntBeanDefinitionRegistryPostProcessor.java | 12 ++--- .../annotation/BrokerClientStaticFactory.java | 20 ++++---- .../DefaultBroadcastAwareClientFactory.java | 15 ++++++ .../DefaultDestinationAwareClientFactory.java | 15 ++++++ .../DefaultGroupAwareClientFactory.java | 15 ++++++ .../RpcBrokerClientFactorySupport.java | 26 ++++++++-- .../config/BrokerClientConfiguration.java | 4 +- .../spring/core/TestableConfiguration.java | 1 - .../spring/core/TestableConfiguration.java | 6 +++ 24 files changed, 307 insertions(+), 108 deletions(-) create mode 100644 netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/DefaultRoutingAutoConfiguration.java rename netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/{ => messaging}/BrokerClientMessagingProperties.java (96%) rename netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/{BrokerClientMessagingAutoConfiguration.java => messaging/BrokerMessagingAutoConfiguration.java} (73%) create mode 100644 netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/messaging/MessagingRoutingAutoConfiguration.java rename netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/{ => messaging}/NetifiBootstrap.java (98%) create mode 100644 netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/TestApplication.java diff --git a/netifi-broker-client/src/main/java/com/netifi/broker/BrokerFactory.java b/netifi-broker-client/src/main/java/com/netifi/broker/BrokerFactory.java index a1f1429e..6e09aaae 100644 --- a/netifi-broker-client/src/main/java/com/netifi/broker/BrokerFactory.java +++ b/netifi-broker-client/src/main/java/com/netifi/broker/BrokerFactory.java @@ -571,12 +571,12 @@ public Builder tags(Iterable tags) { DestinationInfoConfig build() { Tags tags; - if (destination != null && !destination.isEmpty()) { - tags = this.tags.and("com.netifi.destination", destination); - } else { - tags = this.tags; + if (destination == null || destination.isEmpty()) { + destination = defaultDestination(); } + tags = this.tags.and("com.netifi.destination", destination); + return new DestinationInfoConfig() { @Override public String group() { diff --git a/netifi-broker-client/src/main/java/com/netifi/broker/DefaultBuilderConfig.java b/netifi-broker-client/src/main/java/com/netifi/broker/DefaultBuilderConfig.java index 5c3869b5..a6b2ec01 100644 --- a/netifi-broker-client/src/main/java/com/netifi/broker/DefaultBuilderConfig.java +++ b/netifi-broker-client/src/main/java/com/netifi/broker/DefaultBuilderConfig.java @@ -28,8 +28,7 @@ import java.util.stream.Stream; /** - * Gets current default configuration for {@link BrokerFactory}. Can be overridden with - * System + * Gets current default configuration for {@link BrokerFactory}. Can be overridden with System * properties, or if the application provides a config file. The builder will over-ride these values * if they are based directly in to the builder. Otherwise it will these values a default. */ diff --git a/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientAutoConfiguration.java b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientAutoConfiguration.java index 5626de9c..1f283553 100644 --- a/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientAutoConfiguration.java +++ b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientAutoConfiguration.java @@ -19,7 +19,12 @@ import com.netifi.broker.BrokerFactory; import com.netifi.broker.BrokerService; import com.netifi.broker.RoutingBrokerService; -import com.netifi.broker.discovery.*; +import com.netifi.broker.discovery.ConsulDiscoveryConfig; +import com.netifi.broker.discovery.DiscoveryStrategy; +import com.netifi.broker.discovery.EC2TagsDiscoveryConfig; +import com.netifi.broker.discovery.KubernetesDiscoveryConfig; +import com.netifi.broker.discovery.StaticListDiscoveryConfig; +import com.netifi.broker.discovery.StaticListDiscoveryStrategy; import com.netifi.broker.micrometer.BrokerMeterRegistrySupplier; import com.netifi.broker.tracing.BrokerTracerSupplier; import com.netifi.common.tags.Tag; @@ -30,12 +35,9 @@ import io.micrometer.core.instrument.MeterRegistry; import io.opentracing.Tracer; import io.rsocket.ipc.MutableRouter; -import io.rsocket.ipc.Router; -import io.rsocket.ipc.routing.SimpleRouter; import java.time.Duration; import java.util.List; import java.util.Optional; -import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor; import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; @@ -58,8 +60,8 @@ @AutoConfigureBefore(BrokerClientConfiguration.class) public class BrokerClientAutoConfiguration { - static RoutingBrokerService configureBrokerClient( - MutableRouter router, List configurers) { + static RoutingBrokerService configureBrokerClient( + MutableRouter router, List configurers) { BrokerFactory.ClientBuilder clientBuilder = BrokerFactory.connect(); AnnotationAwareOrderComparator.sort(configurers); @@ -72,13 +74,14 @@ static RoutingBrokerService configureBrokerClient( } @Bean(name = "internalScanClassPathBeanDefinitionRegistryPostProcessor") - public BeanDefinitionRegistryPostProcessor scanClassPathBeanDefinitionRegistryPostProcessor() { + public ScanClassPathBeanDefinitionRegistryPostProcessor + scanClassPathBeanDefinitionRegistryPostProcessor() { return new ScanClassPathBeanDefinitionRegistryPostProcessor(); } @Bean @Order(Ordered.HIGHEST_PRECEDENCE) - public BrokerServiceConfigurer propertiesBasedBrokerClientConfigurer( + public BrokerServiceConfigurer propertiesBasedBrokerServiceConfigurer( BrokerClientTagSupplier brokerClientTagSupplier, BrokerClientProperties brokerClientProperties) { return builder -> { @@ -227,15 +230,6 @@ public BrokerClientTagSupplier brokerClientTagSupplier() { } } - @Configuration - @ConditionalOnMissingBean(Router.class) - public static class RouterConfiguration { - @Bean - public MutableRouter mutableRouter() { - return new SimpleRouter(); - } - } - @Configuration @ConditionalOnMissingBean(MeterRegistry.class) @ConditionalOnClass(BrokerMeterRegistrySupplier.class) @@ -267,15 +261,15 @@ public Tracer tracer(BrokerService brokerClient, BrokerClientProperties properti @Configuration @ConditionalOnNotWebApplication - @ConditionalOnMissingBean({BrokerService.class}) + @ConditionalOnMissingBean(BrokerService.class) public static class NonWebBrokerClientConfiguration { @Bean - public RoutingBrokerService routingBrokerService( - MutableRouter router, + public RoutingBrokerService routingBrokerService( + MutableRouter mutableRouter, List configurers, ConfigurableApplicationContext context) { - RoutingBrokerService brokerClient = configureBrokerClient(router, configurers); + RoutingBrokerService brokerClient = configureBrokerClient(mutableRouter, configurers); startDaemonAwaitThread(brokerClient); @@ -306,24 +300,24 @@ public void run() { } @Bean - public BrokerClient routingBrokerService(RoutingBrokerService routingBrokerService) { + public BrokerClient brokerClient(RoutingBrokerService routingBrokerService) { return BrokerClient.from(routingBrokerService); } } @Configuration @ConditionalOnWebApplication - @ConditionalOnMissingBean({BrokerService.class}) + @ConditionalOnMissingBean(BrokerService.class) public static class WebBrokerClientConfiguration { @Bean - public RoutingBrokerService routingBrokerService( - MutableRouter router, List configurers) { + public RoutingBrokerService routingBrokerService( + MutableRouter router, List configurers) { return configureBrokerClient(router, configurers); } @Bean - public BrokerClient routingBrokerService(RoutingBrokerService routingBrokerService) { + public BrokerClient brokerClient(RoutingBrokerService routingBrokerService) { return BrokerClient.from(routingBrokerService); } } diff --git a/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/DefaultRoutingAutoConfiguration.java b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/DefaultRoutingAutoConfiguration.java new file mode 100644 index 00000000..d20db9c0 --- /dev/null +++ b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/DefaultRoutingAutoConfiguration.java @@ -0,0 +1,34 @@ +/* + * Copyright 2019 The Netifi Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.netifi.spring.boot; + +import io.rsocket.ipc.Router; +import io.rsocket.ipc.routing.SimpleRouter; +import org.springframework.boot.autoconfigure.AutoConfigureBefore; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +@AutoConfigureBefore(BrokerClientAutoConfiguration.class) +public class DefaultRoutingAutoConfiguration { + + @Bean + @ConditionalOnMissingBean(Router.class) + public SimpleRouter mutableRouter() { + return new SimpleRouter(); + } +} diff --git a/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientMessagingProperties.java b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/messaging/BrokerClientMessagingProperties.java similarity index 96% rename from netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientMessagingProperties.java rename to netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/messaging/BrokerClientMessagingProperties.java index 97df5b74..54ab964c 100644 --- a/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientMessagingProperties.java +++ b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/messaging/BrokerClientMessagingProperties.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.netifi.spring.boot; +package com.netifi.spring.boot.messaging; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.validation.annotation.Validated; diff --git a/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientMessagingAutoConfiguration.java b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/messaging/BrokerMessagingAutoConfiguration.java similarity index 73% rename from netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientMessagingAutoConfiguration.java rename to netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/messaging/BrokerMessagingAutoConfiguration.java index c7c0988e..3bbea5a3 100644 --- a/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/BrokerClientMessagingAutoConfiguration.java +++ b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/messaging/BrokerMessagingAutoConfiguration.java @@ -14,36 +14,31 @@ * limitations under the License. */ -package com.netifi.spring.boot; +package com.netifi.spring.boot.messaging; import com.netifi.broker.BrokerService; +import com.netifi.spring.boot.BrokerClientAutoConfiguration; import com.netifi.spring.messaging.BrokerClientRequesterMethodArgumentResolver; import com.netifi.spring.messaging.MessagingRSocketRequesterClientFactory; -import com.netifi.spring.messaging.MessagingRouter; import io.micrometer.core.instrument.MeterRegistry; import io.opentracing.Tracer; import io.rsocket.AbstractRSocket; import io.rsocket.RSocket; import io.rsocket.RSocketFactory; -import io.rsocket.ipc.MutableRouter; import io.rsocket.transport.netty.server.TcpServerTransport; import java.util.Optional; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.rsocket.RSocketProperties; import org.springframework.boot.autoconfigure.rsocket.RSocketStrategiesAutoConfiguration; import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.boot.rsocket.context.RSocketServerBootstrap; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.messaging.rsocket.RSocketRequester; import org.springframework.messaging.rsocket.RSocketStrategies; import org.springframework.messaging.rsocket.annotation.support.RSocketMessageHandler; import org.springframework.messaging.rsocket.annotation.support.RSocketRequesterMethodArgumentResolver; -import org.springframework.util.MimeTypeUtils; /** * {@link EnableAutoConfiguration Auto-configuration} for Spring RSocket support in Spring @@ -52,42 +47,23 @@ * @author Oleh Dokuka * @since 1.7.0 */ -@Configuration(proxyBeanMethods = false) +@Configuration @ConditionalOnClass({RSocketRequester.class, RSocketFactory.class, TcpServerTransport.class}) @AutoConfigureAfter({RSocketStrategiesAutoConfiguration.class, BrokerClientAutoConfiguration.class}) @EnableConfigurationProperties(BrokerClientMessagingProperties.class) -public class BrokerClientMessagingAutoConfiguration { +public class BrokerMessagingAutoConfiguration { private static final RSocket STUB_RSOCKET = new AbstractRSocket() {}; @Bean - public MutableRouter messagingCustomizer( - RSocketProperties rSocketProperties, - BrokerClientProperties brokerClientProperties, - BrokerClientMessagingProperties properties, - DefaultListableBeanFactory factory, - RSocketStrategies rSocketStrategies, - RSocketMessageHandler handler) { - return new MessagingRouter( - MimeTypeUtils.ALL, - MimeTypeUtils.ALL, - rSocketStrategies.metadataExtractor(), - handler, - rSocketStrategies.routeMatcher(), - rSocketStrategies); - } - - @Bean - @ConditionalOnMissingBean - public RSocketServerBootstrap messageHandlerAcceptor( - BrokerClientMessagingProperties properties, + public NetifiBootstrap netifiBootstrap( DefaultListableBeanFactory factory, RSocketStrategies rSocketStrategies, RSocketMessageHandler handler, - BrokerService brokerClient, + BrokerService brokerService, Optional registry, Optional tracer) { - RSocketServerBootstrap bootstrap = new NetifiBootstrap(brokerClient); + NetifiBootstrap bootstrap = new NetifiBootstrap(brokerService); handler .getArgumentResolverConfigurer() @@ -98,7 +74,7 @@ public RSocketServerBootstrap messageHandlerAcceptor( .getArgumentResolverConfigurer() .addCustomResolver( new BrokerClientRequesterMethodArgumentResolver( - brokerClient, + brokerService, factory, rSocketStrategies, registry.orElse(null), diff --git a/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/messaging/MessagingRoutingAutoConfiguration.java b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/messaging/MessagingRoutingAutoConfiguration.java new file mode 100644 index 00000000..084280c8 --- /dev/null +++ b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/messaging/MessagingRoutingAutoConfiguration.java @@ -0,0 +1,51 @@ +/* + * Copyright 2019 The Netifi Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.netifi.spring.boot.messaging; + +import com.netifi.spring.boot.BrokerClientAutoConfiguration; +import com.netifi.spring.boot.DefaultRoutingAutoConfiguration; +import com.netifi.spring.messaging.MessagingRouter; +import io.rsocket.RSocketFactory; +import io.rsocket.transport.netty.server.TcpServerTransport; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.AutoConfigureBefore; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.rsocket.RSocketStrategiesAutoConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.messaging.rsocket.RSocketRequester; +import org.springframework.messaging.rsocket.RSocketStrategies; +import org.springframework.messaging.rsocket.annotation.support.RSocketMessageHandler; +import org.springframework.util.MimeTypeUtils; + +@Configuration(proxyBeanMethods = false) +@ConditionalOnClass({RSocketRequester.class, RSocketFactory.class, TcpServerTransport.class}) +@AutoConfigureBefore({BrokerClientAutoConfiguration.class, DefaultRoutingAutoConfiguration.class}) +@AutoConfigureAfter(RSocketStrategiesAutoConfiguration.class) +public class MessagingRoutingAutoConfiguration { + + @Bean + public MessagingRouter messagingRouter( + RSocketStrategies rSocketStrategies, RSocketMessageHandler handler) { + return new MessagingRouter( + MimeTypeUtils.ALL, + MimeTypeUtils.ALL, + rSocketStrategies.metadataExtractor(), + handler, + rSocketStrategies.routeMatcher(), + rSocketStrategies); + } +} diff --git a/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/NetifiBootstrap.java b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/messaging/NetifiBootstrap.java similarity index 98% rename from netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/NetifiBootstrap.java rename to netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/messaging/NetifiBootstrap.java index 68529430..87d6f348 100644 --- a/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/NetifiBootstrap.java +++ b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/messaging/NetifiBootstrap.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.netifi.spring.boot; +package com.netifi.spring.boot.messaging; import com.netifi.broker.BrokerService; import java.net.InetSocketAddress; diff --git a/netifi-spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories b/netifi-spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories index 181bad26..bad5b48c 100644 --- a/netifi-spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories +++ b/netifi-spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories @@ -1,5 +1,7 @@ # Auto Configure org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ + com.netifi.spring.boot.DefaultRoutingAutoConfiguration,\ com.netifi.spring.boot.BrokerClientAutoConfiguration,\ - com.netifi.spring.boot.BrokerClientMessagingAutoConfiguration,\ + com.netifi.spring.boot.messaging.MessagingRoutingAutoConfiguration,\ + com.netifi.spring.boot.messaging.BrokerMessagingAutoConfiguration,\ com.netifi.spring.core.config.BrokerClientConfiguration \ No newline at end of file diff --git a/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/ClientConfigurationIntegrationTest.java b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/ClientConfigurationIntegrationTest.java index a140bc4e..23f0950c 100644 --- a/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/ClientConfigurationIntegrationTest.java +++ b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/ClientConfigurationIntegrationTest.java @@ -18,7 +18,10 @@ import static org.mockito.ArgumentMatchers.any; import com.netifi.broker.BrokerClient; +import com.netifi.broker.BrokerFactory; +import com.netifi.broker.BrokerService; import com.netifi.spring.boot.support.BrokerClientConfigurer; +import com.netifi.spring.boot.support.BrokerServiceConfigurer; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -31,26 +34,31 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; @ExtendWith(SpringExtension.class) -@SpringBootTest(classes = { - com.netifi.spring.boot.BrokerClientAutoConfiguration.class, - com.netifi.spring.boot.BrokerClientMessagingAutoConfiguration.class, - com.netifi.spring.core.config.BrokerClientConfiguration.class -}) +@SpringBootTest public class ClientConfigurationIntegrationTest { @Autowired @Qualifier("mock2") BrokerClientConfigurer configurer; + @Autowired + @Qualifier("mock3") + BrokerServiceConfigurer brokerServiceConfigurer; + @Autowired BrokerClient brokerClient; + @Autowired BrokerService brokerService; @Test public void testThatConfigurerWorks() { Assertions.assertNotNull(brokerClient); - ArgumentCaptor captor = - ArgumentCaptor.forClass(BrokerClient.CustomizableBuilder.class); + // ArgumentCaptor captor = + // ArgumentCaptor.forClass(BrokerClient.CustomizableBuilder.class); + ArgumentCaptor captor = ArgumentCaptor.forClass(Object.class); - Mockito.verify(configurer).configure(captor.capture()); + // fixme + // Mockito.verify(configurer).configure(captor.capture()); + Mockito.verify(brokerServiceConfigurer) + .configure((BrokerFactory.ClientBuilder) captor.capture()); Assertions.assertNotNull(captor.getValue()); } @@ -69,5 +77,12 @@ public BrokerClientConfigurer testBrokerClientConfigurer() { return configurer; } + + @Bean + @Qualifier("mock3") + public BrokerServiceConfigurer testBrokerServiceConfigurer() { + + return Mockito.mock(BrokerServiceConfigurer.class); + } } } diff --git a/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/TestApplication.java b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/TestApplication.java new file mode 100644 index 00000000..7efd8cfd --- /dev/null +++ b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/TestApplication.java @@ -0,0 +1,26 @@ +/* + * Copyright 2019 The Netifi Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.netifi.spring.boot.test; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class TestApplication { + public static void main(String[] args) { + SpringApplication.run(TestApplication.class, args); + } +} diff --git a/netifi-spring-boot-autoconfigure/src/test/resources/META-INF/spring.factories b/netifi-spring-boot-autoconfigure/src/test/resources/META-INF/spring.factories index 181bad26..bad5b48c 100644 --- a/netifi-spring-boot-autoconfigure/src/test/resources/META-INF/spring.factories +++ b/netifi-spring-boot-autoconfigure/src/test/resources/META-INF/spring.factories @@ -1,5 +1,7 @@ # Auto Configure org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ + com.netifi.spring.boot.DefaultRoutingAutoConfiguration,\ com.netifi.spring.boot.BrokerClientAutoConfiguration,\ - com.netifi.spring.boot.BrokerClientMessagingAutoConfiguration,\ + com.netifi.spring.boot.messaging.MessagingRoutingAutoConfiguration,\ + com.netifi.spring.boot.messaging.BrokerMessagingAutoConfiguration,\ com.netifi.spring.core.config.BrokerClientConfiguration \ No newline at end of file diff --git a/netifi-spring-core/src/main/java/com/netifi/spring/core/BrokerClientFactorySupport.java b/netifi-spring-core/src/main/java/com/netifi/spring/core/BrokerClientFactorySupport.java index 673a2486..8f47177e 100644 --- a/netifi-spring-core/src/main/java/com/netifi/spring/core/BrokerClientFactorySupport.java +++ b/netifi-spring-core/src/main/java/com/netifi/spring/core/BrokerClientFactorySupport.java @@ -1,3 +1,18 @@ +/* + * Copyright 2019 The Netifi Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.netifi.spring.core; import com.netifi.common.tags.Tags; diff --git a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BaseBrokerClientFactory.java b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BaseBrokerClientFactory.java index 4e19cb76..732b8538 100644 --- a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BaseBrokerClientFactory.java +++ b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BaseBrokerClientFactory.java @@ -1,3 +1,18 @@ +/* + * Copyright 2019 The Netifi Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.netifi.spring.core.annotation; import com.netifi.common.tags.Tags; diff --git a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClient.java b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClient.java index 9e68a797..1160c338 100644 --- a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClient.java +++ b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClient.java @@ -1,15 +1,17 @@ -/** - * Copyright 2019 Netifi Inc. +/* + * Copyright 2019 The Netifi Authors * - *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - *

http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - *

Unless required by applicable law or agreed to in writing, software distributed under the - * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.netifi.spring.core.annotation; diff --git a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClientBeanDefinitionRegistryPostProcessor.java b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClientBeanDefinitionRegistryPostProcessor.java index 04d93bb7..4810d18a 100644 --- a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClientBeanDefinitionRegistryPostProcessor.java +++ b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClientBeanDefinitionRegistryPostProcessor.java @@ -66,12 +66,6 @@ public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) @Override public Object getSuggestedValue(DependencyDescriptor descriptor) { - List brokerClientFactories = - new ArrayList<>( - beanFactory.getBeansOfType(BrokerClientFactorySupport.class).values()); - - AnnotationAwareOrderComparator.sort(brokerClientFactories); - BrokerClient annotation = descriptor.getField() == null ? AnnotatedElementUtils.getMergedAnnotation( @@ -80,6 +74,12 @@ public Object getSuggestedValue(DependencyDescriptor descriptor) { descriptor.getAnnotatedElement(), BrokerClient.class); if (annotation != null) { + List brokerClientFactories = + new ArrayList<>( + beanFactory.getBeansOfType(BrokerClientFactorySupport.class).values()); + + AnnotationAwareOrderComparator.sort(brokerClientFactories); + Class descriptorDeclaredType = descriptor.getDeclaredType(); String[] beanNamesForType = beanFactory.getBeanNamesForType(descriptorDeclaredType); diff --git a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClientStaticFactory.java b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClientStaticFactory.java index 636a683f..240c2a03 100644 --- a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClientStaticFactory.java +++ b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BrokerClientStaticFactory.java @@ -1,15 +1,17 @@ -/** - * Copyright 2019 Netifi Inc. +/* + * Copyright 2019 The Netifi Authors * - *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - *

http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - *

Unless required by applicable law or agreed to in writing, software distributed under the - * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.netifi.spring.core.annotation; diff --git a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/DefaultBroadcastAwareClientFactory.java b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/DefaultBroadcastAwareClientFactory.java index 9d4e7c9d..844c21cd 100644 --- a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/DefaultBroadcastAwareClientFactory.java +++ b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/DefaultBroadcastAwareClientFactory.java @@ -1,3 +1,18 @@ +/* + * Copyright 2019 The Netifi Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.netifi.spring.core.annotation; import com.netifi.common.tags.Tags; diff --git a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/DefaultDestinationAwareClientFactory.java b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/DefaultDestinationAwareClientFactory.java index 0b5d1dda..64860b3e 100644 --- a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/DefaultDestinationAwareClientFactory.java +++ b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/DefaultDestinationAwareClientFactory.java @@ -1,3 +1,18 @@ +/* + * Copyright 2019 The Netifi Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.netifi.spring.core.annotation; import com.netifi.common.tags.Tags; diff --git a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/DefaultGroupAwareClientFactory.java b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/DefaultGroupAwareClientFactory.java index e4b9c752..ea6864be 100644 --- a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/DefaultGroupAwareClientFactory.java +++ b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/DefaultGroupAwareClientFactory.java @@ -1,3 +1,18 @@ +/* + * Copyright 2019 The Netifi Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.netifi.spring.core.annotation; import com.netifi.common.tags.Tags; diff --git a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/RpcBrokerClientFactorySupport.java b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/RpcBrokerClientFactorySupport.java index 8dee60cd..78d843fe 100644 --- a/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/RpcBrokerClientFactorySupport.java +++ b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/RpcBrokerClientFactorySupport.java @@ -1,5 +1,21 @@ +/* + * Copyright 2019 The Netifi Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.netifi.spring.core.annotation; +import com.netifi.broker.BrokerService; import com.netifi.common.tags.Tags; import com.netifi.spring.core.BrokerClientFactorySupport; import io.micrometer.core.instrument.MeterRegistry; @@ -8,15 +24,15 @@ public class RpcBrokerClientFactorySupport implements BrokerClientFactorySupport { - private final com.netifi.broker.BrokerService brokerClient; + private final com.netifi.broker.BrokerService brokerService; private final Tracer tracer; private final MeterRegistry meterRegistry; public RpcBrokerClientFactorySupport( - com.netifi.broker.BrokerService client, MeterRegistry registry, Tracer tracer) { - brokerClient = client; + BrokerService brokerService, MeterRegistry registry, Tracer tracer) { + this.brokerService = brokerService; this.tracer = tracer; - meterRegistry = registry; + this.meterRegistry = registry; } @Override @@ -35,7 +51,7 @@ public boolean support(Class clazz) { public T lookup(Class clientClass, BrokerClient.Type type, String group, Tags tag) { try { return BrokerClientStaticFactory.createBrokerClient( - brokerClient, type, group, null, tag, tracer, meterRegistry, clientClass); + brokerService, type, group, null, tag, tracer, meterRegistry, clientClass); } catch (Exception e) { throw new RuntimeException( String.format( diff --git a/netifi-spring-core/src/main/java/com/netifi/spring/core/config/BrokerClientConfiguration.java b/netifi-spring-core/src/main/java/com/netifi/spring/core/config/BrokerClientConfiguration.java index 58f74ce9..55f9800f 100644 --- a/netifi-spring-core/src/main/java/com/netifi/spring/core/config/BrokerClientConfiguration.java +++ b/netifi-spring-core/src/main/java/com/netifi/spring/core/config/BrokerClientConfiguration.java @@ -56,8 +56,8 @@ public RpcBrokerClientFactorySupport rpcBrokerClientFactorySupport( @Bean public BrokerClientApplicationEventListener brokerClientApplicationEventListener( - RoutingBrokerService brokerClient) { - return new BrokerClientApplicationEventListener(brokerClient); + RoutingBrokerService routingBrokerService) { + return new BrokerClientApplicationEventListener(routingBrokerService); } @Bean diff --git a/netifi-spring-core/src/test/java/com/netifi/spring/core/TestableConfiguration.java b/netifi-spring-core/src/test/java/com/netifi/spring/core/TestableConfiguration.java index 9b9ffe2d..95c84e6c 100644 --- a/netifi-spring-core/src/test/java/com/netifi/spring/core/TestableConfiguration.java +++ b/netifi-spring-core/src/test/java/com/netifi/spring/core/TestableConfiguration.java @@ -36,7 +36,6 @@ public RoutingBrokerService routingBrokerService() { return Mockito.mock(RoutingBrokerService.class); } - @Bean public TestIdlImpl testIdlImpl() { return new TestIdlImpl(); diff --git a/netifi-spring-messaging/src/test/java/com/netifi/spring/core/TestableConfiguration.java b/netifi-spring-messaging/src/test/java/com/netifi/spring/core/TestableConfiguration.java index 385f0378..95c84e6c 100644 --- a/netifi-spring-messaging/src/test/java/com/netifi/spring/core/TestableConfiguration.java +++ b/netifi-spring-messaging/src/test/java/com/netifi/spring/core/TestableConfiguration.java @@ -16,6 +16,7 @@ package com.netifi.spring.core; import com.netifi.broker.BrokerClient; +import com.netifi.broker.RoutingBrokerService; import com.netifi.spring.core.config.EnableBrokerClient; import org.mockito.Mockito; import org.springframework.context.annotation.Bean; @@ -30,6 +31,11 @@ public BrokerClient brokerClient() { return Mockito.mock(BrokerClient.class); } + @Bean + public RoutingBrokerService routingBrokerService() { + return Mockito.mock(RoutingBrokerService.class); + } + @Bean public TestIdlImpl testIdlImpl() { return new TestIdlImpl();