1.在bfxy-order模块下的application.properties添加dubbo的配置文件
# Dubbo Config properties
dubbo.application.id=bfxy-order
dubbo.application.name=bfxy-order
dubbo.application.qosPort=22211
dubbo.application.qosEnable=true
dubbo.scan.basePackages=com.bfxy.order.*
dubbo.protocol.id=dubbo
dubbo.protocol.name=dubbo
dubbo.protocol.port=12343
dubbo.registry.id=bfxy-order-registry
dubbo.registry.address=zookeeper://192.168.11.125:2181?backup=192.168.11.126:2181,192.168.11.127:2181
# Enables Dubbo All Endpoints
management.endpoint.dubbo.enabled = true
management.endpoint.dubbo-shutdown.enabled = true
management.endpoint.dubbo-configs.enabled = true
management.endpoint.dubbo-services.enabled = true
management.endpoint.dubbo-references.enabled = true
management.endpoint.dubbo-properties.enabled = true
# Dubbo Health
## StatusChecker Name defaults (default : "memory", "load" )
management.health.dubbo.status.defaults = memory
## StatusChecker Name extras (default : empty )
management.health.dubbo.status.extras = load,threadpool
2.在bfxy-store模块下的application.properties添加dubbo的配置文件
# Dubbo Config properties
dubbo.application.id=bfxy-store
dubbo.application.name=bfxy-store
dubbo.application.qosPort=22212
dubbo.application.qosEnable=true
dubbo.scan.basePackages=com.bfxy.store.*
dubbo.protocol.id=dubbo
dubbo.protocol.name=dubbo
dubbo.protocol.port=12343
dubbo.registry.id=bfxy-store-registry
dubbo.registry.address=zookeeper://192.168.11.125:2181?backup=192.168.11.126:2181,192.168.11.127:2181
# Enables Dubbo All Endpoints
management.endpoint.dubbo.enabled = true
management.endpoint.dubbo-shutdown.enabled = true
management.endpoint.dubbo-configs.enabled = true
management.endpoint.dubbo-services.enabled = true
management.endpoint.dubbo-references.enabled = true
management.endpoint.dubbo-properties.enabled = true
# Dubbo Health
## StatusChecker Name defaults (default : "memory", "load" )
management.health.dubbo.status.defaults = memory
## StatusChecker Name extras (default : empty )
management.health.dubbo.status.extras = load,threadpool
3.创建一个maven工程
在这个maven工程里面创建一个接口,我们先测试一下dubbo
package com.bfxy.store.service.api;
public interface HelloServiceApi {
String sayHello(String name);
}
4.我们将新创建的这个工程添加到bfxy-order和bfxy-store模块的依赖里面去
<dependency>
<groupId>com.bfxy</groupId>
<artifactId>bfxy-store-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
5.在bfxy-store模块下创建一个dubbo提供服务的类
package com.bfxy.store.service.provider;
import com.alibaba.dubbo.config.annotation.Service;
import com.bfxy.store.service.api.HelloServiceApi;
@Service(
version = "1.0.0",
application = "${dubbo.application.id}",
protocol = "${dubbo.protocol.id}",
registry = "${dubbo.registry.id}"
)
public class HelloServiceProvider implements HelloServiceApi {
@Override
public String sayHello(String name) {
System.err.println("-------------name:" + name);
return name;
}
}
6.在bfxy-order模块下创建一个dubbo调用的类
package com.bfxy.order.web;
import com.alibaba.dubbo.config.annotation.Reference;
import com.bfxy.store.service.api.HelloServiceApi;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@Reference(
version = "1.0.0",
application = "${dubbo.application.id}",
interfaceName = "com.bfxy.store.service.api.HelloServiceApi",
check = false,
timeout = 3000,
retries = 0 //读请求允许重试3次,写请求不要进行重试
)
private HelloServiceApi helloServiceApi;
@RequestMapping("/hello")
public String hello(@RequestParam("name") String name) {
System.err.println("----------");
return helloServiceApi.sayHello(name);
}
}
8.springboo整合dubbo成功