You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by al...@apache.org on 2022/08/22 08:09:14 UTC

[dubbo-samples] branch master updated: update: recover readinessProbe (#498)

This is an automated email from the ASF dual-hosted git repository.

albumenj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-samples.git


The following commit(s) were added to refs/heads/master by this push:
     new 135797c8 update: recover readinessProbe (#498)
135797c8 is described below

commit 135797c8805ee79157ecbe397bdb9d04f398fdfc
Author: conghuhu <56...@users.noreply.github.com>
AuthorDate: Mon Aug 22 16:09:07 2022 +0800

    update: recover readinessProbe (#498)
    
    feat: add bi example in mesh example
---
 .../deploy/consumer/Deployment.yml                 | 12 +++----
 .../deploy/provider/Deployment-v2.yml              | 14 ++++----
 .../deploy/provider/Deployment.yml                 | 14 ++++----
 .../apache/dubbo/samples/ConsumerBootstrap.java    | 20 ++++++++---
 .../samples/action/GreetingServiceConsumer.java    | 19 +++++++++++
 .../StdoutStreamObserver.java}                     | 39 ++++++++++++----------
 6 files changed, 77 insertions(+), 41 deletions(-)

diff --git a/dubbo-samples-mesh-k8s/deploy/consumer/Deployment.yml b/dubbo-samples-mesh-k8s/deploy/consumer/Deployment.yml
index bd5320b3..156af2a8 100644
--- a/dubbo-samples-mesh-k8s/deploy/consumer/Deployment.yml
+++ b/dubbo-samples-mesh-k8s/deploy/consumer/Deployment.yml
@@ -43,12 +43,12 @@ spec:
               port: http-health
             initialDelaySeconds: 5
             periodSeconds: 5
-          #          readinessProbe:
-          #            httpGet:
-          #              path: /ready
-          #              port: http-health
-          #            initialDelaySeconds: 5
-          #            periodSeconds: 5
+          readinessProbe:
+            httpGet:
+              path: /ready
+              port: http-health
+            initialDelaySeconds: 5
+            periodSeconds: 5
           startupProbe:
             httpGet:
               path: /startup
diff --git a/dubbo-samples-mesh-k8s/deploy/provider/Deployment-v2.yml b/dubbo-samples-mesh-k8s/deploy/provider/Deployment-v2.yml
index a04b89b0..7631153a 100644
--- a/dubbo-samples-mesh-k8s/deploy/provider/Deployment-v2.yml
+++ b/dubbo-samples-mesh-k8s/deploy/provider/Deployment-v2.yml
@@ -36,13 +36,13 @@ spec:
             initialDelaySeconds: 10
             periodSeconds: 5
             timeoutSeconds: 1
-          #          readinessProbe:
-          #            httpGet:
-          #              path: /ready
-          #              port: http-health
-          #            initialDelaySeconds: 5
-          #            periodSeconds: 5
-          #            timeoutSeconds: 2
+          readinessProbe:
+            httpGet:
+              path: /ready
+              port: http-health
+            initialDelaySeconds: 5
+            periodSeconds: 5
+            timeoutSeconds: 2
           startupProbe:
             httpGet:
               path: /startup
diff --git a/dubbo-samples-mesh-k8s/deploy/provider/Deployment.yml b/dubbo-samples-mesh-k8s/deploy/provider/Deployment.yml
index 1f449f37..7afdad99 100644
--- a/dubbo-samples-mesh-k8s/deploy/provider/Deployment.yml
+++ b/dubbo-samples-mesh-k8s/deploy/provider/Deployment.yml
@@ -36,13 +36,13 @@ spec:
             initialDelaySeconds: 10
             periodSeconds: 5
             timeoutSeconds: 1
-          #          readinessProbe:
-          #            httpGet:
-          #              path: /ready
-          #              port: http-health
-          #            initialDelaySeconds: 5
-          #            periodSeconds: 5
-          #            timeoutSeconds: 2
+          readinessProbe:
+            httpGet:
+              path: /ready
+              port: http-health
+            initialDelaySeconds: 5
+            periodSeconds: 5
+            timeoutSeconds: 2
           startupProbe:
             httpGet:
               path: /startup
diff --git a/dubbo-samples-mesh-k8s/dubbo-samples-mesh-consumer/src/main/java/org/apache/dubbo/samples/ConsumerBootstrap.java b/dubbo-samples-mesh-k8s/dubbo-samples-mesh-consumer/src/main/java/org/apache/dubbo/samples/ConsumerBootstrap.java
index a249d933..cd6d159d 100644
--- a/dubbo-samples-mesh-k8s/dubbo-samples-mesh-consumer/src/main/java/org/apache/dubbo/samples/ConsumerBootstrap.java
+++ b/dubbo-samples-mesh-k8s/dubbo-samples-mesh-consumer/src/main/java/org/apache/dubbo/samples/ConsumerBootstrap.java
@@ -33,16 +33,28 @@ public class ConsumerBootstrap {
     public static void main(String[] args) throws InterruptedException {
         AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerConfiguration.class);
         context.start();
-        System.out.println("==================== dubbo invoke loop started ====================");
         GreetingServiceConsumer greetingServiceConsumer = context.getBean(GreetingServiceConsumer.class);
         AtomicInteger count = new AtomicInteger(0);
 
-        while (true) {
+        System.out.println("==================== dubbo unary invoke loop started ====================");
+        do {
+            Thread.sleep(5000);
             greetingServiceConsumer.doSayHello("service mesh");
-            System.out.println("==================== dubbo invoke " + count.get() + " end ====================");
+            System.out.println("==================== dubbo unary invoke " + count.get() + " end ====================");
             count.getAndIncrement();
-            Thread.sleep(5000);
         }
+        while (count.get() != 20);
+
+        System.out.println("==================== dubbo start bi streaming ====================");
+        greetingServiceConsumer.doBISayHello("service mesh");
+        System.out.println("==================== dubbo bi stream done ====================");
+
+        System.out.println("==================== dubbo start server streaming ====================");
+        greetingServiceConsumer.getHelloFromServer();
+        System.out.println("==================== dubbo server stream done ====================");
+
+        CountDownLatch countDownLatch = new CountDownLatch(1);
+        countDownLatch.await();
     }
 
     @Configuration
diff --git a/dubbo-samples-mesh-k8s/dubbo-samples-mesh-consumer/src/main/java/org/apache/dubbo/samples/action/GreetingServiceConsumer.java b/dubbo-samples-mesh-k8s/dubbo-samples-mesh-consumer/src/main/java/org/apache/dubbo/samples/action/GreetingServiceConsumer.java
index 69605253..d721156d 100644
--- a/dubbo-samples-mesh-k8s/dubbo-samples-mesh-consumer/src/main/java/org/apache/dubbo/samples/action/GreetingServiceConsumer.java
+++ b/dubbo-samples-mesh-k8s/dubbo-samples-mesh-consumer/src/main/java/org/apache/dubbo/samples/action/GreetingServiceConsumer.java
@@ -19,11 +19,13 @@
 
 package org.apache.dubbo.samples.action;
 
+import org.apache.dubbo.common.stream.StreamObserver;
 import org.apache.dubbo.config.annotation.DubboReference;
 import org.apache.dubbo.samples.Greeter;
 import org.apache.dubbo.samples.GreeterReply;
 import org.apache.dubbo.samples.GreeterRequest;
 
+import org.apache.dubbo.samples.util.StdoutStreamObserver;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Component;
@@ -43,4 +45,21 @@ public class GreetingServiceConsumer {
         LOGGER.info("consumer Unary reply <-{}", reply);
     }
 
+    public void doBISayHello(String name) {
+        String clientName = "consumer";
+        final StreamObserver<GreeterRequest> request = greeter.greetStream(new StdoutStreamObserver<>(name));
+        for (int i = 0; i < 10; i++) {
+            LOGGER.info("{} Send stream request-> {}", clientName, i);
+            request.onNext(GreeterRequest.newBuilder()
+                .setName("request")
+                .build());
+        }
+        request.onCompleted();
+    }
+
+    public void getHelloFromServer() {
+        GreeterRequest greeterRequest = GreeterRequest.newBuilder().setName("consumer").build();
+        greeter.greetServerStream(greeterRequest, new StdoutStreamObserver<>("consumer"));
+    }
+
 }
diff --git a/dubbo-samples-mesh-k8s/dubbo-samples-mesh-consumer/src/main/java/org/apache/dubbo/samples/action/GreetingServiceConsumer.java b/dubbo-samples-mesh-k8s/dubbo-samples-mesh-consumer/src/main/java/org/apache/dubbo/samples/util/StdoutStreamObserver.java
similarity index 56%
copy from dubbo-samples-mesh-k8s/dubbo-samples-mesh-consumer/src/main/java/org/apache/dubbo/samples/action/GreetingServiceConsumer.java
copy to dubbo-samples-mesh-k8s/dubbo-samples-mesh-consumer/src/main/java/org/apache/dubbo/samples/util/StdoutStreamObserver.java
index 69605253..94ac1726 100644
--- a/dubbo-samples-mesh-k8s/dubbo-samples-mesh-consumer/src/main/java/org/apache/dubbo/samples/action/GreetingServiceConsumer.java
+++ b/dubbo-samples-mesh-k8s/dubbo-samples-mesh-consumer/src/main/java/org/apache/dubbo/samples/util/StdoutStreamObserver.java
@@ -17,30 +17,35 @@
  *
  */
 
-package org.apache.dubbo.samples.action;
-
-import org.apache.dubbo.config.annotation.DubboReference;
-import org.apache.dubbo.samples.Greeter;
-import org.apache.dubbo.samples.GreeterReply;
-import org.apache.dubbo.samples.GreeterRequest;
+package org.apache.dubbo.samples.util;
 
+import org.apache.dubbo.common.stream.StreamObserver;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.stereotype.Component;
 
-@Component("annotatedConsumer")
-public class GreetingServiceConsumer {
+public class StdoutStreamObserver<T> implements StreamObserver<T>, io.grpc.stub.StreamObserver<T> {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(StdoutStreamObserver.class);
+
+    private final String name;
 
-    private static final Logger LOGGER = LoggerFactory.getLogger(GreetingServiceConsumer.class);
+    public StdoutStreamObserver(String name) {
+        this.name = name;
+    }
 
-    @DubboReference(version = "1.0.0", providedBy = "dubbo-samples-mesh-provider", lazy = true)
-    private Greeter greeter;
+    @Override
+    public void onNext(T data) {
+        LOGGER.info("{} stream <- reply:{}", name, data);
+    }
 
-    public void doSayHello(String name) {
-        final GreeterReply reply = greeter.greet(GreeterRequest.newBuilder()
-            .setName(name)
-            .build());
-        LOGGER.info("consumer Unary reply <-{}", reply);
+    @Override
+    public void onError(Throwable throwable) {
+        LOGGER.error("{} stream onError", name, throwable);
+        throwable.printStackTrace();
     }
 
+    @Override
+    public void onCompleted() {
+        LOGGER.info("{} stream completed", name);
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org