From 438a06f7299a9628316d36117a5a35ed510c905a Mon Sep 17 00:00:00 2001 From: Robert Roeser Date: Mon, 13 Aug 2018 23:55:25 -0700 Subject: [PATCH] updated to 0.8.9 --- README.md | 3 +- build.gradle | 2 +- .../com/netifi/proteus/demo/DemoRunner.java | 46 ++++++++++-------- .../src/main/resources/application.properties | 4 +- .../src/main/resources/application.properties | 4 +- .../src/main/proto/vowelcount.proto | 2 +- .../service/DefaultVowelCountService.java | 48 +++++++------------ .../src/main/resources/application.properties | 4 +- 8 files changed, 53 insertions(+), 60 deletions(-) diff --git a/README.md b/README.md index 9f1d21d..9068331 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # proteus-spring -[![Build Status](https://travis-ci.org/netifi-proteus/proteus-spring.svg?branch=master)](https://travis-ci.org/netifi-proteus/proteus-spring) +[![Join the chat at https://gitter.im/netifi/general](https://badges.gitter.im/netifi/general.svg)](https://gitter.im/netifi/general) + [![Build Status](https://travis-ci.org/netifi-proteus/proteus-spring.svg?branch=master)](https://travis-ci.org/netifi-proteus/proteus-spring) A simple and easy mechanism for integrating the power of [Netifi Proteus](https://www.netifi.com) into your [Spring Boot](https://spring.io/projects/spring-boot) applications. diff --git a/build.gradle b/build.gradle index ae66dae..7a53fc5 100644 --- a/build.gradle +++ b/build.gradle @@ -27,7 +27,7 @@ allprojects { ext { protobufVersion = '3.6.0' - proteusVersion = '0.8.5' + proteusVersion = '0.8.9' springbomVersion = 'Cairo-SR1' } diff --git a/demos/springboot-demo/client/src/main/java/com/netifi/proteus/demo/DemoRunner.java b/demos/springboot-demo/client/src/main/java/com/netifi/proteus/demo/DemoRunner.java index 0558336..945bcb9 100644 --- a/demos/springboot-demo/client/src/main/java/com/netifi/proteus/demo/DemoRunner.java +++ b/demos/springboot-demo/client/src/main/java/com/netifi/proteus/demo/DemoRunner.java @@ -17,6 +17,7 @@ import com.netifi.proteus.demo.core.RandomString; 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 org.slf4j.Logger; @@ -26,37 +27,40 @@ import org.springframework.stereotype.Component; import reactor.core.publisher.Flux; -import java.util.concurrent.CountDownLatch; import java.util.concurrent.ThreadLocalRandom; @Component public class DemoRunner implements CommandLineRunner { - private static final Logger LOGGER = LoggerFactory.getLogger(DemoRunner.class); + private static final Logger LOGGER = LoggerFactory.getLogger(DemoRunner.class); - @Autowired - private RandomString randomString; + @Autowired private RandomString randomString; - @ProteusClient(group = "com.netifi.proteus.demo.vowelcount") - private VowelCountServiceClient client; + @ProteusClient(group = "com.netifi.proteus.demo.vowelcount") + private VowelCountServiceClient client; - @Override - public void run(String... args) throws Exception { - CountDownLatch latch = new CountDownLatch(1); + @Override + public void run(String... args) throws Exception { - // Generate stream of random strings - Flux requests = Flux.range(1, 100) - .map(cnt -> VowelCountRequest.newBuilder() + // Generate stream of random strings + Flux requests = + Flux.range(1, 100) + .map( + cnt -> + VowelCountRequest.newBuilder() .setMessage(randomString.next(10, ThreadLocalRandom.current())) .build()); - // Send stream of random strings to vowel count service - client.countVowels(requests) - .onBackpressureDrop() - .doOnComplete(latch::countDown) - .subscribe(response -> { - LOGGER.info("Total Vowels: {}", response.getVowelCnt()); - }); +/* + // Send stream of random strings to vowel count service + VowelCountResponse response = client.countVowels(requests).block(); - latch.await(); - } + LOGGER.info("Total Vowels: {}", response.getVowelCnt()); + + System.exit(0); + */ + + // Send stream of random strings to vowel count service + client.countVowels(requests).doOnError(Throwable::printStackTrace).subscribe(response -> LOGGER.info("Total Vowels: {}", response.getVowelCnt())); + + } } diff --git a/demos/springboot-demo/client/src/main/resources/application.properties b/demos/springboot-demo/client/src/main/resources/application.properties index bd91aa2..75b7121 100644 --- a/demos/springboot-demo/client/src/main/resources/application.properties +++ b/demos/springboot-demo/client/src/main/resources/application.properties @@ -17,5 +17,5 @@ netifi.proteus.broker.hostname=localhost netifi.proteus.broker.port=8001 -netifi.proteus.accesskey=3006839580103245170 -netifi.proteus.accesstoken=SkOlZxqQcTboZE3fni4OVXVC0e0= +netifi.proteus.accesskey=9007199254740991 +netifi.proteus.accesstoken=kTBDVtfRBO4tHOnZzSyY5ym2kfY= diff --git a/demos/springboot-demo/isvowel-service/src/main/resources/application.properties b/demos/springboot-demo/isvowel-service/src/main/resources/application.properties index 077f60a..7f1e244 100644 --- a/demos/springboot-demo/isvowel-service/src/main/resources/application.properties +++ b/demos/springboot-demo/isvowel-service/src/main/resources/application.properties @@ -17,5 +17,5 @@ netifi.proteus.brokerHostname=localhost netifi.proteus.brokerPort=8001 -netifi.proteus.accessKey=3006839580103245170 -netifi.proteus.accessToken=SkOlZxqQcTboZE3fni4OVXVC0e0= +netifi.proteus.accesskey=9007199254740991 +netifi.proteus.accesstoken=kTBDVtfRBO4tHOnZzSyY5ym2kfY= diff --git a/demos/springboot-demo/vowelcount-idl/src/main/proto/vowelcount.proto b/demos/springboot-demo/vowelcount-idl/src/main/proto/vowelcount.proto index 8e77098..596d03d 100644 --- a/demos/springboot-demo/vowelcount-idl/src/main/proto/vowelcount.proto +++ b/demos/springboot-demo/vowelcount-idl/src/main/proto/vowelcount.proto @@ -7,7 +7,7 @@ option java_outer_classname = "VowelCountServiceProto"; option java_multiple_files = true; service VowelCountService { - rpc CountVowels (stream VowelCountRequest) returns (stream VowelCountResponse) {} + rpc CountVowels (stream VowelCountRequest) returns (VowelCountResponse) {} } message VowelCountRequest { diff --git a/demos/springboot-demo/vowelcount-service/src/main/java/com/netifi/proteus/demo/vowelcount/service/DefaultVowelCountService.java b/demos/springboot-demo/vowelcount-service/src/main/java/com/netifi/proteus/demo/vowelcount/service/DefaultVowelCountService.java index 5a63771..4968056 100644 --- a/demos/springboot-demo/vowelcount-service/src/main/java/com/netifi/proteus/demo/vowelcount/service/DefaultVowelCountService.java +++ b/demos/springboot-demo/vowelcount-service/src/main/java/com/netifi/proteus/demo/vowelcount/service/DefaultVowelCountService.java @@ -23,38 +23,26 @@ import org.reactivestreams.Publisher; import org.springframework.stereotype.Component; import reactor.core.publisher.Flux; - -import java.util.concurrent.atomic.AtomicLong; -import java.util.function.Function; +import reactor.core.publisher.Mono; @Component public class DefaultVowelCountService implements VowelCountService { - private final AtomicLong totalVowels = new AtomicLong(0); - - @ProteusClient(group = "com.netifi.proteus.demo.isvowel") - private IsVowelServiceClient isVowelClient; + @ProteusClient(group = "com.netifi.proteus.demo.isvowel") + private IsVowelServiceClient isVowelClient; - @Override - public Flux countVowels(Publisher messages, ByteBuf metadata) { - return Flux.from(s -> - Flux.from(messages) - // Split each incoming random string into a stream of individual characters - .flatMap(vowelCountRequest -> Flux.just(vowelCountRequest.getMessage().split("(? IsVowelRequest.newBuilder().setCharacter(c).build()) - // Send each IsVowelRequest to the IsVowel service - .flatMap((Function>) isVowelClient::isVowel) - .doOnNext(isVowelResponse -> { - if (isVowelResponse.getIsVowel()) { - // For every vowel found by the IsVowel service, increment the vowel count and send the - // current vowel count to the client - s.onNext(VowelCountResponse.newBuilder() - .setVowelCnt(totalVowels.incrementAndGet()) - .build()); - } - }) - .doOnComplete(s::onComplete) - .subscribe() - ); - } + @Override + public Mono countVowels( + Publisher messages, ByteBuf metadata) { + return Flux.from(messages) + .flatMap( + request -> + Flux.fromArray(request.getMessage().split("(? + isVowelClient + .isVowel(IsVowelRequest.newBuilder().setCharacter(s).build()) + .filter(IsVowelResponse::getIsVowel))) + .count() + .map(count -> VowelCountResponse.newBuilder().setVowelCnt(count).build()); + } } diff --git a/demos/springboot-demo/vowelcount-service/src/main/resources/application.properties b/demos/springboot-demo/vowelcount-service/src/main/resources/application.properties index 077f60a..7f1e244 100644 --- a/demos/springboot-demo/vowelcount-service/src/main/resources/application.properties +++ b/demos/springboot-demo/vowelcount-service/src/main/resources/application.properties @@ -17,5 +17,5 @@ netifi.proteus.brokerHostname=localhost netifi.proteus.brokerPort=8001 -netifi.proteus.accessKey=3006839580103245170 -netifi.proteus.accessToken=SkOlZxqQcTboZE3fni4OVXVC0e0= +netifi.proteus.accesskey=9007199254740991 +netifi.proteus.accesstoken=kTBDVtfRBO4tHOnZzSyY5ym2kfY=