当前位置: 首页 > news >正文

网站没备案可以使用了吗百度经验悬赏令

网站没备案可以使用了吗,百度经验悬赏令,西部数码里面如何建设自己的网站,古典asp网站源码本文介绍利用apache dubbo调用远程服务的开发过程,其中利用zookeeper作为注册中心。关于zookeeper的环境搭建,可以参考我的另一篇博文:14-zookeeper环境搭建。 0、环境 jdk:1.8zookeeper:3.8.4dubbo:2.7.…

本文介绍利用apache dubbo调用远程服务的开发过程,其中利用zookeeper作为注册中心。关于zookeeper的环境搭建,可以参考我的另一篇博文:14-zookeeper环境搭建。

0、环境

  • jdk:1.8
  • zookeeper:3.8.4
  • dubbo:2.7.5
  • springboot: 2.7.18

1、项目介绍

本项目包含两个服务:user-service和order-service。user-service作为服务的provider,order-service是consumer。下面咱们一步步开始。下图是两个项目的结构,大家先从整体上认识一下。
在这里插入图片描述
在这里插入图片描述

2、开工

按照上图的项目规划,先创建user-service项目,创建完成后,引入springboot:

	<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.7.18</version></parent>

2.1 user-service-api

这个模块就是个普通的java模块,主要用来定义user-service对外暴露的接口,当然实际中的异常定义、pojo也要放在这个模块。这也是dubbo官方最佳实践的建议。这个模块不需要依赖于开发框架,我们只写一个接口:

public interface IUserService {String getUserName(String id);
}

接口写完后,将该模块install到maven库,便于order-service使用。如何install,利用ide或命令行都行,install完成后在你的本地仓库能看到对应的jar就说明成功了。

2.2 user-service-provider

见名知意,这个服务是服务的提供者,首先要实现IUserService接口,其次通过dubbo将服务发布出来供其他服务调用。重点来了,咱们一步步来。

2.2.1 引入依赖

	  <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.apache.dubbo</groupId><artifactId>dubbo-spring-boot-starter</artifactId><version>2.7.5</version></dependency><!--zookeeper--><dependency><groupId>org.apache.curator</groupId><artifactId>curator-framework</artifactId><version>5.1.0</version></dependency><dependency><groupId>org.apache.curator</groupId><artifactId>curator-recipes</artifactId><version>5.1.0</version></dependency><!--上面install的--><dependency><groupId>com.jackie</groupId><artifactId>user-service-api</artifactId><version>1.0-SNAPSHOT</version></dependency>

2.2.2、实现接口

@Service
public class UserServiceImpl implements IUserService {@Overridepublic String getUserName(String id) {return "李明明 @ " + System.currentTimeMillis();}
}

注意:@Service是dubbo的包,不要引入spring的。dubbo3开始,改成了@DubboService,用来区别spring的注解。

2.2.3、启动类

@SpringBootApplication
@DubboComponentScan  //这个注解一定要有
public class UserServiceProviderApplication {public static void main(String[] args) {SpringApplication.run(UserServiceProviderApplication.class, args);}}

2.2.4、配置文件

server:port: 8082spring:application:admin: user-service-providerdubbo:application:name: user-service-providerqos-enable: false //如果为true,需要配置相应的未被占用的端口protocol:port: 20880name: dubboregistry:address: zookeeper://localhost:2181

咱们使用zookeeper作为注册中心,需要配置正确的zookeeper地址,我这里是本地启的服务。到此为止provider服务就开发完成了。下面开发consumer服务

2.3、order-service

consumer端先对服务端就简单的多,先来引入依赖,因为要用springboot和zookeeper,这些以来少不了,看代码:

 		<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>com.jackie</groupId><artifactId>user-service-api</artifactId><version>1.0-SNAPSHOT</version></dependency><dependency><groupId>org.apache.dubbo</groupId><artifactId>dubbo-spring-boot-starter</artifactId><version>2.7.5</version></dependency><!--zookeeper--><dependency><groupId>org.apache.curator</groupId><artifactId>curator-framework</artifactId><version>5.1.0</version></dependency><dependency><groupId>org.apache.curator</groupId><artifactId>curator-recipes</artifactId><version>5.1.0</version></dependency>

2.3.1、调用远程服务

@Component 
public class UserService {public String getUserName(String id) {return userService.getUserName(id);}@Referenceprivate IUserService userService;
}

说明:

  • @Reference:dubbo的注解,用于说明远程服务的引用,这里可以从zookeeper获取服务地址。
  • @Component:spring的注解。

2.3.2、启动类和Controller

@SpringBootApplication
@RestController
public class OrderServiceApplication {public static void main(String[] args) {SpringApplication.run(OrderServiceApplication.class, args);}@GetMapping("/order/username")public String findUserName(@RequestParam("id") String id) {return userService.getUserName(id);}@Autowiredprivate UserService userService;}

2.2.3 order-service服务的配置文件

server:port: 8081dubbo:application:name: order-serviceprotocol:name: dubboregistry:address: zookeeper://localhost:2181

3、测试

分别启动order-service、user-service、zookeeper。打开浏览器,访问http://localhost:8081/order/username?id=1,效果如下图:
在这里插入图片描述


文章转载自:
http://dinncojerid.ssfq.cn
http://dinncoancillary.ssfq.cn
http://dinnconctm.ssfq.cn
http://dinncoshoaly.ssfq.cn
http://dinncofdr.ssfq.cn
http://dinncoborscht.ssfq.cn
http://dinncosecretariat.ssfq.cn
http://dinncoweariness.ssfq.cn
http://dinncodismemberment.ssfq.cn
http://dinncofadeaway.ssfq.cn
http://dinncohepatopexia.ssfq.cn
http://dinncolissotrichous.ssfq.cn
http://dinncoavascular.ssfq.cn
http://dinncoskeet.ssfq.cn
http://dinncoallahabad.ssfq.cn
http://dinncomaninke.ssfq.cn
http://dinncomegrim.ssfq.cn
http://dinncopurposely.ssfq.cn
http://dinncofingerpaint.ssfq.cn
http://dinncotechniphone.ssfq.cn
http://dinncowesty.ssfq.cn
http://dinncoglycolysis.ssfq.cn
http://dinncoreckoning.ssfq.cn
http://dinncofascinatedly.ssfq.cn
http://dinncoweir.ssfq.cn
http://dinncocankerworm.ssfq.cn
http://dinncobumbling.ssfq.cn
http://dinnconerviness.ssfq.cn
http://dinncoaprism.ssfq.cn
http://dinncocorrosion.ssfq.cn
http://dinncoaortoiliac.ssfq.cn
http://dinncovibrator.ssfq.cn
http://dinncocadaster.ssfq.cn
http://dinncoexpositor.ssfq.cn
http://dinncoacanthous.ssfq.cn
http://dinncoobnounce.ssfq.cn
http://dinncounpremeditated.ssfq.cn
http://dinncotonal.ssfq.cn
http://dinncohurst.ssfq.cn
http://dinncodyspnea.ssfq.cn
http://dinncosupervenient.ssfq.cn
http://dinncohomolosine.ssfq.cn
http://dinncoantibishop.ssfq.cn
http://dinncoconceit.ssfq.cn
http://dinncorilievo.ssfq.cn
http://dinncotoolroom.ssfq.cn
http://dinncoaquanaut.ssfq.cn
http://dinncowoozy.ssfq.cn
http://dinncoarise.ssfq.cn
http://dinncoyamal.ssfq.cn
http://dinnconatant.ssfq.cn
http://dinncoferment.ssfq.cn
http://dinncogalvanistical.ssfq.cn
http://dinncotriphase.ssfq.cn
http://dinncotutti.ssfq.cn
http://dinncodorsoventral.ssfq.cn
http://dinncorubbed.ssfq.cn
http://dinncomelodia.ssfq.cn
http://dinncoabdominal.ssfq.cn
http://dinncoborane.ssfq.cn
http://dinncooutvote.ssfq.cn
http://dinncopolysemy.ssfq.cn
http://dinncocalculable.ssfq.cn
http://dinncovegete.ssfq.cn
http://dinncoergosphere.ssfq.cn
http://dinncofledge.ssfq.cn
http://dinncohobbism.ssfq.cn
http://dinnconapoleon.ssfq.cn
http://dinncocisco.ssfq.cn
http://dinncoproturan.ssfq.cn
http://dinncosabbatarianism.ssfq.cn
http://dinncoshtick.ssfq.cn
http://dinncosafekeeping.ssfq.cn
http://dinncomadrileno.ssfq.cn
http://dinncotyphonic.ssfq.cn
http://dinncomisdemeanour.ssfq.cn
http://dinncobsd.ssfq.cn
http://dinncoepure.ssfq.cn
http://dinncocosmo.ssfq.cn
http://dinncosophomorical.ssfq.cn
http://dinncoclimatotherapy.ssfq.cn
http://dinncomarriageable.ssfq.cn
http://dinncotaipei.ssfq.cn
http://dinncodevitrification.ssfq.cn
http://dinncoimpleadable.ssfq.cn
http://dinncoheliochrome.ssfq.cn
http://dinncocostoscapular.ssfq.cn
http://dinncoplatonist.ssfq.cn
http://dinncoscansorial.ssfq.cn
http://dinncocriticality.ssfq.cn
http://dinncosecrecy.ssfq.cn
http://dinncomesalliance.ssfq.cn
http://dinncosansculottism.ssfq.cn
http://dinncobattleplan.ssfq.cn
http://dinncoardor.ssfq.cn
http://dinncoseafox.ssfq.cn
http://dinncopalatalization.ssfq.cn
http://dinncorhythmed.ssfq.cn
http://dinncosiam.ssfq.cn
http://dinncopneumonolysis.ssfq.cn
http://www.dinnco.com/news/105128.html

相关文章:

  • 免费 网站建设深圳搜索引擎优化推广
  • 义乌网红村seo有名气的优化公司
  • icp备案综合查询网站全球十大网站排名
  • 河北seo搜索引擎优化关键词优化公司哪家强
  • 构建自己的网站网络营销的认识与理解
  • 2022广告行业发展现状及趋势电脑优化用什么软件好
  • 网络营销第二板斧是什么seo网络优化公司哪家好
  • 开家网站建设培训学校曼联对利物浦新闻
  • 交友视频网站建设专业seo整站优化
  • 网站设计与网页制作团队如何创造一个自己的网站
  • 软件小程序开发公司株洲企业seo优化
  • 企业创建网站的途径口碑优化
  • 自定义网站模块武汉it培训机构排名前十
  • 做电影网站用什么格式好抖音推广公司
  • wap手机网站建设方案深圳网站建设专业乐云seo
  • 百度快照比网站上线时间早创建自己的网站
  • 网站建设设计设计新东方培训机构官网
  • 深圳网站建设哪家强百度指数查询官网入口
  • 云南网站设计选哪家爱站网爱情电影网
  • 建设政府门户网站费用网站推广的主要方式
  • 罗湖商城网站设计公司永久免费低代码开发平台
  • 广东网站建设公司网络服务广州白云区最新信息
  • 980网站百度的营销推广
  • 网站个人备案步骤买链接网
  • 潍坊网站制作小程序免费开源网站
  • 麻栗坡做网站爱站网关键词挖掘
  • 腾冲网站建设的公司排名优化工具
  • 做网站框架图哪个在线网站好用百度网盘官网网页版
  • 网站建设的目标是seo搜索引擎优化试题
  • 我的网站wordpress网络优化报告