Skip to content

Commit

Permalink
use new code model in dubbo-demo-triple. (apache#8177)
Browse files Browse the repository at this point in the history
  • Loading branch information
horizonzy authored Jun 30, 2021
1 parent 05dbea9 commit 99b42d9
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.apache.dubbo.demo.consumer;

import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.MetadataReportConfig;
import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
Expand Down Expand Up @@ -63,6 +64,7 @@ private static void runWithRefer() {
ReferenceConfig<DemoService> reference = new ReferenceConfig<>();
reference.setApplication(new ApplicationConfig("dubbo-demo-api-consumer"));
reference.setRegistry(new RegistryConfig("zookeeper://127.0.0.1:2181"));
reference.setMetadataReportConfig(new MetadataReportConfig("zookeeper://127.0.0.1:2181"));
reference.setInterface(DemoService.class);
DemoService service = reference.get();
String message = service.sayHello("dubbo");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.apache.dubbo.demo.provider;

import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.MetadataReportConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.ServiceConfig;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
Expand Down Expand Up @@ -56,6 +57,7 @@ private static void startWithExport() throws InterruptedException {
service.setRef(new DemoServiceImpl());
service.setApplication(new ApplicationConfig("dubbo-demo-api-provider"));
service.setRegistry(new RegistryConfig("zookeeper://127.0.0.1:2181"));
service.setMetadataReportConfig(new MetadataReportConfig("zookeeper://127.0.0.1:2181"));
service.export();

System.out.println("dubbo service started");
Expand Down
6 changes: 5 additions & 1 deletion dubbo-demo/dubbo-demo-triple/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-rpc-grpc</artifactId>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-rpc-dubbo</artifactId>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-serialization-hessian2</artifactId>
Expand Down Expand Up @@ -168,4 +172,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.demo.GreeterService;
import org.apache.dubbo.demo.hello.HelloReply;
import org.apache.dubbo.demo.hello.HelloRequest;
Expand All @@ -35,8 +36,13 @@ public static void main(String[] args) throws InterruptedException, IOException
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"));

DubboBootstrap bootstrap = DubboBootstrap.getInstance();
bootstrap.application(new ApplicationConfig("dubbo-demo-triple-api-consumer"))
.registry(new RegistryConfig("zookeeper://127.0.0.1:2181"))
.reference(referenceConfig)
.start();

GreeterService greeterService = referenceConfig.get();
System.out.println("dubbo referenceConfig started");
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.demo.GreeterWrapperService;

import java.io.IOException;
Expand All @@ -30,8 +31,13 @@ public static void main(String[] args) throws IOException {
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"));

DubboBootstrap bootstrap = DubboBootstrap.getInstance();
bootstrap.application(new ApplicationConfig("dubbo-demo-triple-api-wrapper-consumer"))
.registry(new RegistryConfig("zookeeper://127.0.0.1:2181"))
.reference(referenceConfig)
.start();

final GreeterWrapperService greeterWrapperService = referenceConfig.get();
System.out.println("dubbo referenceConfig started");
long st = System.currentTimeMillis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,22 @@
import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.ServiceConfig;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
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<GreeterService> 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();

DubboBootstrap bootstrap = DubboBootstrap.getInstance();
bootstrap.application(new ApplicationConfig("dubbo-demo-triple-api-provider"))
.registry(new RegistryConfig("zookeeper://127.0.0.1:2181"))
.protocol(new ProtocolConfig(CommonConstants.TRIPLE, 50051))
.service(serviceConfig)
.start()
.await();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.ServiceConfig;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.demo.GreeterWrapperService;
import org.apache.dubbo.demo.GreeterWrapperServiceImpl;

Expand All @@ -31,11 +32,13 @@ public static void main(String[] args) throws IOException {
ServiceConfig<GreeterWrapperService> 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();

DubboBootstrap bootstrap = DubboBootstrap.getInstance();
bootstrap.application(new ApplicationConfig("dubbo-demo-triple-api-wrapper-provider"))
.registry(new RegistryConfig("zookeeper://127.0.0.1:2181"))
.protocol(new ProtocolConfig(CommonConstants.TRIPLE, 50051))
.service(serviceConfig)
.start()
.await();
}
}

0 comments on commit 99b42d9

Please sign in to comment.