怎么单独使用dubbo协议
我用java类调用接口,现在想在中间加一层dubbo协议,请求的东西封装号,然后用dubbo传,最后到具体服务在解析。
ReferenceConfig<GreetingsService> reference = new ReferenceConfig<>();
reference.setApplication(new ApplicationConfig("first-dubbo-consumer"));
RegistryConfig registryConfig = new RegistryConfig("zookeeper://" + zookeeperHost + ":2181");
reference.setRegistry(registryConfig);
reference.setTimeout(1000 * 60);
reference.setInterface(GreetingsService.class);
GreetingsService service = reference.get();
//String message = service.sayHi("dubbo");
Person person = service.getPerson();
估计还得使用dubbo中的直连
现在情况是这样,本来是生产者,消费者,公用api对吧,现在把生产者只剩下配端口和服务名,其他和公用api一起放到一个jar包里,效果就是谁要用dubbo协议谁引这个包,服务在jar包里封好了。(就是简化使用者花的成本,引我的包就可以用dubbo协议提供我的服务,到时候还会给消费者封成一个包,直接引包就能用,包里就没服务了) 现在写成这样不知道有没有用,或者有什么别的好方法 @Configuration @ConditionalOnBean(annotation = EnableDubboConfiguration.class) @AutoConfigureAfter(DubboAutoConfiguration.class) @EnableConfigurationProperties(DubboProperties.class) public class DubboConfiguration extends DubboCommonAutoConfiguration {
@Autowired
private ApplicationContext applicationContext;
@Autowired
private DubboProperties properties;
@Reference
private BexDubboService bexDubboService;
@Bean(value = "bexDubboImpl")
public BexDubboImpl bexDubboImpl() {
return new BexDubboImpl();
}
@Bean
public ServiceBean<BexDubboImpl> bexDubboServiceBean(BexDubboImpl bexDubboService) {
String beanName = bexDubboService.getClass().getName();
Environment environment = applicationContext.getEnvironment();
ServiceBean<BexDubboImpl> serviceBean = new ServiceBean<>();
serviceBean.setInterface(BexDubboImpl.class);
serviceBean.setRef(bexDubboService);
serviceBean.setApplication(this.parseApplication(null, properties, environment,
beanName, "application"));
serviceBean.setModule(
this.parseModule(null, properties, environment, beanName, "module"));
serviceBean.setRegistries(
this.parseRegistries(null, properties, environment, beanName, "registry"));
serviceBean.setProtocols(
this.parseProtocols(new String[]{}, properties, environment, beanName, "registry"));
serviceBean.setMonitor(
this.parseMonitor(null, properties, environment, beanName, "monitor"));
serviceBean.setProvider(
this.parseProvider(null, properties, environment, beanName, "provider"));
return serviceBean;
}
}
------------------ 原始邮件 ------------------ 发件人: "apache/dubbo" <[email protected]>; 发送时间: 2021年2月3日(星期三) 下午4:42 收件人: "apache/dubbo"<[email protected]>; 抄送: "满船清梦压星河"<[email protected]>;"Author"<[email protected]>; 主题: Re: [apache/dubbo] 怎么单独使用dubbo协议 (#7146)
估计还得使用dubbo中的直连
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.
你的意思是说吧实现和 api 放在一个 jar?
对的,别人用了我这个jar包就可以用dubbo协议调用我的服务(生产者部分,消费者那端还要做另一个)。(就别人不需要选择怎么序列化、该扫描哪个包、该怎么配置dubbo,我jar包都做好了提供出去,服务也是我自己的服务,别人也不用管,最后消费者那端用我暴露的接口给个参数就好了)。
------------------ 原始邮件 ------------------ 发件人: "apache/dubbo" <[email protected]>; 发送时间: 2021年2月3日(星期三) 下午5:12 收件人: "apache/dubbo"<[email protected]>; 抄送: "满船清梦压星河"<[email protected]>;"Author"<[email protected]>; 主题: Re: [apache/dubbo] 怎么单独使用dubbo协议 (#7146)
你的意思是说吧实现和 api 放在一个 jar?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.
是不是在Jar包里提供了一个XxService类, 假设这个类中有一个test()方法,别人调用这个test方法,就可以直接使用dubbo协议调用远程对于的XxService服务
我大概明白你的意思了,你现在只是想用 dubbo 封装下调用过程,可以了解下 dubbo 的泛化调用。
用泛化调用,在你的jar包里都不用引入api接口了
我的服务是个java代码,并没有服务器在跑。原来是引用一个jar包,直接http的就能用。我的问题最原始是多协议调用(http、dubbo、rpc),现在我要封个生产者的包a和消费者的包b。A引a,B引b,AB起服务。麻烦老师了
------------------ 原始邮件 ------------------ 发件人: "apache/dubbo" <[email protected]>; 发送时间: 2021年2月3日(星期三) 下午5:21 收件人: "apache/dubbo"<[email protected]>; 抄送: "满船清梦压星河"<[email protected]>;"Author"<[email protected]>; 主题: Re: [apache/dubbo] 怎么单独使用dubbo协议 (#7146)
我大概明白你的意思了,你现在只是想用 dubbo 封装下调用过程,可以了解下 dubbo 的泛化调用。
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.
就是我把配置服务在哪个包,用的协议,序列化类型这些配置从原来服务端配放到服务端引用的jar包里配,这样行吗,因为使用者的代码不能改,只能让他换个包。就达到原来是用http协议,现在变成用dubbo协议
------------------ 原始邮件 ------------------ 发件人: "apache/dubbo" <[email protected]>; 发送时间: 2021年2月3日(星期三) 下午5:26 收件人: "apache/dubbo"<[email protected]>; 抄送: "满船清梦压星河"<[email protected]>;"Author"<[email protected]>; 主题: Re: [apache/dubbo] 怎么单独使用dubbo协议 (#7146)
用泛化调用,在你的jar包里都不用引入api接口了
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.
其实还是不太明白需求,如果只是要切换服务所使用的协议,服务提供者这边完成切换就行了,你要么看看Dubbo的Stub功能,或泛化调用,或Dubbo配置优先级,看能不能帮到你
所有配置都是用 @bean 的方式就可以了,至于参数?可以读取外部的,或者你直接写死在jar?
谢谢老师们
------------------ 原始邮件 ------------------ 发件人: "apache/dubbo" <[email protected]>; 发送时间: 2021年2月3日(星期三) 晚上10:26 收件人: "apache/dubbo"<[email protected]>; 抄送: "满船清梦压星河"<[email protected]>;"Author"<[email protected]>; 主题: Re: [apache/dubbo] 怎么单独使用dubbo协议 (#7146)
所有配置都是用 @bean 的方式就可以了,至于参数?可以读取外部的,或者你直接写死在jar?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.
&READY-TO-CLOSE&