[bigdata-108] spring-cloud-04 分布式服务的feign消费者
来源:互联网 发布:adobe reader百度软件 编辑:程序博客网 时间:2024/05/17 08:25
1. 本例,以feign模式,建立一个调用分布式服务的web服务。这个服务调用前三个步骤建立起来的分布式服务。
2. 参考文献
https://github.com/dyc87112/SpringCloudBook/tree/master/feign-consumer
3. 源码目录结构
├── pom.xml
├── src
│ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ └── brian
│ │ │ └── demo
│ │ │ └── helloserviceconsumer
│ │ │ ├── App.java
│ │ │ └── HelloService.java
│ │ └── resources
│ │ └── application.properties
4. pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.brian.demo</groupId><artifactId>helloserviceconsumer</artifactId><version>0.0.1-SNAPSHOT</version><packaging>jar</packaging><name>helloserviceconsumer</name><url>http://maven.apache.org</url><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.3.7.RELEASE</version><relativePath /> <!-- lookup parent from repository --></parent><repositories><repository><id>my-nexus-central</id><name>my local nexus</name><url>http://localhost:8081/nexus/content/repositories/central/</url><releases><enabled>true</enabled><updatePolicy>never</updatePolicy></releases></repository></repositories><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-eureka</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-feign</artifactId></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>3.8.1</version><scope>test</scope></dependency></dependencies><dependencyManagement><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>Brixton.SR5</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>
5. App.java
package com.brian.demo.helloserviceconsumer;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.client.discovery.EnableDiscoveryClient;import org.springframework.cloud.netflix.feign.EnableFeignClients;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.bind.annotation.RestController;@RestController@EnableFeignClients@EnableDiscoveryClient@SpringBootApplicationpublic class App {@AutowiredHelloService helloService;@RequestMapping(value = "/feign-consumer", method = RequestMethod.GET)public String helloConsumer() {return helloService.hello();}public static void main(String[] args) {SpringApplication.run(App.class, args);}}
package com.brian.demo.helloserviceconsumer;import org.springframework.cloud.netflix.feign.FeignClient;import org.springframework.web.bind.annotation.RequestMapping;@FeignClient(value = "HELLO-SERVICE")public interface HelloService {@RequestMapping("/hello") String hello();}
7. application.properties
spring.application.name=feign-consumerserver.port=9001eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/,http://localhost:1112/eureka/
mvn clean package
9. 运行
java -jar target/helloserviceconsumer-0.0.1-SNAPSHOT.jar
10. 查看
http://localhost:9001/feign-consumer
能看到这里返回的字符串是前述部署的服务返回的字符串。
阅读全文
0 0
- [bigdata-108] spring-cloud-04 分布式服务的feign消费者
- [bigdata-109] spring-cloud-05 分布式服务的ribbon消费者
- Spring Cloud(五):服务消费者Feign
- Spring Cloud(四)服务提供者 Eureka + 服务消费者 Feign
- Spring Cloud | 第三篇:服务消费者(Feign)
- Spring Cloud 服务消费者
- Spring Cloud Feign客户端无法找到可用的服务。
- Spring Cloud构建微服务架构(三)服务消费者(Feign)
- spring cloud的的服务消费者
- Spring Cloud(Netflix) Feign: 以Dubbo暴露服务的方式使用Feign
- spring cloud feign 调用服务注意问题
- Spring Cloud 声明式服务调用 Feign
- 声明式服务调用:Spring Cloud Feign
- spring cloud Feign(声明式服务调用)
- 【Spring Cloud学习】服务消费者
- Spring Cloud服务提供者与服务消费者怎么运作的?
- spring-cloud-feign集成feign的几个注意事项
- spring cloud-Feign的Hystrix支持
- Android -MediaPlayer 菜鸟心得
- 仿ios底部菜单栏
- 原生js调用json方法
- Android Material Design动画 Animated Vector Drawables|矢量图片动画
- Unity鼠标点击删除Mesh中的三角面
- [bigdata-108] spring-cloud-04 分布式服务的feign消费者
- 怎样用Java编写一个简单的计算器
- 大数据高效复制的处理案例分析总结
- 什么是数据库散列存储?
- 动态规划训练9 [Brackets POJ
- Libev 官方文档学习笔记
- android 调用网络api
- RSSI相关概念
- VPC最佳实践(六):业务如何从经典网络平滑迁移到VPC