Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
refactoring of the integration with Spring
* split autoconfiguration module onto core and autoconfiguration
* fixed application bootstrap for the cases where there is no web environment
* improve configurations and components bootstrap
* update to proteus 0.8.10
* fixed examples
  • Loading branch information
OlegDokuka committed Sep 5, 2018
1 parent 2a4f417 commit 90d3593
Show file tree
Hide file tree
Showing 32 changed files with 506 additions and 346 deletions.
7 changes: 4 additions & 3 deletions build.gradle
Expand Up @@ -26,9 +26,10 @@ allprojects {
apply plugin: 'idea'

ext {
protobufVersion = '3.6.0'
proteusVersion = '0.8.9'
springbomVersion = 'Cairo-SR1'
rsocketRpcVersion = "0.1.2"
protobufVersion = '3.6.1'
proteusVersion = '0.8.10'
springBootDependenciesVersion = '2.0.4.RELEASE'
}

repositories {
Expand Down
2 changes: 1 addition & 1 deletion demos/springboot-demo/client/build.gradle
Expand Up @@ -10,7 +10,7 @@ sourceCompatibility = 1.8

dependencyManagement {
imports {
mavenBom "io.spring.platform:platform-bom:${springbomVersion}"
mavenBom "org.springframework.boot:spring-boot-dependencies:${springBootDependenciesVersion}"
}
}

Expand Down
Expand Up @@ -15,12 +15,10 @@
*/
package com.netifi.proteus.demo;

import com.netifi.proteus.springboot.EnableProteus;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@EnableProteus(group = "com.netifi.proteus.demo", destination = "client")
public class Application {

public static void main(String... args) {
Expand Down
Expand Up @@ -19,7 +19,7 @@
import com.netifi.proteus.demo.vowelcount.service.VowelCountRequest;
import com.netifi.proteus.demo.vowelcount.service.VowelCountResponse;
import com.netifi.proteus.demo.vowelcount.service.VowelCountServiceClient;
import io.netifi.proteus.annotations.ProteusClient;
import io.rsocket.rpc.annotations.Client;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -35,7 +35,7 @@ public class DemoRunner implements CommandLineRunner {

@Autowired private RandomString randomString;

@ProteusClient(group = "com.netifi.proteus.demo.vowelcount")
@Client(group = "com.netifi.proteus.demo.vowelcount")
private VowelCountServiceClient client;

@Override
Expand Down
Expand Up @@ -17,5 +17,8 @@
netifi.proteus.broker.hostname=localhost
netifi.proteus.broker.port=8001

netifi.proteus.accesskey=9007199254740991
netifi.proteus.accesstoken=kTBDVtfRBO4tHOnZzSyY5ym2kfY=
netifi.proteus.access.key=9007199254740991
netifi.proteus.access.token=kTBDVtfRBO4tHOnZzSyY5ym2kfY=

netifi.proteus.group=com.netifi.proteus.demo
netifi.proteus.destination=client
12 changes: 6 additions & 6 deletions demos/springboot-demo/isvowel-idl/build.gradle
Expand Up @@ -6,7 +6,7 @@ plugins {
sourceCompatibility = 1.8

dependencies {
compile "io.netifi.proteus:core:${proteusVersion}"
compile "io.rsocket.rpc:core:${rsocketRpcVersion}"
compile "com.google.protobuf:protobuf-java:${protobufVersion}"
}

Expand All @@ -18,12 +18,12 @@ protobuf {
}

plugins {
proteus {
artifact = "io.netifi.proteus:protobuf-rpc:${proteusVersion}"
rsocketRpc {
artifact = "io.rsocket.rpc:protobuf-rpc:${rsocketRpcVersion}"
}
generateProtoTasks {
ofSourceSet('main')*.plugins {
proteus {}
rsocketRpc {}
}
}
}
Expand All @@ -32,10 +32,10 @@ protobuf {
idea {
module {
sourceDirs += file("src/generated/main/java")
sourceDirs += file("src/generated/main/proteus")
sourceDirs += file("src/generated/main/rsocketRpc")

generatedSourceDirs += file('src/generated/main/java')
generatedSourceDirs += file('src/generated/main/proteus')
generatedSourceDirs += file('src/generated/main/rsocketRpc')
}
}

Expand Down
2 changes: 1 addition & 1 deletion demos/springboot-demo/isvowel-service/build.gradle
Expand Up @@ -10,7 +10,7 @@ sourceCompatibility = 1.8

dependencyManagement {
imports {
mavenBom "io.spring.platform:platform-bom:${springbomVersion}"
mavenBom "org.springframework.boot:spring-boot-dependencies:${springBootDependenciesVersion}"
}
}

Expand Down
Expand Up @@ -15,12 +15,10 @@
*/
package com.netifi.proteus.demo.isvowel;

import com.netifi.proteus.springboot.EnableProteus;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@EnableProteus(group = "com.netifi.proteus.demo.isvowel")
public class Application {

public static void main(String... args) {
Expand Down
Expand Up @@ -14,8 +14,10 @@
# limitations under the License.
#

netifi.proteus.brokerHostname=localhost
netifi.proteus.brokerPort=8001
netifi.proteus.broker.hostname=localhost
netifi.proteus.broker.port=8001

netifi.proteus.accesskey=9007199254740991
netifi.proteus.accesstoken=kTBDVtfRBO4tHOnZzSyY5ym2kfY=
netifi.proteus.access.key=9007199254740991
netifi.proteus.access.token=kTBDVtfRBO4tHOnZzSyY5ym2kfY=

netifi.proteus.group=com.netifi.proteus.demo.isvowel
12 changes: 6 additions & 6 deletions demos/springboot-demo/vowelcount-idl/build.gradle
Expand Up @@ -6,7 +6,7 @@ plugins {
sourceCompatibility = 1.8

dependencies {
compile "io.netifi.proteus:core:${proteusVersion}"
compile "io.rsocket.rpc:core:${rsocketRpcVersion}"
compile "com.google.protobuf:protobuf-java:${protobufVersion}"
}

Expand All @@ -18,12 +18,12 @@ protobuf {
}

plugins {
proteus {
artifact = "io.netifi.proteus:protobuf-rpc:${proteusVersion}"
rsocketRpc {
artifact = "io.rsocket.rpc:protobuf-rpc:${rsocketRpcVersion}"
}
generateProtoTasks {
ofSourceSet('main')*.plugins {
proteus {}
rsocketRpc {}
}
}
}
Expand All @@ -32,10 +32,10 @@ protobuf {
idea {
module {
sourceDirs += file("src/generated/main/java")
sourceDirs += file("src/generated/main/proteus")
sourceDirs += file("src/generated/main/rsocketRpc")

generatedSourceDirs += file('src/generated/main/java')
generatedSourceDirs += file('src/generated/main/proteus')
generatedSourceDirs += file('src/generated/main/rsocketRpc')
}
}

Expand Down
2 changes: 1 addition & 1 deletion demos/springboot-demo/vowelcount-service/build.gradle
Expand Up @@ -10,7 +10,7 @@ sourceCompatibility = 1.8

dependencyManagement {
imports {
mavenBom "io.spring.platform:platform-bom:${springbomVersion}"
mavenBom "org.springframework.boot:spring-boot-dependencies:${springBootDependenciesVersion}"
}
}

Expand Down
Expand Up @@ -15,12 +15,10 @@
*/
package com.netifi.proteus.demo.vowelcount;

import com.netifi.proteus.springboot.EnableProteus;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@EnableProteus(group = "com.netifi.proteus.demo.vowelcount")
public class Application {

public static void main(String... args) {
Expand Down
Expand Up @@ -18,16 +18,17 @@
import com.netifi.proteus.demo.isvowel.service.IsVowelRequest;
import com.netifi.proteus.demo.isvowel.service.IsVowelResponse;
import com.netifi.proteus.demo.isvowel.service.IsVowelServiceClient;
import io.netifi.proteus.annotations.ProteusClient;
import io.netty.buffer.ByteBuf;
import io.rsocket.rpc.annotations.Client;
import org.reactivestreams.Publisher;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import org.springframework.stereotype.Component;

@Component
public class DefaultVowelCountService implements VowelCountService {
@ProteusClient(group = "com.netifi.proteus.demo.isvowel")
@Client(group = "com.netifi.proteus.demo.isvowel")
private IsVowelServiceClient isVowelClient;

@Override
Expand Down
Expand Up @@ -14,8 +14,10 @@
# limitations under the License.
#

netifi.proteus.brokerHostname=localhost
netifi.proteus.brokerPort=8001
netifi.proteus.broker.hostname=localhost
netifi.proteus.broker.port=8001

netifi.proteus.accesskey=9007199254740991
netifi.proteus.accesstoken=kTBDVtfRBO4tHOnZzSyY5ym2kfY=
netifi.proteus.access.key=9007199254740991
netifi.proteus.access.token=kTBDVtfRBO4tHOnZzSyY5ym2kfY=

netifi.proteus.group=com.netifi.proteus.demo.vowelcount
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-bin.zip
15 changes: 9 additions & 6 deletions proteus-spring-boot-autoconfigure/build.gradle
@@ -1,5 +1,5 @@
plugins {
id 'io.spring.dependency-management' version '1.0.5.RELEASE'
id 'io.spring.dependency-management' version '1.0.6.RELEASE'
}

ext.artifactName = 'proteus-spring-boot-autoconfigure'
Expand All @@ -9,17 +9,20 @@ apply from: file('../gradle/java.gradle')

dependencyManagement {
imports {
mavenBom "io.spring.platform:platform-bom:${springbomVersion}"
mavenBom "org.springframework.boot:spring-boot-dependencies:${springBootDependenciesVersion}"
}
}

dependencies {
compile project(":proteus-spring-core")

compile "io.netifi.proteus:client:${proteusVersion}"
compile 'org.slf4j:slf4j-api:1.7.25'

compile 'org.slf4j:slf4j-api'
compile 'org.springframework.boot:spring-boot-autoconfigure'
compile 'javax.validation:validation-api:2.0.1.Final'
compile 'io.opentracing:opentracing-api:0.31.0'
compile 'io.micrometer:micrometer-core:1.0.3'
compile 'org.springframework.boot:spring-boot-starter-validation'
compile 'io.opentracing:opentracing-api'
compile 'io.micrometer:micrometer-core'

annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"
}
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.netifi.proteus.springboot.config;
package com.netifi.proteus.springboot;

import io.micrometer.core.instrument.MeterRegistry;
import org.springframework.context.annotation.Condition;
Expand Down
@@ -0,0 +1,112 @@
/**
* Copyright 2018 Netifi Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.netifi.proteus.springboot;

import java.util.function.Supplier;

import com.netifi.proteus.spring.core.config.ProteusConfiguration;
import io.micrometer.core.instrument.MeterRegistry;
import io.netifi.proteus.Proteus;
import io.opentracing.Tracer;

import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnNotWebApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Import;
import org.springframework.util.StringUtils;

@SpringBootConfiguration
@EnableConfigurationProperties(ProteusProperties.class)
@Import(ProteusConfiguration.class)
public class ProteusAutoConfiguration {

@Bean
@Conditional(MeterRegistrySupplierCondition.class)
public MeterRegistry meterRegistry(Supplier<MeterRegistry> supplier) {
return supplier.get();
}

@Bean
@Conditional(TracerSupplierCondition.class)
public Tracer tracer(Supplier<Tracer> supplier) {
return supplier.get();
}

@SpringBootConfiguration
@ConditionalOnNotWebApplication
@ConditionalOnMissingBean(Proteus.class)
public static class NonWebProteusConfiguration {

@Bean
public Proteus proteus(ProteusProperties proteusProperties) {
Proteus proteus = configureProteus(proteusProperties);

startDaemonAwaitThread(proteus);

return proteus;
}

private void startDaemonAwaitThread(Proteus proteus) {
Thread awaitThread = new Thread("proteus") {

@Override
public void run() {
proteus.onClose().block();
}

};
awaitThread.setContextClassLoader(getClass().getClassLoader());
awaitThread.setDaemon(false);
awaitThread.start();
}
}

@SpringBootConfiguration
@ConditionalOnWebApplication
@ConditionalOnMissingBean(Proteus.class)
public static class WebProteusConfiguration {

@Bean
public Proteus proteus(ProteusProperties proteusProperties) {
return configureProteus(proteusProperties);
}
}


static Proteus configureProteus(ProteusProperties proteusProperties) {
ProteusProperties.AccessProperties access = proteusProperties.getAccess();
ProteusProperties.BrokerProperties broker = proteusProperties.getBroker();

Proteus.Builder builder = Proteus.builder();

if (!StringUtils.isEmpty(proteusProperties.getDestination())) {
builder.destination(proteusProperties.getDestination());
}

return builder
.accessKey(access.getKey())
.accessToken(access.getToken())
.group(proteusProperties.getGroup())
.poolSize(proteusProperties.getPoolSize())
.host(broker.getHostname())
.port(broker.getPort())
.build();
}
}

0 comments on commit 90d3593

Please sign in to comment.