1. 消费方调用所有服务提供方的配置
<dubbo:serviceinterface="operatingPlatform.DispatchServer" ref="DispatchServerImpl"executes="20" cluster="broadcast"/>
--注意红色部分,这个配置说明是广播模式调用服务提供方,在这种配置情况下,所有注册到注册中心的服务提供方都会收到客户端的调用命令,这个调用过程是一个接一个直到所有服务提供方都调用成功。对于这种模式而言,返回值只有其中一个服务提供方的返回值而非是所有服务提供方的服务方法的所有返回值。
2.异步调用以及强制远程调用配置
<dubbo:reference id="DispatchServer" interface="operatingPlatform.DispatchServer" async="true" scope="remote"/>
--注意红色部分,async="true"说明消费端调用服务提供方时是异步调用,不阻塞等待返回值。scope="remote"这个配置比较少用,只有当我们服务提供方的服务方法要作为客户端递归调用自身服务时才可能需要用到,简单来说就是dubbo默认优先调用自身JVM上的本地方法,而非远程方法。如果一定要调用远程方法则需要设置该配置。
3.如何在代码中获取和修改dubbo的xml文件配置信息
providerContext = new ClassPathXmlApplicationContext(providerConfigLocation);
Map<String, ProtocolConfig> beansOfType =providerContext.getBeansOfType(ProtocolConfig.class);
for(Entry<String, ProtocolConfig> item : beansOfType.entrySet()) {
System.out.println("端口号:"+item.getValue().getPort());
item.getValue().setPort(20880);
}
--第一行是通过加载配置文件,获得所有spring配置项的容器对象(不仅仅是dubbo的配置,dubbo的配置只是作为所有spring配置中扩展性的一部分)
第二行就是,通过spring配置容易获取dubbo的Protocol层的配置信息,并存放在容器Map<String, ProtocolConfig> beansOfType中。如果需要获取其他层面的配置信息,则修改getBeansOfType方法中的参数即可,比如ApplicationConfig,ArgumentConfig,ConsumerConfig,MethodConfig,ProviderConfig,ReferenceConfig,RegistryConfig,ServiceConfig等。
beansOfType中的key值为“dubbo”。
第三行就是通过beansOfType容器的接口去获取或则设置xml文件中相关的配置项。
注意:通过实践发现,设置后的配置项并没有生效,只是个很让人困惑的问题。