pom引用
<properties>
<dubbo.version>2.7.3</dubbo.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<version>${dubbo.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-dependencies-zookeeper</artifactId>
<version>${dubbo.version}</version>
<type>pom</type>
</dependency>
</dependencies>
provider
配置文件
发布的时候可以和 jar同路径,会优先读取。
dubbo.properties
dubbo.application.name=xxx-provider
dubbo.protocol.port=-1
dubbo.registry.address=zookeeper://ip-191:2181
dubbo.protocol.name=dubbo
dubbo.service.loadbalance=roundrobin
dubbo.service.group=test
dubbo.service.version=1.0
dubbo.service.retries=0
启动类
@EnableDubbo(scanBasePackages = "com.alvin")
service
import org.apache.dubbo.config.annotation.Service;
@Service
public class AddService implements IAddService {
@Override
public Integer add(int a, int b) {
return a + b;
}
}
consumer
配置文件
dubbo.properties
dubbo.application.name=xxx-consumer
dubbo.registry.address=zookeeper://ip-191:2181
dubbo.consumer.check=false
dubbo.reference.loadbalance=roundrobin
dubbo.reference.group=test
dubbo.reference.version=1.0
dubbo.reference.retries=0
启动类
@EnableDubbo(scanBasePackages = "com.alvin.service")
调用
@Reference
private IAddService addService;
@Override
public void run(String... args) throws Exception {
System.out.println(addService.add(2,3));
System.in.read();
}