1 Dubbo 配置
dubbo配置xml配置 属性配置 注解配置 api配置
注解配置
服务提供方注解:
import com.alibaba.dubbo.config.annotation.Service; @Service (version= "1.0.0" ) public class FooServiceImpl implements FooService { // ...... } |
服务提供方配置:
<!-- 公共信息,也可以用dubbo.properties配置 --> < dubbo:application name = "annotation-provider" /> < dubbo:registry address = "127.0.0.1:4548" /> <!-- 扫描注解包路径,多个包用逗号分隔,不填pacakge表示扫描当前ApplicationContext中所有的类 --> < dubbo:annotation package = "com.foo.bar.service" /> |
服务消费方注解:
import com.alibaba.dubbo.config.annotation.Reference; import org.springframework.stereotype.Component; @Component public class BarAction { @Reference (version= "1.0.0" ) private FooService fooService; } |
服务消费方配置:
<!-- 公共信息,也可以用dubbo.properties配置 --> < dubbo:application name = "annotation-consumer" /> < dubbo:registry address = "127.0.0.1:4548" /> <!-- 扫描注解包路径,多个包用逗号分隔,不填pacakge表示扫描当前ApplicationContext中所有的类 --> < dubbo:annotation package = "com.foo.bar.action" /> |
也可以使用:(等价于前面的:<dubbo:annotation package="com.foo.bar.service" />)
< dubbo:annotation /> < context:component-scan base-package = "com.foo.bar.service" > < context:include-filter type = "annotation" expression = "com.alibaba.dubbo.config.annotation.Service" /> </ context:component-scan > |
Spring2.5及以后版本支持component-scan,如果用的是Spring2.0及以前版本,需配置:
|
2 功能熟悉
并发控制
限制com.foo.BarService的每个方法,服务器端并发执行(或占用线程池线程数)不能超过10个:
< dubbo:service interface = "com.foo.BarService" executes = "10" /> |
限制com.foo.BarService的sayHello方法,服务器端并发执行(或占用线程池线程数)不能超过10个:
< dubbo:service interface = "com.foo.BarService" > < dubbo:method name = "sayHello" executes = "10" /> </ dubbo:service > |
限制com.foo.BarService的每个方法,每客户端并发执行(或占用连接的请求数)不能超过10个:
< dubbo:service interface = "com.foo.BarService" actives = "10" /> |
Or:
< dubbo:reference interface = "com.foo.BarService" actives = "10" /> |
限制com.foo.BarService的sayHello方法,每客户端并发执行(或占用连接的请求数)不能超过10个:
< dubbo:service interface = "com.foo.BarService" > < dubbo:method name = "sayHello" actives = "10" /> </ dubbo:service > |
Or:
< dubbo:reference interface = "com.foo.BarService" > < dubbo:method name = "sayHello" actives = "10" /> </ dubbo:service > |
如果<dubbo:service>和<dubbo:reference>都配了actives,<dubbo:reference>优先,参见:配置的覆盖策略。
Load Balance均衡:
配置服务的客户端的loadbalance属性为leastactive,此Loadbalance会调用并发数最小的Provider(Consumer端并发数)。
< dubbo:reference interface = "com.foo.BarService" loadbalance = "leastactive" /> |
Or:
< dubbo:service interface = "com.foo.BarService" loadbalance = "leastactive" />
|