This is an automated email from the ASF dual-hosted git repository.
liujun 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 fd313ba Updating gRPC sample
fd313ba is described below
commit fd313ba50195fc5f9be2b791ef75637fe5607a9a
Author: ken.lj <[email protected]>
AuthorDate: Fri Nov 15 15:23:08 2019 +0800
Updating gRPC sample
---
.../basic/comtomize/MyClientInterceptor.java | 35 ---------
.../basic/comtomize/MyClientStreamInterceptor.java | 78 ++++++++++++++++++++
.../basic/comtomize/MyServerInterceptor.java | 30 --------
.../basic/comtomize/MyServerStreamInterceptor.java | 86 ++++++++++++++++++++++
.../dubbo/samples/basic/impl/GrpcGreeterImpl.java | 1 -
...pc.protocol.grpc.interceptors.ClientInterceptor | 1 +
...pc.protocol.grpc.interceptors.ServerInterceptor | 1 +
7 files changed, 166 insertions(+), 66 deletions(-)
diff --git
a/dubbo-samples-grpc/src/main/java/org/apache/dubbo/samples/basic/comtomize/MyClientInterceptor.java
b/dubbo-samples-grpc/src/main/java/org/apache/dubbo/samples/basic/comtomize/MyClientInterceptor.java
deleted file mode 100644
index 344727f..0000000
---
a/dubbo-samples-grpc/src/main/java/org/apache/dubbo/samples/basic/comtomize/MyClientInterceptor.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 org.apache.dubbo.samples.basic.comtomize;
-
-import org.apache.dubbo.rpc.protocol.grpc.interceptors.ClientInterceptor;
-
-import io.grpc.CallOptions;
-import io.grpc.Channel;
-import io.grpc.ClientCall;
-import io.grpc.MethodDescriptor;
-
-public class MyClientInterceptor implements ClientInterceptor {
- @Override
- public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
- MethodDescriptor<ReqT, RespT> methodDescriptor,
- CallOptions callOptions,
- Channel channel
- ) {
- return null;
- }
-}
diff --git
a/dubbo-samples-grpc/src/main/java/org/apache/dubbo/samples/basic/comtomize/MyClientStreamInterceptor.java
b/dubbo-samples-grpc/src/main/java/org/apache/dubbo/samples/basic/comtomize/MyClientStreamInterceptor.java
new file mode 100644
index 0000000..f0d73bd
--- /dev/null
+++
b/dubbo-samples-grpc/src/main/java/org/apache/dubbo/samples/basic/comtomize/MyClientStreamInterceptor.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.dubbo.samples.basic.comtomize;
+
+import org.apache.dubbo.common.extension.Activate;
+import org.apache.dubbo.rpc.protocol.grpc.interceptors.ClientInterceptor;
+
+import io.grpc.CallOptions;
+import io.grpc.Channel;
+import io.grpc.ClientCall;
+import io.grpc.ForwardingClientCall;
+import io.grpc.ForwardingClientCallListener;
+import io.grpc.Metadata;
+import io.grpc.MethodDescriptor;
+
+import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER;
+
+@Activate(group = CONSUMER)
+public class MyClientStreamInterceptor implements ClientInterceptor {
+ @Override
+ public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
+ MethodDescriptor<ReqT, RespT> methodDescriptor,
+ CallOptions callOptions,
+ Channel channel) {
+
+ final ClientCall<ReqT, RespT> wrappedCall =
channel.newCall(methodDescriptor, callOptions);
+ return new StreamRequestClientCall<>(wrappedCall);
+
+ }
+
+ private static class StreamRequestClientCall<ReqT, RespT> extends
ForwardingClientCall.SimpleForwardingClientCall<ReqT, RespT> {
+
+ public StreamRequestClientCall(final ClientCall<ReqT, RespT>
wrappedCall) {
+ super(wrappedCall);
+ }
+
+ @Override
+ public void start(final ClientCall.Listener<RespT> responseListener,
Metadata headers) {
+ delegate().start(new StreamResponseListener<>(responseListener),
headers);
+ }
+
+ @Override
+ public void sendMessage(ReqT reqMessage) {
+ // add your logic here
+ System.out.println("Sending request msg to server: " + reqMessage);
+ delegate().sendMessage(reqMessage);
+ }
+ }
+
+ private static class StreamResponseListener<RespT>
+ extends
ForwardingClientCallListener.SimpleForwardingClientCallListener<RespT> {
+
+ public StreamResponseListener(final ClientCall.Listener<RespT>
responseListener) {
+ super(responseListener);
+ }
+
+ @Override
+ public void onMessage(RespT respMessage) {
+ // add your logic here
+ System.out.println("Received msg from server: " + respMessage);
+ delegate().onMessage(respMessage);
+ }
+ }
+}
diff --git
a/dubbo-samples-grpc/src/main/java/org/apache/dubbo/samples/basic/comtomize/MyServerInterceptor.java
b/dubbo-samples-grpc/src/main/java/org/apache/dubbo/samples/basic/comtomize/MyServerInterceptor.java
deleted file mode 100644
index 222a8b6..0000000
---
a/dubbo-samples-grpc/src/main/java/org/apache/dubbo/samples/basic/comtomize/MyServerInterceptor.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 org.apache.dubbo.samples.basic.comtomize;
-
-import org.apache.dubbo.rpc.protocol.grpc.interceptors.ServerInterceptor;
-
-import io.grpc.Metadata;
-import io.grpc.ServerCall;
-import io.grpc.ServerCallHandler;
-
-public class MyServerInterceptor implements ServerInterceptor {
- @Override
- public <ReqT, RespT> ServerCall.Listener<ReqT>
interceptCall(ServerCall<ReqT, RespT> serverCall, Metadata metadata,
ServerCallHandler<ReqT, RespT> serverCallHandler) {
- return null;
- }
-}
diff --git
a/dubbo-samples-grpc/src/main/java/org/apache/dubbo/samples/basic/comtomize/MyServerStreamInterceptor.java
b/dubbo-samples-grpc/src/main/java/org/apache/dubbo/samples/basic/comtomize/MyServerStreamInterceptor.java
new file mode 100644
index 0000000..c5f73c7
--- /dev/null
+++
b/dubbo-samples-grpc/src/main/java/org/apache/dubbo/samples/basic/comtomize/MyServerStreamInterceptor.java
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.dubbo.samples.basic.comtomize;
+
+import org.apache.dubbo.common.extension.Activate;
+import org.apache.dubbo.rpc.protocol.grpc.interceptors.ServerInterceptor;
+
+import io.grpc.ForwardingServerCall;
+import io.grpc.ForwardingServerCallListener;
+import io.grpc.Metadata;
+import io.grpc.ServerCall;
+import io.grpc.ServerCallHandler;
+
+import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER;
+
+@Activate(group = PROVIDER)
+public class MyServerStreamInterceptor implements ServerInterceptor {
+ @Override
+ public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
+ ServerCall<ReqT, RespT> serverCall,
+ Metadata requestHeaders,
+ ServerCallHandler<ReqT, RespT> next) {
+ ServerCall.Listener<ReqT> listener = next.startCall(new
StreamResponseServerCall<>(serverCall), requestHeaders);
+
+ return new StreamRequestListener<>(listener);
+ }
+
+ private static class StreamResponseServerCall<ReqT, RespT>
+ extends ForwardingServerCall.SimpleForwardingServerCall<ReqT,
RespT> {
+
+ public StreamResponseServerCall(ServerCall<ReqT, RespT> serverCall) {
+ super(serverCall);
+ }
+
+ @Override
+ public void sendMessage(RespT message) {
+ // add you logic here
+ System.out.println("Sending response message back to client: " +
message);
+ super.sendMessage(message);
+ }
+
+ @Override
+ public void request(int numMessages) {
+ // add your logic here
+ System.out.println("Requesting " + numMessages + " more messages
from client.");
+ super.request(numMessages);
+ }
+
+ }
+
+ private static class StreamRequestListener<ReqT>
+ extends
ForwardingServerCallListener.SimpleForwardingServerCallListener<ReqT> {
+
+ public StreamRequestListener(ServerCall.Listener<ReqT>
requestListener) {
+ super(requestListener);
+ }
+
+ @Override
+ public void onMessage(ReqT message) {
+ // add your logic here
+ System.out.println("Received request message from client: " +
message);
+ super.onMessage(message);
+ }
+
+ @Override
+ public void onComplete() {
+ // add your logic here
+ System.out.println("Completed, all requests finished.");
+ super.onComplete();
+ }
+ }
+}
diff --git
a/dubbo-samples-grpc/src/main/java/org/apache/dubbo/samples/basic/impl/GrpcGreeterImpl.java
b/dubbo-samples-grpc/src/main/java/org/apache/dubbo/samples/basic/impl/GrpcGreeterImpl.java
index 0d3db40..2c7a5e3 100644
---
a/dubbo-samples-grpc/src/main/java/org/apache/dubbo/samples/basic/impl/GrpcGreeterImpl.java
+++
b/dubbo-samples-grpc/src/main/java/org/apache/dubbo/samples/basic/impl/GrpcGreeterImpl.java
@@ -25,7 +25,6 @@ public class GrpcGreeterImpl extends
GreeterGrpc.GreeterImplBase {
@Override
public void sayHello(HelloRequest request, StreamObserver<HelloReply>
responseObserver) {
- System.out.println("Received request from client.");
System.out.println("Executing thread is " +
Thread.currentThread().getName());
HelloReply reply = HelloReply.newBuilder().setMessage("Hello " +
request.getName()).build();
responseObserver.onNext(reply);
diff --git
a/dubbo-samples-grpc/src/main/resources/META-INF/services/org.apache.dubbo.rpc.protocol.grpc.interceptors.ClientInterceptor
b/dubbo-samples-grpc/src/main/resources/META-INF/services/org.apache.dubbo.rpc.protocol.grpc.interceptors.ClientInterceptor
new file mode 100644
index 0000000..de1fba9
--- /dev/null
+++
b/dubbo-samples-grpc/src/main/resources/META-INF/services/org.apache.dubbo.rpc.protocol.grpc.interceptors.ClientInterceptor
@@ -0,0 +1 @@
+logger=org.apache.dubbo.samples.basic.comtomize.MyClientStreamInterceptor
\ No newline at end of file
diff --git
a/dubbo-samples-grpc/src/main/resources/META-INF/services/org.apache.dubbo.rpc.protocol.grpc.interceptors.ServerInterceptor
b/dubbo-samples-grpc/src/main/resources/META-INF/services/org.apache.dubbo.rpc.protocol.grpc.interceptors.ServerInterceptor
new file mode 100644
index 0000000..6ca19b9
--- /dev/null
+++
b/dubbo-samples-grpc/src/main/resources/META-INF/services/org.apache.dubbo.rpc.protocol.grpc.interceptors.ServerInterceptor
@@ -0,0 +1 @@
+logger=org.apache.dubbo.samples.basic.comtomize.MyServerStreamInterceptor
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]