diff --git a/build.gradle b/build.gradle index bb414fb2..af798628 100644 --- a/build.gradle +++ b/build.gradle @@ -1,27 +1,20 @@ buildscript { - configurations.classpath { - resolutionStrategy.activateDependencyLocking() - } +// configurations.classpath { +// resolutionStrategy.activateDependencyLocking() +// } } 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.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' } -//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 = "" @@ -44,9 +37,9 @@ if (details.branchName != null) { } allprojects { - dependencyLocking { - lockAllConfigurations() - } +// dependencyLocking { +// lockAllConfigurations() +// } project.version += versionSuffix ext { uniqueVersion = "${tmpUniqueVersion}" @@ -65,6 +58,9 @@ subprojects { targetCompatibility = 1.8 repositories { + 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 0229ab87..49c545b8 100644 --- a/dependency-management.gradle +++ b/dependency-management.gradle @@ -1,23 +1,29 @@ apply plugin: 'io.spring.dependency-management' +ext["rsocket.version"] = rsocketVersion + 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}" 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}" + mavenBom "org.springframework.boot:spring-boot-dependencies:${springBootDependenciesVersion}" } 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: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 +65,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}" @@ -81,5 +81,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.properties b/gradle.properties index 6f377eab..aa866a3a 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 @@ -25,14 +25,15 @@ nettyTcnativeVersion=2.0.25.Final nettyVersion=4.1.36.Final opentracingVersion=0.31.0 postgresqlVersion=42.2.5 -protobufVersion=3.6.1 -reactorBomVersion=Californium-SR8 +protobufVersion=3.7.1 +reactorBomVersion=Dysprosium-RELEASE roaringbitmapVersion=0.7.42 -rsocketRpcVersion=0.2.18 -rsocketVersion=0.12.2-RC4 +rsocketRpcVersion=0.3.0-feature-routing-SNAPSHOT +rsocketVersion=1.0.0-RC6-bugfix-prioritization-SNAPSHOT rxjava2JdbcVersion=0.2.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 +testcontainersVersion=1.11.3 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/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 87b738cb..5c2d1cf0 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index f4d7b2bf..94920145 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-6.0.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index af6708ff..83f2acfd 100755 --- a/gradlew +++ b/gradlew @@ -1,5 +1,21 @@ #!/usr/bin/env sh +# +# Copyright 2015 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. +# + ############################################################################## ## ## Gradle start up script for UN*X @@ -28,7 +44,7 @@ APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m"' +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" @@ -109,8 +125,8 @@ if $darwin; then GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` JAVACMD=`cygpath --unix "$JAVACMD"` diff --git a/gradlew.bat b/gradlew.bat index 0f8d5937..24467a14 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,3 +1,19 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + @if "%DEBUG%" == "" @echo off @rem ########################################################################## @rem @@ -14,7 +30,7 @@ set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome 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-client/src/main/java/com/netifi/broker/BrokerClient.java b/netifi-broker-client/src/main/java/com/netifi/broker/BrokerClient.java index 882b8b7c..f649ec2b 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,8 +20,8 @@ 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.net.HostAndPort; import com.netifi.common.tags.Tag; import com.netifi.common.tags.Tags; import io.netty.buffer.ByteBuf; @@ -34,8 +34,10 @@ import io.opentracing.Tracer; import io.rsocket.Closeable; import io.rsocket.RSocket; -import io.rsocket.rpc.RSocketRpcService; -import io.rsocket.rpc.rsocket.RequestHandlingRSocket; +import io.rsocket.ipc.MutableRouter; +import io.rsocket.ipc.RoutingServerRSocket; +import io.rsocket.ipc.SelfRegistrable; +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; @@ -44,11 +46,13 @@ import java.net.SocketAddress; import java.net.UnknownHostException; import java.nio.charset.StandardCharsets; +import java.time.Duration; import java.util.*; import java.util.concurrent.Callable; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Function; import java.util.function.Supplier; +import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import reactor.core.Exceptions; @@ -57,6 +61,7 @@ import reactor.netty.tcp.TcpClient; /** This is where the magic happens */ +@Deprecated public class BrokerClient implements Closeable { private static final Logger logger = LoggerFactory.getLogger(BrokerClient.class); private static final ConcurrentHashMap BROKERCLIENT = @@ -72,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, @@ -89,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, @@ -102,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() { @@ -151,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 @@ -177,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; } @@ -195,7 +236,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 @@ -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; } @@ -605,7 +651,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) { @@ -633,7 +681,8 @@ public BrokerClient build() { socketAddresses, BrokerAddressSelectors.WEBSOCKET_ADDRESS, clientTransportFactory, - responder, + router, + responderBuilder.apply(router), responderRequiresUnwrapping, poolSize, tracerSupplier, @@ -696,7 +745,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) { @@ -724,7 +775,8 @@ public BrokerClient build() { socketAddresses, BrokerAddressSelectors.TCP_ADDRESS, clientTransportFactory, - responder, + router, + responderBuilder.apply(router), responderRequiresUnwrapping, poolSize, tracerSupplier, @@ -775,7 +827,8 @@ public BrokerClient build() { socketAddresses, addressSelector, clientTransportFactory, - responder, + router, + responderBuilder.apply(router), responderRequiresUnwrapping, poolSize, tracerSupplier, @@ -792,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(); @@ -900,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; } @@ -1065,7 +1115,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) { @@ -1084,7 +1136,7 @@ public BrokerClient build() { } } - List socketAddresses = null; + List socketAddresses = null; if (discoveryStrategy == null) { if (seedAddresses == null) { Objects.requireNonNull(host, "host is required"); @@ -1100,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, @@ -1121,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..6e09aaae --- /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()) { + destination = defaultDestination(); + } + + tags = this.tags.and("com.netifi.destination", destination); + + 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 5e78456a..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 @@ -20,14 +20,15 @@ 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.Arrays; import java.util.List; +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 + * 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. */ @@ -148,13 +149,38 @@ 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()); @@ -266,8 +292,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/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/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 dcc639f8..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 @@ -15,9 +15,11 @@ */ 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 org.junit.Assert; import org.junit.Ignore; import org.junit.Test; @@ -28,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()); @@ -40,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()); @@ -51,18 +53,28 @@ 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 + 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(); + 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 6bd52236..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,38 +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())); - - 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-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/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-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 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/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 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-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/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/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-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/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/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/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-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-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/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/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 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/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 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-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-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-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..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( @@ -130,7 +139,9 @@ public String retentionDuration() { return t; })), Optional.empty(), - Optional.empty())); + Optional.empty(), + Optional.empty()) + .selfRegister(brokerClient.router()); brokerClient.onClose().block(); } 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-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/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-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..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), @@ -105,7 +115,9 @@ public static void main(String... args) { Optional.ofNullable(bindPort), 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 83c5a0bd..ac150cda 100644 --- a/netifi-spring-boot-autoconfigure/build.gradle +++ b/netifi-spring-boot-autoconfigure/build.gradle @@ -4,14 +4,9 @@ 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') compile project(':netifi-broker-client') compile project(':netifi-discovery') @@ -20,7 +15,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') @@ -30,10 +26,16 @@ 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' 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/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 6acbd788..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,39 +40,42 @@ 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: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 +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/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-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..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 @@ -16,27 +16,28 @@ package com.netifi.spring.boot; import com.netifi.broker.BrokerClient; -import com.netifi.broker.discovery.*; +import com.netifi.broker.BrokerFactory; +import com.netifi.broker.BrokerService; +import com.netifi.broker.RoutingBrokerService; +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.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 java.time.Duration; 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; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; @@ -44,7 +45,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; @@ -54,35 +54,34 @@ 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") - public BeanDefinitionRegistryPostProcessor scanClassPathBeanDefinitionRegistryPostProcessor( - ApplicationContext applicationContext) throws BeansException { + public ScanClassPathBeanDefinitionRegistryPostProcessor + scanClassPathBeanDefinitionRegistryPostProcessor() { return new ScanClassPathBeanDefinitionRegistryPostProcessor(); } @Bean @Order(Ordered.HIGHEST_PRECEDENCE) - public BrokerClientConfigurer propertiesBasedBrokerClientConfigurer( + public BrokerServiceConfigurer propertiesBasedBrokerServiceConfigurer( BrokerClientTagSupplier brokerClientTagSupplier, BrokerClientProperties brokerClientProperties) { return builder -> { @@ -90,23 +89,20 @@ public BrokerClientConfigurer propertiesBasedBrokerClientConfigurer( BrokerClientProperties.AccessProperties access = brokerClientProperties.getAccess(); BrokerClientProperties.BrokerProperties broker = brokerClientProperties.getBroker(); BrokerClientProperties.DiscoveryProperties discovery = brokerClientProperties.getDiscovery(); - - if (!StringUtils.isEmpty(brokerClientProperties.getDestination())) { - builder.destination(brokerClientProperties.getDestination()); - } - + BrokerClientProperties.KeepAliveProperties keepalive = brokerClientProperties.getKeepalive(); 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 = @@ -152,110 +148,82 @@ 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 = brokerClientProperties.getSsl().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.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 - .tags(tags) - .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; @@ -269,7 +237,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()), @@ -285,7 +253,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(); } @@ -293,14 +261,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 mutableRouter, + List configurers, ConfigurableApplicationContext context) { - BrokerClient brokerClient = configureBrokerClient(configurers); + RoutingBrokerService brokerClient = configureBrokerClient(mutableRouter, configurers); startDaemonAwaitThread(brokerClient); @@ -316,9 +285,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() { @@ -329,16 +298,27 @@ public void run() { awaitThread.setDaemon(false); awaitThread.start(); } + + @Bean + public BrokerClient brokerClient(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 brokerClient(RoutingBrokerService routingBrokerService) { + return BrokerClient.from(routingBrokerService); } } } 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..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 @@ -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,46 @@ 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/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/messaging/BrokerClientMessagingProperties.java b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/messaging/BrokerClientMessagingProperties.java new file mode 100644 index 00000000..54ab964c --- /dev/null +++ b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/messaging/BrokerClientMessagingProperties.java @@ -0,0 +1,27 @@ +/* + * 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 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 {} diff --git a/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/messaging/BrokerMessagingAutoConfiguration.java b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/messaging/BrokerMessagingAutoConfiguration.java new file mode 100644 index 00000000..3bbea5a3 --- /dev/null +++ b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/messaging/BrokerMessagingAutoConfiguration.java @@ -0,0 +1,96 @@ +/* + * 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.broker.BrokerService; +import com.netifi.spring.boot.BrokerClientAutoConfiguration; +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 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.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.RSocketRequester; +import org.springframework.messaging.rsocket.RSocketStrategies; +import org.springframework.messaging.rsocket.annotation.support.RSocketMessageHandler; +import org.springframework.messaging.rsocket.annotation.support.RSocketRequesterMethodArgumentResolver; + +/** + * {@link EnableAutoConfiguration Auto-configuration} for Spring RSocket support in Spring + * Messaging. + * + * @author Oleh Dokuka + * @since 1.7.0 + */ +@Configuration +@ConditionalOnClass({RSocketRequester.class, RSocketFactory.class, TcpServerTransport.class}) +@AutoConfigureAfter({RSocketStrategiesAutoConfiguration.class, BrokerClientAutoConfiguration.class}) +@EnableConfigurationProperties(BrokerClientMessagingProperties.class) +public class BrokerMessagingAutoConfiguration { + + private static final RSocket STUB_RSOCKET = new AbstractRSocket() {}; + + @Bean + public NetifiBootstrap netifiBootstrap( + DefaultListableBeanFactory factory, + RSocketStrategies rSocketStrategies, + RSocketMessageHandler handler, + BrokerService brokerService, + Optional registry, + Optional tracer) { + NetifiBootstrap bootstrap = new NetifiBootstrap(brokerService); + + handler + .getArgumentResolverConfigurer() + .getCustomResolvers() + .removeIf(r -> r instanceof RSocketRequesterMethodArgumentResolver); + + handler + .getArgumentResolverConfigurer() + .addCustomResolver( + new BrokerClientRequesterMethodArgumentResolver( + brokerService, + factory, + rSocketStrategies, + registry.orElse(null), + tracer.orElse(null))); + + return bootstrap; + } + + @Bean + public MessagingRSocketRequesterClientFactory messagingRSocketRequesterClientFactory( + BrokerClientMessagingProperties properties, + BrokerService brokerClient, + RSocketStrategies rSocketStrategies, + Optional registry, + Optional tracer) { + return new MessagingRSocketRequesterClientFactory( + brokerClient, registry.orElse(null), tracer.orElse(null), rSocketStrategies); + } +} 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/messaging/NetifiBootstrap.java b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/messaging/NetifiBootstrap.java new file mode 100644 index 00000000..87d6f348 --- /dev/null +++ b/netifi-spring-boot-autoconfigure/src/main/java/com/netifi/spring/boot/messaging/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.messaging; + +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/main/resources/META-INF/spring.factories b/netifi-spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories index 079a0421..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,4 +1,7 @@ # Auto Configure org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ + com.netifi.spring.boot.DefaultRoutingAutoConfiguration,\ com.netifi.spring.boot.BrokerClientAutoConfiguration,\ + 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/BrokerClientSpringIntegrationTest.java b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/BrokerClientSpringIntegrationTest.java similarity index 91% 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..5e580981 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,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 com.netifi.broker.info.BrokerInfoService; import com.netifi.broker.info.BrokerInfoServiceClient; @@ -25,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; @@ -34,23 +33,15 @@ 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) @SpringBootTest -@DirtiesContext -@ImportAutoConfiguration({ - BrokerClientAutoConfiguration.class, - BrokerClientConfiguration.class, - BrokerClientSpringIntegrationTest.TestConfiguration.class -}) public class BrokerClientSpringIntegrationTest { @Autowired ConfigurableListableBeanFactory beanFactory; @@ -92,6 +83,8 @@ public class BrokerClientSpringIntegrationTest { @Autowired com.netifi.broker.BrokerClient brokerClient; + @Autowired com.netifi.broker.BrokerService brokerService; + @Autowired ConfigurableApplicationContext context; @Test @@ -119,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/ClientConfigurationIntegrationTest.java b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/ClientConfigurationIntegrationTest.java similarity index 67% 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..23f0950c 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,13 +13,15 @@ * 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.broker.BrokerFactory; +import com.netifi.broker.BrokerService; import com.netifi.spring.boot.support.BrokerClientConfigurer; -import com.netifi.spring.core.config.BrokerClientConfiguration; +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; @@ -27,38 +29,42 @@ 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 -}) public class ClientConfigurationIntegrationTest { @Autowired @Qualifier("mock2") BrokerClientConfigurer configurer; + @Autowired + @Qualifier("mock3") + BrokerServiceConfigurer brokerServiceConfigurer; + + @Autowired BrokerClient brokerClient; + @Autowired BrokerService brokerService; + @Test public void testThatConfigurerWorks() { - ArgumentCaptor captor = - ArgumentCaptor.forClass(BrokerClient.CustomizableBuilder.class); + Assertions.assertNotNull(brokerClient); + // 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()); } @org.springframework.boot.test.context.TestConfiguration - @ComponentScan + // @ComponentScan static class TestConfiguration { @Bean @@ -71,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/DefaultClientTestIdl.java b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/DefaultClientTestIdl.java new file mode 100644 index 00000000..beca6579 --- /dev/null +++ b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/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.boot.test; + +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-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/MessageHandlerTest.java b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/MessageHandlerTest.java new file mode 100644 index 00000000..1a9ecb58 --- /dev/null +++ b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/MessageHandlerTest.java @@ -0,0 +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 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 MessageHandlerTest { + + @MessageMapping("process") + public Mono process(@Payload Mono 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 new file mode 100644 index 00000000..ce4d4871 --- /dev/null +++ b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/SpringMessagingIntegrationTest.java @@ -0,0 +1,57 @@ +/* + * 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.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.messaging.rsocket.RSocketRequester; +import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.testcontainers.containers.GenericContainer; + +@ExtendWith(SpringExtension.class) +@SpringBootTest +public class SpringMessagingIntegrationTest { + + public static GenericContainer redis = + new GenericContainer("netifi/broker:1.6.10") + .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()); + 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/TestApplication.java b/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/test/TestApplication.java similarity index 96% 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..7efd8cfd 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,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.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; 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 89% 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 0ab92b3a..f52ef3bc 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,8 +13,9 @@ * 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.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-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..bad5b48c --- /dev/null +++ b/netifi-spring-boot-autoconfigure/src/test/resources/META-INF/spring.factories @@ -0,0 +1,7 @@ +# Auto Configure +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ + com.netifi.spring.boot.DefaultRoutingAutoConfiguration,\ + com.netifi.spring.boot.BrokerClientAutoConfiguration,\ + 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-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/gradle/dependency-locks/compileClasspath.lockfile b/netifi-spring-core/gradle/dependency-locks/compileClasspath.lockfile index ab1c2f03..17961a09 100644 --- a/netifi-spring-core/gradle/dependency-locks/compileClasspath.lockfile +++ b/netifi-spring-core/gradle/dependency-locks/compileClasspath.lockfile @@ -4,35 +4,36 @@ 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.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 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.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.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-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-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/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..8f47177e --- /dev/null +++ b/netifi-spring-core/src/main/java/com/netifi/spring/core/BrokerClientFactorySupport.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.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/annotation/BaseBrokerClientFactory.java b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BaseBrokerClientFactory.java new file mode 100644 index 00000000..732b8538 --- /dev/null +++ b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/BaseBrokerClientFactory.java @@ -0,0 +1,110 @@ +/* + * 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; +import com.netifi.spring.core.BrokerClientFactory; +import com.netifi.spring.core.BrokerClientFactorySupport; +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; + + 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..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 @@ -15,7 +15,6 @@ */ 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; @@ -43,7 +42,7 @@ String group() default ""; - Class clientClass() default NoClass.class; + Class clientClass() default Void.class; Class tagSupplier() default NoTagsSupplier.class; 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..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 @@ -16,9 +16,13 @@ package com.netifi.spring.core.annotation; 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; @@ -34,9 +38,13 @@ 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; import org.springframework.core.type.MethodMetadata; import org.springframework.util.ClassUtils; @@ -66,29 +74,35 @@ public Object getSuggestedValue(DependencyDescriptor descriptor) { descriptor.getAnnotatedElement(), BrokerClient.class); if (annotation != null) { - String[] beanNamesForType = - beanFactory.getBeanNamesForType(descriptor.getDeclaredType()); + List brokerClientFactories = + new ArrayList<>( + beanFactory.getBeansOfType(BrokerClientFactorySupport.class).values()); + + AnnotationAwareOrderComparator.sort(brokerClientFactories); + + Class descriptorDeclaredType = descriptor.getDeclaredType(); + String[] beanNamesForType = beanFactory.getBeanNamesForType(descriptorDeclaredType); 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); - } + return BrokerClientStaticFactory.getBeanInstance( + 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.getDeclaredType(), annotation); + beanFactory, descriptor.getResolvableType(), annotation, brokerClientFactories); } } @@ -104,6 +118,16 @@ 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 { @@ -155,7 +179,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) { @@ -176,6 +201,17 @@ public static Class resolveClass(BeanDefinition beanDefinition) throws ClassN return clazz; } + private static ResolvableType resolveResolvableType(BeanDefinition beanDefinition) { + + if (beanDefinition instanceof RootBeanDefinition) { + return ResolvableType.forClass(((RootBeanDefinition) beanDefinition).getTargetType()); + } else if (beanDefinition instanceof GenericBeanDefinition) { + return ResolvableType.forClass(((GenericBeanDefinition) beanDefinition).getBeanClass()); + } else { + return beanDefinition.getResolvableType(); + } + } + 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 c08bf51b..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 @@ -19,9 +19,9 @@ 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.TagSupplier; import io.micrometer.core.instrument.MeterRegistry; @@ -29,9 +29,7 @@ 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 java.util.Collection; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition; @@ -53,197 +51,131 @@ 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, - final Class targetClass, - final BrokerClient brokerClientAnnotation) { - final String beanName = getBeanName(brokerClientAnnotation, targetClass); + final ResolvableType targetClass, + final BrokerClient brokerClientAnnotation, + final Collection brokerClientFactories) { + final Class resolvedTargetClass = targetClass.toClass(); + final String beanName = getBeanName(brokerClientAnnotation, resolvedTargetClass); 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())); - } - } + 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."); + // 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"); } - meterRegistry = (MeterRegistry) meterRegistryBeans.values().toArray()[0]; - } - } - - Class clientClass = brokerClientAnnotation.clientClass(); - if (BrokerClientFactory.class.isAssignableFrom(targetClass)) { - - if (clientClass.equals(NoClass.class)) { - throw new RuntimeException( - "Instantiating BrokerClientFactory requires target client class"); + clientClass = clientResolvableType.toClass(); } - 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; + for (BrokerClientFactorySupport brokerClientFactory : brokerClientFactories) { + if (brokerClientFactory.support(clientClass)) { + toRegister = + createBrokerClientFactory( + clientClass, + resolvedTargetClass, + brokerClientFactory, + brokerClientAnnotation.type(), + brokerClientAnnotation.group(), + brokerClientAnnotation.destination(), + suppliedTags); + } } - } else { - toRegister = - createBrokerClient( - brokerClient, - brokerClientAnnotation.type(), - brokerClientAnnotation.group(), - brokerClientAnnotation.destination(), - suppliedTags, - tracer, - meterRegistry, - targetClass); + 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.getSimpleName()), 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(targetClass); + new AnnotatedGenericBeanDefinition(resolvedTargetClass); AutowireCandidateQualifier qualifier = new AutowireCandidateQualifier(Qualifier.class); qualifier.setAttribute("value", "client"); @@ -261,6 +193,24 @@ public Object lookup(BrokerClient.Type type, Tags tags) { } } + 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()); + } + + 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; + } + /** * Generates a unique bean name for the field. * @@ -285,8 +235,8 @@ private static String getBeanName(BrokerClient brokerClientAnnotation, Class return beanName; } - private static T createBrokerClient( - com.netifi.broker.BrokerClient brokerClient, + static T createBrokerClient( + com.netifi.broker.BrokerService brokerClient, BrokerClient.Type routeType, String group, String destination, @@ -297,21 +247,8 @@ private static T createBrokerClient( 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; - } + BrokerSocket brokerSocket = + createBrokerRSocket(brokerClient, routeType, group, destination, tags); T toRegister; @@ -336,72 +273,54 @@ private static T createBrokerClient( return toRegister; } - private static BrokerClientFactory createBaseClientFactory( - Class clientClass, - com.netifi.broker.BrokerClient brokerClient, + public static BrokerSocket createBrokerRSocket( + com.netifi.broker.BrokerService 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); - } + Tags tags) { + BrokerSocket brokerSocket = null; - @Override - public Object lookup(BrokerClient.Type type, Tags methodTags) { - return lookup(type, group, methodTags); - } + switch (routeType) { + case BROADCAST: + brokerSocket = brokerClient.broadcast(group, tags); + break; + case GROUP: + brokerSocket = brokerClient.group(group, tags); + break; + case DESTINATION: + brokerSocket = + brokerClient.group( + group, + StringUtils.isEmpty(destination) + ? tags + : Tags.of("com.netifi.destination", destination).and(tags)); + break; + } + return brokerSocket; + } - // TODO: Do something smarter - private String key(BrokerClient.Type type, String group, Tags tags) { - return type.name() + group + destination + tags.hashCode(); - } - }; + 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 baseFactory; + 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 new file mode 100644 index 00000000..844c21cd --- /dev/null +++ b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/DefaultBroadcastAwareClientFactory.java @@ -0,0 +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.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..64860b3e --- /dev/null +++ b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/DefaultDestinationAwareClientFactory.java @@ -0,0 +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.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..ea6864be --- /dev/null +++ b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/DefaultGroupAwareClientFactory.java @@ -0,0 +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.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..78d843fe --- /dev/null +++ b/netifi-spring-core/src/main/java/com/netifi/spring/core/annotation/RpcBrokerClientFactorySupport.java @@ -0,0 +1,62 @@ +/* + * 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; +import io.opentracing.Tracer; +import io.rsocket.RSocket; + +public class RpcBrokerClientFactorySupport implements BrokerClientFactorySupport { + + private final com.netifi.broker.BrokerService brokerService; + private final Tracer tracer; + private final MeterRegistry meterRegistry; + + public RpcBrokerClientFactorySupport( + BrokerService brokerService, MeterRegistry registry, Tracer tracer) { + this.brokerService = brokerService; + this.tracer = tracer; + this.meterRegistry = registry; + } + + @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( + brokerService, 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 b33cd145..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 @@ -15,20 +15,17 @@ */ 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.BrokerService; +import com.netifi.broker.RoutingBrokerService; import com.netifi.broker.info.BrokerInfoService; import com.netifi.broker.info.BrokerInfoServiceClient; import com.netifi.broker.info.BrokerInfoServiceServer; import com.netifi.spring.core.BrokerClientApplicationEventListener; 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.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,11 +37,17 @@ 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 { + @Bean + public RpcBrokerClientFactorySupport rpcBrokerClientFactorySupport( + BrokerService brokerService, Optional registry, Optional tracer) { + return new RpcBrokerClientFactorySupport( + brokerService, registry.orElse(null), tracer.orElse(null)); + } + @Bean(name = "internalBrokerClientBeanDefinitionRegistryPostProcessor") public BrokerClientBeanDefinitionRegistryPostProcessor brokerClientBeanDefinitionRegistryPostProcessor() { @@ -53,41 +56,27 @@ public class BrokerClientConfiguration implements ApplicationContextAware { @Bean public BrokerClientApplicationEventListener brokerClientApplicationEventListener( - BrokerClient brokerClient) { - return new BrokerClientApplicationEventListener(brokerClient); + RoutingBrokerService routingBrokerService) { + return new BrokerClientApplicationEventListener(routingBrokerService); } @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 +85,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..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,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-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..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 @@ -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(); diff --git a/netifi-spring-messaging/build.gradle b/netifi-spring-messaging/build.gradle new file mode 100644 index 00000000..0a2eb58e --- /dev/null +++ b/netifi-spring-messaging/build.gradle @@ -0,0 +1,30 @@ +plugins { + id 'io.spring.dependency-management' +} + +description = 'Netifi Spring Core' + +dependencies { + compile 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..7914c03e --- /dev/null +++ b/netifi-spring-messaging/gradle/dependency-locks/compileClasspath.lockfile @@ -0,0 +1,40 @@ +# 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.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.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.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 +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.3 +org.slf4j:slf4j-api:1.7.25 +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 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..689ec02e --- /dev/null +++ b/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/BrokerClientRequesterMethodArgumentResolver.java @@ -0,0 +1,96 @@ +/* + * 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.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.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; +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 reactor.core.publisher.Mono; + +public class BrokerClientRequesterMethodArgumentResolver implements HandlerMethodArgumentResolver { + + private final BrokerService brokerClient; + private final DefaultListableBeanFactory listableBeanFactory; + private final RSocketStrategies rSocketStrategies; + private final MeterRegistry registry; + private final Tracer tracer; + + public BrokerClientRequesterMethodArgumentResolver( + BrokerService client, + DefaultListableBeanFactory factory, + RSocketStrategies strategies, + MeterRegistry registry, + Tracer tracer) { + this.brokerClient = client; + this.listableBeanFactory = factory; + this.rSocketStrategies = strategies; + this.registry = registry; + this.tracer = tracer; + } + + @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( + brokerClient, + brokerClientAnnotation, + resolveTags(listableBeanFactory, brokerClientAnnotation), + rSocketStrategies, + registry, + tracer)); + } else if (RSocket.class.isAssignableFrom(type)) { + return Mono.just( + resolveBrokerClientRSocket( + 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..85efb460 --- /dev/null +++ b/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/MessagingRSocketRequesterClientFactory.java @@ -0,0 +1,66 @@ +/* + * 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; + +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; + +public class MessagingRSocketRequesterClientFactory implements BrokerClientFactorySupport { + + private final com.netifi.broker.BrokerService brokerClient; + private final Tracer tracer; + private final MeterRegistry meterRegistry; + private final RSocketStrategies rSocketStrategies; + + public MessagingRSocketRequesterClientFactory( + com.netifi.broker.BrokerService brokerClient, + MeterRegistry meterRegistry, + Tracer tracer, + RSocketStrategies strategies) { + 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( + brokerClient, + type, + methodGroup, + null, + methodTags, + rSocketStrategies, + meterRegistry, + tracer); + } +} 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 new file mode 100644 index 00000000..2c2a204d --- /dev/null +++ b/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/MetricsAwareRSocketRequester.java @@ -0,0 +1,188 @@ +/* + * 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 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; + +public class MetricsAwareRSocketRequester implements RSocketRequester { + + private final RSocketRequester rSocketRequester; + private final MeterRegistry registry; + private final Tracer tracer; + + public MetricsAwareRSocketRequester( + RSocketRequester requester, + RSocketStrategies rSocketStrategies, + MeterRegistry meterRegistry, + Tracer tracer) { + this.rSocketRequester = requester; + this.registry = meterRegistry; + this.tracer = tracer; + } + + @Override + public RSocket rsocket() { + return rSocketRequester.rsocket(); + } + + @Override + 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 { + + 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 RequestSpec metadata(Consumer> configurer) { + return null; + } + + @Override + public RetrieveSpec data(Object data) { + requestSpec.data(data); + return this; + } + + @Override + public RetrieveSpec data(Object producer, Class elementClass) { + requestSpec.data(producer, elementClass); + return this; + } + + @Override + public RetrieveSpec data(Object producer, ParameterizedTypeReference elementTypeRef) { + requestSpec.data(producer, elementTypeRef); + return this; + } + + @Override + public RequestSpec metadata(Object metadata, MimeType mimeType) { + return requestSpec; + } + + @Override + public Mono send() { + return requestSpec + .send() + .transform( + Metrics.timed( + registry, "rsocket.spring.client", "route", route, "call.type", "send")); + } + + @Override + public Mono retrieveMono(Class dataType) { + return requestSpec + .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 requestSpec + .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 requestSpec + .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 requestSpec + .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..0610dfc7 --- /dev/null +++ b/netifi-spring-messaging/src/main/java/com/netifi/spring/messaging/RSocketRequesterStaticFactory.java @@ -0,0 +1,103 @@ +/* + * 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.BrokerService; +import com.netifi.broker.rsocket.BrokerSocket; +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( + BrokerService brokerClient, + com.netifi.spring.core.annotation.BrokerClient brokerClientAnnotation, + Tags tags, + 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( + brokerClient, + brokerClientAnnotation.type(), + brokerClientAnnotation.group(), + brokerClientAnnotation.destination(), + tags), + MimeTypeUtils.ALL, + MimeTypeUtils.ALL, + rSocketStrategies); + } + + static RSocketRequester createRSocketRequester( + BrokerService brokerClient, + com.netifi.spring.core.annotation.BrokerClient.Type routingType, + String group, + String destination, + Tags tags, + RSocketStrategies rSocketStrategies, + MeterRegistry meterRegistry, + Tracer 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( + BrokerService brokerClient, + com.netifi.spring.core.annotation.BrokerClient.Type routingType, + String group, + String destination, + Tags tags) { + return 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-boot-autoconfigure/src/test/java/com/netifi/spring/boot/DefaultClientTestIdl.java b/netifi-spring-messaging/src/test/java/com/netifi/spring/core/DefaultClientTestIdl.java similarity index 97% rename from netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/DefaultClientTestIdl.java rename to netifi-spring-messaging/src/test/java/com/netifi/spring/core/DefaultClientTestIdl.java index 6d913704..b381a1c5 100644 --- a/netifi-spring-boot-autoconfigure/src/test/java/com/netifi/spring/boot/DefaultClientTestIdl.java +++ b/netifi-spring-messaging/src/test/java/com/netifi/spring/core/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.core; import io.rsocket.rpc.annotations.internal.Generated; import io.rsocket.rpc.annotations.internal.ResourceType; 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..69b5957b --- /dev/null +++ b/netifi-spring-messaging/src/test/java/com/netifi/spring/core/TestIdlServiceServer.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 io.rsocket.ipc.MutableRouter; +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; + } + + @Override + public void selfRegister(MutableRouter router) {} +} 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..95c84e6c --- /dev/null +++ b/netifi-spring-messaging/src/test/java/com/netifi/spring/core/TestableConfiguration.java @@ -0,0 +1,43 @@ +/* + * 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.broker.RoutingBrokerService; +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 RoutingBrokerService routingBrokerService() { + return Mockito.mock(RoutingBrokerService.class); + } + + @Bean + public TestIdlImpl testIdlImpl() { + return new TestIdlImpl(); + } +} 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/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/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/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 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 edf18e94..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,21 +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 abcfa576..62e1b778 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,13 +1,17 @@ -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}" +// } +// } +// } +//} + +plugins { + id 'com.gradle.enterprise' version '3.1' } rootProject.name = 'netifi-java' @@ -27,5 +31,13 @@ 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' + +gradleEnterprise { + buildScan { + termsOfServiceUrl = 'https://gradle.com/terms-of-service' + termsOfServiceAgree = 'yes' + } +}