硬編碼發送dubbo請求

獲取dubbo註冊地址

1.獲取ApplicationContext

ApplicationContext context = ServiceBean.getSpringContext();

2.加載RegistryConfig

RegistryConfig registryConfig = (RegistryConfig) context.getBean("elZookeeper");

3.獲取zkUrl

zkUrl = registryConfig.getAddress();

4.獲取service

public IService getIService() {
        if(StringUtils.isEmpty(zkUrl)){
            return null;
        }else {
            ApplicationConfig application = new ApplicationConfig();
            application.setName("dubbo.xxx");
            RegistryConfig registry = new RegistryConfig();
            registry.setProtocol("zookeeper");
            registry.setAddress(zkUrl);

            ReferenceConfig<IService> rc = new ReferenceConfig<IService>();
            rc.setApplication(application);
            rc.setRegistry(registry);
            rc.setInterface(IService.class.getName());
            rc.setVersion("2.6");
            rc.setGroup("conf-soa");
            rc.setProtocol("dubbo");
            rc.setTimeout(1000);

            return rc.get();
        }
    }

5.大搞成功
有了service,盡情調用吧!!

getIService().save(domain);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章