dubbo 多协议的配置和使用

1.配置多协议

@Configuration
public class DubboConfig {

    @NacosValue(value = "${dubbo.protocol.port}",autoRefreshed = true)
    private Integer port;
    @NacosValue(value = "${dubbo.protocol.name}",autoRefreshed = true)
    private String name;

    @NacosValue(value = "${dubbo.port}",autoRefreshed = true)
    private Integer hessianPort;
    @NacosValue(value = "${dubbo.name}",autoRefreshed = true)
    private String hessianName;
    @NacosValue(value = "${dubbo.server}",autoRefreshed = true)
    private String server;
    @NacosValue(value = "${dubbo.accepts}",autoRefreshed = true)
    private Integer accepts;
    @NacosValue(value = "${dubbo.threads}",autoRefreshed = true)
    private Integer threads;


    // 配置dubbo协议
    @Bean("dubbo")
    public ProtocolConfig dubboProtocolConfig() {
        ProtocolConfig protocolConfig = new ProtocolConfig();
        protocolConfig.setName(name);
        protocolConfig.setId(name);
        protocolConfig.setPort(port);
        protocolConfig.setServer(null);
        // 可继续增加其它配置
        return protocolConfig;
    }

    // 配置hessian协议
    @Bean("hessian")
    public ProtocolConfig restProtocolConfig() {
        ProtocolConfig protocolConfig = new ProtocolConfig();
        protocolConfig.setName(hessianName);
        protocolConfig.setId(hessianName);
        protocolConfig.setServer(server);
        protocolConfig.setPort(hessianPort);
        protocolConfig.setAccepts(accepts);
        protocolConfig.setThreads(threads);
        // 可继续增加其它配置
        return protocolConfig;
    }
}

2.注解协议的使用

服务端

@Service(protocol = {"hessian"},timeout = 360000)

客户端

@Reference(protocol = "hessian",timeout = 360000)

你可能感兴趣的:(dubbo,hessian)