springboot 集成dubbo 关键配置:

1.pom

<!--dubbo与zk的组件 start -->
<dependency>
    <groupId>com.alibaba.boot</groupId>
    <artifactId>dubbo-spring-boot-starter</artifactId>
    <version>0.1.0</version>
</dependency>
<dependency>
    <groupId>com.github.sgroschupf</groupId>
    <artifactId>zkclient</artifactId>
    <version>0.1</version>
</dependency>
<!--dubbo与zk的组件 end -->

2.yml

dubbo:
  application:
    name: your-service-name
  registry:
    address: zookeeper://127.0.0.1:2181
    timeout: '20000'
  protocol:
    name: dubbo
    port: '-1'
  monitor:
    protocol: registry
  consumer:
    check: false

 3.config:

import com.alibaba.dubbo.config.ConsumerConfig;
import com.alibaba.dubbo.config.ProviderConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DubboConfig {
    @Bean
    public ConsumerConfig consumerConfig() {
        ConsumerConfig consumerConfig = new ConsumerConfig();
        consumerConfig.setCheck(false);
        consumerConfig.setTimeout(5000);
        return consumerConfig;
    }

    @Bean
    public ProviderConfig providerConfig(){
        ProviderConfig providerConfig = new ProviderConfig();
        providerConfig.setTimeout(30000);
        providerConfig.setRetries(0);
        return providerConfig;
    }
}

 4.主启动类注解:

@EnableDubbo
@SpringBootApplication
public class WarehousingMain {
    public static void main(String[] args) {
        SpringApplication.run(WarehousingMain.class,args);
    }
}

 

posted @ 2023-11-16 18:08  jiafeng  阅读(39)  评论(0编辑  收藏  举报