Dubbo的泛化调用不需要引入调用方的接口,只需要指定接口的全类名,就可以调用服务,一般用于框架集成。接下来就基于SpringBoot实现了Dubbo的泛化调用。
1、服务端定义
1.1 服务定义及实现
package com.smart.springboot.api;
public interface HelloServiceFacade {
void sayHello();
}
package com.smart.springboot.service;
import com.alibaba.dubbo.config.annotation.Service;
import com.smart.springboot.api.HelloServiceFacade;
/**
* @author : cuantianhou 2020/1/14
*/
@Service(version = "1.0.0",timeout = 20000)
public class HelloService implements HelloServiceFacade {
@Override
public void sayHello() {
System.out.println("123");
}
}
1.2 服务提供者配置
package com.smart.springboot.config;
import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.MonitorConfig;
import com.alibaba.dubbo.config.ProtocolConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author : cuantianhou 2020/4/1
*/
@Configuration
public class DubboServiceConfig {
@Bean
public ApplicationConfig applicationConfig(){
ApplicationConfig applicationConfig = new ApplicationConfig();
applicationConfig.setId("springboot-dubbo-provider");
applicationConfig.setName("springboot-dubbo-provider");
return applicationConfig;
}
@Bean
public ProtocolConfig protocolConfig() {
ProtocolConfig protocolConfig = new ProtocolConfig();
protocolConfig.setPort(20880);
protocolConfig.setName("dubbo");
return protocolConfig;
}
@Bean
public RegistryConfig registryConfig() {
RegistryConfig registryConfig = new RegistryConfig();
registryConfig.setAddress("zookeeper://ip1:2181?backup=ip2:2181");
registryConfig.setCheck(false);
return registryConfig;
}
@Bean
public MonitorConfig monitorConfig() {
MonitorConfig monitorConfig = new MonitorConfig();
monitorConfig.setProtocol("regist