dubbo-solon-plugin
<dependency>
<groupId>org.noear</groupId>
<artifactId>dubbo-solon-plugin</artifactId>
</dependency>
1、描述
分布式扩展插件。基于 dubbo2 适配的 rpc 插件。此插件需要使用 duboo 配套的注册与发现插件。
2、配置示例
- pom.xml 增加专属的注册与发现服务包:
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-registry-nacos</artifactId>
<version>${dubbo2.version}</version>
</dependency>
<!-- 或者 zk(nacos 与 zookeeper 二选一,或者别的注册服务包) -->
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-registry-zookeeper</artifactId>
<version>${dubbo2.version}</version>
</dependency>
- app.yml 增加 dubbo 配置:
server.port: 8011
dubbo:
application:
name: hello
owner: noear
registry:
address: nacos://localhost:8848
# port default = ${server.port + 20000}
3、代码应用
- 申明接口
public interface HelloService {
String sayHello(String name);
}
- 提供者(实现接口服务)
@Service(group = "hello")
@EnableDubbo
public class DubboProviderApp implements HelloService{
public static void main(String[] args) {
Solon.start(DubboProviderApp.class, args);
}
@Override
public String sayHello(String name) {
return "hello, " + name;
}
}
- 消息者
@EnableDubbo
@Controller
public class DubboConsumeApp {
public static void main(String[] args) {
Solon.start(DubboConsumeApp.class, args, app -> app.enableHttp(false));
//通过手动模式直接拉取bean
DubboConsumeApp tmp = Solon.context().getBean(DubboConsumeApp.class);
System.out.println(tmp.home());
}
@Reference(group = "hello")
HelloService helloService;
@Mapping("/")
public String home() {
return helloService.sayHello("noear");
}
}
4、代码演示
https://gitee.com/noear/solon-examples/tree/main/7.Solon-Remoting-Rpc/demo7011-rpc_dubbo_sml