Dubbo怎么用
这篇文章主要介绍了Dubbo怎么用,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。
我们提供的服务有:网站设计制作、网站制作、微信公众号开发、网站优化、网站认证、河东ssl等。为数千家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的河东网站制作公司
依赖:
4.0.0 org.springframework.boot spring-boot-starter-parent 2.1.7.RELEASE 1.8 com.example api 1.0 org.apache.dubbo dubbo-spring-boot-starter 2.7.3 org.apache.curator curator-framework 4.2.0 org.apache.curator curator-recipes 4.2.0 org.springframework.boot spring-boot-starter-thymeleaf org.springframework.boot spring-boot-starter-web org.projectlombok lombok true
服务提供方配置
package com.example.order.service; import com.example.api.Order; import com.example.api.OrderService; import org.apache.dubbo.config.annotation.Service; import java.util.Date; @Service public class OrderServiceImpl implements OrderService { @Override public Order getOrder() { Order order = new Order(); order.setId(1L); order.setOrderName("xxx"); order.setCreateTime(new Date()); return order; } }
application.yml
server: port: 4059 tomcat: uri-encoding: UTF-8 servlet: context-path: /order # session: # timeout: 300s dubbo: application: ###########注册到注册中心的名称############ name: ordder ###########采用协议和端口号################ protocol: ###########采用dubbo协议#################### name: dubbo ###########发布dubbo端口号为40591########### port: 40591 registry: ###########注册中心地址##################### address: zookeeper://192.168.0.18:2181 scan: ############实现类扫包范围################### base-packages: com.example.order.service spring: output: ansi: enabled: always
服务消费者
package com.example.user.controller; import com.example.api.OrderService; import org.apache.dubbo.config.annotation.Reference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class UserController { @Reference private OrderService orderService; @RequestMapping("/order") public Object getUser() { return this.orderService.getOrder(); } }
application.yml
server: port: 4058 tomcat: uri-encoding: UTF-8 servlet: context-path: /user # session: # timeout: 300s dubbo: application: ##### 注册服务的名称 name: user ##### 注册中心地址 registry: address: zookeeper://192.168.0.18:2181 ##### 调用服务超时时间 consumer: timeout: 5000 spring: output: ansi: enabled: always
注意项目启用要使用 @EnableDubbo
接口注册要使用: Service
接口引用要使用:Reference
@EnableDubbo
org.apache.dubbo.config.annotation.Service
org.apache.dubbo.config.annotation.Reference
@Configuration @EnableDubbo(scanBasePackages = "org.apache.dubbo.samples.simple.annotation.impl") @PropertySource("classpath:/spring/dubbo-provider.properties") static public class ProviderConfiguration { }
@Configuration @EnableDubbo(scanBasePackages = "org.apache.dubbo.samples.simple.annotation.action") @PropertySource("classpath:/spring/dubbo-consumer.properties") @ComponentScan(value = {"org.apache.dubbo.samples.simple.annotation.action"}) static public class ConsumerConfiguration { }
感谢你能够认真阅读完这篇文章,希望小编分享的“Dubbo怎么用”这篇文章对大家有帮助,同时也希望大家多多支持创新互联,关注创新互联行业资讯频道,更多相关知识等着你来学习!
文章标题:Dubbo怎么用
转载来源:http://myzitong.com/article/ijipge.html