<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.7.8</version>
</dependency>
public interface HelloService {
public String sayHello(String name);
}
public class HelloServiceImpl implements HelloService {
public String sayHello(String name) {
return "Hello, " + name;
}
}
public class HelloConsumer {
public static void main(String[] args) {
ApplicationConfig application = new ApplicationConfig();
application.setName("hello-consumer");
ReferenceConfig<HelloService> reference = new ReferenceConfig<HelloService>();
reference.setInterface(HelloService.class);
reference.setUrl("dubbo://localhost:20880/com.example.HelloService");
HelloService helloService = reference.get();
String result = helloService.sayHello("Dubbo");
System.out.println(result);
}
}
properties
dubbo.application.name=hello-application
dubbo.registry.address=zookeeper://127.0.0.1:2181
dubbo.protocol.name=dubbo
dubbo.protocol.port=20880
dubbo.provider.timeout=5000