Browse Source

sc consumer

master
yasaka 7 years ago
parent
commit
026668f393
  1. 27
      sc-consumer/.gitignore
  2. 45
      sc-consumer/build.gradle
  3. 27
      sc-consumer/src/main/java/com/trgis/sb2sc/Sb2scConsumerApplication.java
  4. 25
      sc-consumer/src/main/java/com/trgis/sb2sc/controller/FeignController.java
  5. 25
      sc-consumer/src/main/java/com/trgis/sb2sc/controller/RibbonController.java
  6. 0
      sc-consumer/src/main/resources/application.yml
  7. 22
      sc-consumer/src/main/resources/bootstrap.yml
  8. 16
      sc-consumer/src/test/java/com/trgis/sb2sc/Sb2scApplicationTests.java
  9. 7
      sc-provider/src/main/java/com/trgis/sb2sc/controller/IndexController.java
  10. 2
      settings.gradle

27
sc-consumer/.gitignore

@ -0,0 +1,27 @@
.gradle
/build/
!gradle/wrapper/gradle-wrapper.jar
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
/out/
### NetBeans ###
/nbproject/private/
/build/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

45
sc-consumer/build.gradle

@ -0,0 +1,45 @@
buildscript {
ext {
springBootVersion = '2.0.3.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'com.trgis'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
ext {
springCloudVersion = 'Finchley.RELEASE'
}
dependencies {
compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-client')
compile('org.springframework.cloud:spring-cloud-starter-config')
compile('org.springframework.boot:spring-boot-starter-webflux')
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.cloud:spring-cloud-starter-openfeign')
compile('org.springframework.cloud:spring-cloud-starter-netflix-hystrix')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}

27
sc-consumer/src/main/java/com/trgis/sb2sc/Sb2scConsumerApplication.java

@ -0,0 +1,27 @@
package com.trgis.sb2sc;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
@EnableDiscoveryClient
@SpringBootApplication
public class Sb2scConsumerApplication {
@Autowired
private RestTemplateBuilder builder;
@Bean
@LoadBalanced
public RestTemplate restTemplate() {
return builder.build();
}
public static void main(String[] args) {
SpringApplication.run(Sb2scConsumerApplication.class, args);
}
}

25
sc-consumer/src/main/java/com/trgis/sb2sc/controller/FeignController.java

@ -0,0 +1,25 @@
package com.trgis.sb2sc.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import reactor.core.publisher.Mono;
@RestController
public class FeignController {
@Autowired
private RestTemplate restTemplate;
@Autowired
private LoadBalancerClient loadBalancerClient;
@GetMapping("/feign/{wd}")
public Mono<String> sayHelloWorld(@PathVariable("wd") String parm) {
String res = this.restTemplate.getForObject("http://sc-provider/test/" + parm, String.class);
return Mono.just(res);
}
}

25
sc-consumer/src/main/java/com/trgis/sb2sc/controller/RibbonController.java

@ -0,0 +1,25 @@
package com.trgis.sb2sc.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import reactor.core.publisher.Mono;
@RestController
public class RibbonController {
@Autowired
private RestTemplate restTemplate;
@Autowired
private LoadBalancerClient loadBalancerClient;
@GetMapping("/ribbon/{wd}")
public Mono<String> sayHelloWorld(@PathVariable("wd") String parm) {
String res = this.restTemplate.getForObject("http://sc-provider/test/" + parm, String.class);
return Mono.just(res);
}
}

0
sc-consumer/src/main/resources/application.yml

22
sc-consumer/src/main/resources/bootstrap.yml

@ -0,0 +1,22 @@
eureka:
client:
service-url:
defaultZone: http://root:booszy@localhost:8761/eureka/
instance:
prefer-ip-address: true
instance-id: ${spring.application.name}:${spring.application.instance_id:${server.port}}
appname: sc-consumer
spring:
application:
name: sc-consumer
cloud:
config:
discovery:
enabled: true
service-id: springcloud-config-server
fail-fast: true
username: root
password: booszy
profile: csdn

16
sc-consumer/src/test/java/com/trgis/sb2sc/Sb2scApplicationTests.java

@ -0,0 +1,16 @@
package com.trgis.sb2sc;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class Sb2scApplicationTests {
@Test
public void contextLoads() {
}
}

7
sc-provider/src/main/java/com/trgis/sb2sc/controller/IndexController.java

@ -1,14 +1,15 @@
package com.trgis.sb2sc.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;
@RestController
public class IndexController {
@GetMapping("/helloworld")
public Mono<String> sayHelloWorld() {
return Mono.just("Hello World SC");
@GetMapping("/test/{msg}")
public Mono<String> sayHelloWorld(@PathVariable("msg") String msg) {
return Mono.just("sc-provider receive : " +msg);
}
}

2
settings.gradle

@ -1,2 +1,2 @@
rootProject.name = 'sb2sc'
include('sc-eureka','sc-config','sc-provider')
include('sc-eureka','sc-config','sc-provider','sc-consumer')
Loading…
Cancel
Save