blob: fe54c147dc09f35ebaf8c6f31a987ea08b9d07df [file] [log] [blame]
package org.apache.dubbo.sample;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
public class ApiConsumer {
public static void main(String[] args) {
DubboBootstrap bootstrap = DubboBootstrap.getInstance();
ReferenceConfig<Greeter> ref = new ReferenceConfig<>();
ref.setInterface(Greeter.class);
ref.setProtocol(CommonConstants.TRIPLE);
ref.setProxy(CommonConstants.NATIVE_STUB);
ref.setTimeout(3000);
bootstrap.application(new ApplicationConfig("duboo-test"))
.registry(new RegistryConfig("zookeeper://127.0.0.1:2181"))
.protocol(new ProtocolConfig(CommonConstants.TRIPLE,50052))
.reference(ref)
.start();
Greeter greeter = ref.get();
HelloRequest request = HelloRequest.newBuilder().setName("Demo").build();
HelloReply reply = greeter.sayHello(request);
System.out.println("Received reply:" + reply);
}
}