diff --git a/.gitignore b/.gitignore index 47be2ad7f0..ef129e79f7 100644 --- a/.gitignore +++ b/.gitignore @@ -44,3 +44,4 @@ compiler/.gradle/* # protobuf dubbo-serialization/dubbo-serialization-protobuf/build/* +dubbo-demo/dubbo-demo-triple/build/* diff --git a/dubbo-demo/dubbo-demo-triple/pom.xml b/dubbo-demo/dubbo-demo-triple/pom.xml new file mode 100644 index 0000000000..4bf7a4b788 --- /dev/null +++ b/dubbo-demo/dubbo-demo-triple/pom.xml @@ -0,0 +1,155 @@ + + + + + org.apache.dubbo + dubbo-demo + ${revision} + ../pom.xml + + 4.0.0 + + dubbo-demo-triple + + + true + 1.8 + 1.8 + 3.7.0 + + + + + org.apache.dubbo + dubbo-filter-cache + + + org.apache.dubbo + dubbo-config-api + + + org.apache.dubbo + dubbo-config-spring + + + org.apache.dubbo + dubbo-common + + + org.apache.dubbo + dubbo-registry-api + + + org.apache.dubbo + dubbo-registry-multicast + + + org.apache.dubbo + dubbo-registry-zookeeper + + + org.apache.dubbo + dubbo-configcenter-zookeeper + + + org.apache.dubbo + dubbo-metadata-report-zookeeper + + + org.apache.dubbo + dubbo-rpc-triple + ${project.parent.version} + + + org.apache.dubbo + dubbo-remoting-netty4 + + + org.apache.dubbo + dubbo-rpc-grpc + + + org.apache.dubbo + dubbo-serialization-hessian2 + + + com.google.protobuf + protobuf-java + + + + + + + kr.motd.maven + os-maven-plugin + 1.6.1 + + + + + org.xolstice.maven.plugins + protobuf-maven-plugin + 0.6.1 + + com.google.protobuf:protoc:3.7.1:exe:${os.detected.classifier} + triple-java + build/generated/source/proto/main/java + + + + + compile + test-compile + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + ${source.level} + ${target.level} + + + + org.codehaus.mojo + build-helper-maven-plugin + + + generate-sources + + add-source + + + + build/generated/source/proto/main/java + + + + + + + + \ No newline at end of file diff --git a/dubbo-demo/dubbo-demo-triple/src/main/java/org/apache/dubbo/demo/GreeterService.java b/dubbo-demo/dubbo-demo-triple/src/main/java/org/apache/dubbo/demo/GreeterService.java new file mode 100644 index 0000000000..ae1a1c9d22 --- /dev/null +++ b/dubbo-demo/dubbo-demo-triple/src/main/java/org/apache/dubbo/demo/GreeterService.java @@ -0,0 +1,28 @@ +/* + * 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.demo; + +import org.apache.dubbo.demo.hello.HelloReply; +import org.apache.dubbo.demo.hello.HelloRequest; + +public interface GreeterService { + + /** + * Sends a greeting + */ + HelloReply sayHello(HelloRequest request); +} diff --git a/dubbo-demo/dubbo-demo-triple/src/main/java/org/apache/dubbo/demo/GreeterServiceImpl.java b/dubbo-demo/dubbo-demo-triple/src/main/java/org/apache/dubbo/demo/GreeterServiceImpl.java new file mode 100644 index 0000000000..825dd7a5e6 --- /dev/null +++ b/dubbo-demo/dubbo-demo-triple/src/main/java/org/apache/dubbo/demo/GreeterServiceImpl.java @@ -0,0 +1,30 @@ +/* + * 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.demo; + +import org.apache.dubbo.demo.hello.HelloReply; +import org.apache.dubbo.demo.hello.HelloRequest; + +public class GreeterServiceImpl implements GreeterService { + + @Override + public HelloReply sayHello(HelloRequest request) { + return HelloReply.newBuilder() + .setMessage("Hello " + request.getName()) + .build(); + } +} diff --git a/dubbo-demo/dubbo-demo-triple/src/main/java/org/apache/dubbo/demo/GreeterWrapperService.java b/dubbo-demo/dubbo-demo-triple/src/main/java/org/apache/dubbo/demo/GreeterWrapperService.java new file mode 100644 index 0000000000..bb90d4c54f --- /dev/null +++ b/dubbo-demo/dubbo-demo-triple/src/main/java/org/apache/dubbo/demo/GreeterWrapperService.java @@ -0,0 +1,25 @@ +/* + * 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.demo; + +public interface GreeterWrapperService { + + /** + * Sends a greeting + */ + String sayHello(String request); +} diff --git a/dubbo-demo/dubbo-demo-triple/src/main/java/org/apache/dubbo/demo/GreeterWrapperServiceImpl.java b/dubbo-demo/dubbo-demo-triple/src/main/java/org/apache/dubbo/demo/GreeterWrapperServiceImpl.java new file mode 100644 index 0000000000..5fb68739f8 --- /dev/null +++ b/dubbo-demo/dubbo-demo-triple/src/main/java/org/apache/dubbo/demo/GreeterWrapperServiceImpl.java @@ -0,0 +1,29 @@ +/* + * 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.demo; + +public class GreeterWrapperServiceImpl implements GreeterWrapperService { + + @Override + public String sayHello(String request) { + StringBuilder responseBuilder = new StringBuilder(request); + for (int i = 0; i < 20; i++) { + responseBuilder.append(responseBuilder); + } + return responseBuilder.toString(); + } +} diff --git a/dubbo-demo/dubbo-demo-triple/src/main/java/org/apache/dubbo/demo/consumer/ApiConsumer.java b/dubbo-demo/dubbo-demo-triple/src/main/java/org/apache/dubbo/demo/consumer/ApiConsumer.java new file mode 100644 index 0000000000..af326d3efa --- /dev/null +++ b/dubbo-demo/dubbo-demo-triple/src/main/java/org/apache/dubbo/demo/consumer/ApiConsumer.java @@ -0,0 +1,53 @@ +/* + * 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.demo.consumer; + +import org.apache.dubbo.common.constants.CommonConstants; +import org.apache.dubbo.config.ApplicationConfig; +import org.apache.dubbo.config.ReferenceConfig; +import org.apache.dubbo.config.RegistryConfig; +import org.apache.dubbo.demo.GreeterService; +import org.apache.dubbo.demo.hello.HelloReply; +import org.apache.dubbo.demo.hello.HelloRequest; + +import java.io.IOException; +import java.util.concurrent.TimeUnit; + +public class ApiConsumer { + public static void main(String[] args) throws InterruptedException, IOException { + ReferenceConfig referenceConfig = new ReferenceConfig<>(); + referenceConfig.setInterface(GreeterService.class); + referenceConfig.setCheck(false); + referenceConfig.setProtocol(CommonConstants.TRIPLE); + referenceConfig.setLazy(true); + referenceConfig.setTimeout(100000); + referenceConfig.setApplication(new ApplicationConfig("dubbo-demo-triple-api-consumer")); + referenceConfig.setRegistry(new RegistryConfig("zookeeper://127.0.0.1:2181")); + GreeterService greeterService = referenceConfig.get(); + System.out.println("dubbo referenceConfig started"); + try { + final HelloReply reply = greeterService.sayHello(HelloRequest.newBuilder() + .setName("triple") + .build()); + TimeUnit.SECONDS.sleep(1); + System.out.println("Reply: " + reply.getMessage()); + } catch (Throwable t) { + t.printStackTrace(); + } + System.in.read(); + } +} diff --git a/dubbo-demo/dubbo-demo-triple/src/main/java/org/apache/dubbo/demo/consumer/ApiWrapperConsumer.java b/dubbo-demo/dubbo-demo-triple/src/main/java/org/apache/dubbo/demo/consumer/ApiWrapperConsumer.java new file mode 100644 index 0000000000..7ef57526ed --- /dev/null +++ b/dubbo-demo/dubbo-demo-triple/src/main/java/org/apache/dubbo/demo/consumer/ApiWrapperConsumer.java @@ -0,0 +1,43 @@ +/* + * 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.demo.consumer; + +import org.apache.dubbo.config.ApplicationConfig; +import org.apache.dubbo.config.ReferenceConfig; +import org.apache.dubbo.config.RegistryConfig; +import org.apache.dubbo.demo.GreeterWrapperService; + +import java.io.IOException; + +public class ApiWrapperConsumer { + public static void main(String[] args) throws IOException { + ReferenceConfig referenceConfig = new ReferenceConfig<>(); + referenceConfig.setInterface(GreeterWrapperService.class); + referenceConfig.setCheck(false); + referenceConfig.setProtocol("tri"); + referenceConfig.setLazy(true); + referenceConfig.setApplication(new ApplicationConfig("dubbo-demo-triple-api-wrapper-consumer")); + referenceConfig.setRegistry(new RegistryConfig("zookeeper://127.0.0.1:2181")); + final GreeterWrapperService greeterWrapperService = referenceConfig.get(); + System.out.println("dubbo referenceConfig started"); + long st = System.currentTimeMillis(); + String reply = greeterWrapperService.sayHello("haha"); + // 4MB response + System.out.println("Reply length:" + reply.length() + " cost:" + (System.currentTimeMillis() - st)); + System.in.read(); + } +} diff --git a/dubbo-demo/dubbo-demo-triple/src/main/java/org/apache/dubbo/demo/provider/ApiProvider.java b/dubbo-demo/dubbo-demo-triple/src/main/java/org/apache/dubbo/demo/provider/ApiProvider.java new file mode 100644 index 0000000000..6aa7599a29 --- /dev/null +++ b/dubbo-demo/dubbo-demo-triple/src/main/java/org/apache/dubbo/demo/provider/ApiProvider.java @@ -0,0 +1,41 @@ +/* + * 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.demo.provider; + +import org.apache.dubbo.common.constants.CommonConstants; +import org.apache.dubbo.config.ApplicationConfig; +import org.apache.dubbo.config.ProtocolConfig; +import org.apache.dubbo.config.RegistryConfig; +import org.apache.dubbo.config.ServiceConfig; +import org.apache.dubbo.demo.GreeterService; +import org.apache.dubbo.demo.GreeterServiceImpl; + +import java.util.concurrent.CountDownLatch; + +public class ApiProvider { + public static void main(String[] args) throws InterruptedException { + ServiceConfig serviceConfig = new ServiceConfig<>(); + serviceConfig.setInterface(GreeterService.class); + serviceConfig.setRef(new GreeterServiceImpl()); + serviceConfig.setProtocol(new ProtocolConfig(CommonConstants.TRIPLE, 50051)); + serviceConfig.setApplication(new ApplicationConfig("dubbo-demo-triple-api-provider")); + serviceConfig.setRegistry(new RegistryConfig("zookeeper://127.0.0.1:2181")); + serviceConfig.export(); + System.out.println("dubbo service started"); + new CountDownLatch(1).await(); + } +} diff --git a/dubbo-demo/dubbo-demo-triple/src/main/java/org/apache/dubbo/demo/provider/ApiWrapperProvider.java b/dubbo-demo/dubbo-demo-triple/src/main/java/org/apache/dubbo/demo/provider/ApiWrapperProvider.java new file mode 100644 index 0000000000..9fff3f6f80 --- /dev/null +++ b/dubbo-demo/dubbo-demo-triple/src/main/java/org/apache/dubbo/demo/provider/ApiWrapperProvider.java @@ -0,0 +1,41 @@ +/* + * 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.demo.provider; + +import org.apache.dubbo.common.constants.CommonConstants; +import org.apache.dubbo.config.ApplicationConfig; +import org.apache.dubbo.config.ProtocolConfig; +import org.apache.dubbo.config.RegistryConfig; +import org.apache.dubbo.config.ServiceConfig; +import org.apache.dubbo.demo.GreeterWrapperService; +import org.apache.dubbo.demo.GreeterWrapperServiceImpl; + +import java.io.IOException; + +public class ApiWrapperProvider { + public static void main(String[] args) throws IOException { + ServiceConfig serviceConfig = new ServiceConfig<>(); + serviceConfig.setInterface(GreeterWrapperService.class); + serviceConfig.setRef(new GreeterWrapperServiceImpl()); + serviceConfig.setProtocol(new ProtocolConfig(CommonConstants.TRIPLE, 50051)); + serviceConfig.setApplication(new ApplicationConfig("dubbo-demo-triple-api-wrapper-provider")); + serviceConfig.setRegistry(new RegistryConfig("zookeeper://127.0.0.1:2181")); + serviceConfig.export(); + System.out.println("dubbo service started"); + System.in.read(); + } +} diff --git a/dubbo-demo/dubbo-demo-triple/src/main/proto/helloworld.proto b/dubbo-demo/dubbo-demo-triple/src/main/proto/helloworld.proto new file mode 100644 index 0000000000..f23688817e --- /dev/null +++ b/dubbo-demo/dubbo-demo-triple/src/main/proto/helloworld.proto @@ -0,0 +1,29 @@ +// 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. +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "org.apache.dubbo.demo.hello"; +option java_outer_classname = "HelloWorldProto"; +option objc_class_prefix = "HLW"; + +package helloworld; + +// The request message containing the user's name. +message HelloRequest { + string name = 1; +} + +// The response message containing the greetings +message HelloReply { + string message = 1; +} diff --git a/dubbo-demo/dubbo-demo-triple/src/main/resources/log4j.properties b/dubbo-demo/dubbo-demo-triple/src/main/resources/log4j.properties new file mode 100644 index 0000000000..6b82abab9e --- /dev/null +++ b/dubbo-demo/dubbo-demo-triple/src/main/resources/log4j.properties @@ -0,0 +1,26 @@ +# +# +# 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. +# +# + +###set log levels### +log4j.rootLogger=debug, stdout +###output to the console### +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=[%d{dd/MM/yy hh:mm:ss:sss z}] %t %5p %c{2}: %m%n \ No newline at end of file diff --git a/dubbo-demo/pom.xml b/dubbo-demo/pom.xml index 573615a6fc..12dfeb3a13 100644 --- a/dubbo-demo/pom.xml +++ b/dubbo-demo/pom.xml @@ -36,6 +36,7 @@ dubbo-demo-annotation dubbo-demo-api dubbo-demo-generic-call + dubbo-demo-triple