Skip to content

Commit 43d4c9c

Browse files
committed
Spring Cloud Hystrix Dashboard仪表盘 & RabbitMQ
1 parent 9aae17b commit 43d4c9c

File tree

25 files changed

+908
-1
lines changed

25 files changed

+908
-1
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.example</groupId>
7+
<artifactId>Eureka-Client</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
<packaging>jar</packaging>
10+
11+
<name>Eureka-Client</name>
12+
<description>Demo project for Spring Boot</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>1.5.13.RELEASE</version>
18+
<relativePath/> <!-- lookup parent from repository -->
19+
</parent>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24+
<java.version>1.8</java.version>
25+
</properties>
26+
27+
<dependencyManagement>
28+
<dependencies>
29+
<dependency>
30+
<groupId>org.springframework.cloud</groupId>
31+
<artifactId>spring-cloud-dependencies</artifactId>
32+
<version>Edgware.SR3</version>
33+
<type>pom</type>
34+
<scope>import</scope>
35+
</dependency>
36+
</dependencies>
37+
</dependencyManagement>
38+
<dependencies>
39+
40+
<dependency>
41+
<groupId>org.springframework.cloud</groupId>
42+
<artifactId>spring-cloud-starter-eureka</artifactId>
43+
</dependency>
44+
<dependency>
45+
<groupId>org.springframework.boot</groupId>
46+
<artifactId>spring-boot-starter</artifactId>
47+
</dependency>
48+
</dependencies>
49+
50+
<build>
51+
<plugins>
52+
<plugin>
53+
<groupId>org.springframework.boot</groupId>
54+
<artifactId>spring-boot-maven-plugin</artifactId>
55+
</plugin>
56+
</plugins>
57+
</build>
58+
59+
60+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.example.demo;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
6+
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
7+
8+
@EnableDiscoveryClient
9+
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
10+
public class DemoApplication {
11+
12+
public static void main(String[] args) {
13+
SpringApplication.run(DemoApplication.class, args);
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.example.demo.controller;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.cloud.client.ServiceInstance;
7+
import org.springframework.cloud.client.discovery.DiscoveryClient;
8+
import org.springframework.web.bind.annotation.GetMapping;
9+
import org.springframework.web.bind.annotation.RestController;
10+
11+
@RestController
12+
public class TestController {
13+
14+
private Logger log = LoggerFactory.getLogger(this.getClass());
15+
16+
@Autowired
17+
private DiscoveryClient client;
18+
19+
@GetMapping("/info")
20+
public String info() {
21+
@SuppressWarnings("deprecation")
22+
ServiceInstance instance = client.getLocalServiceInstance();
23+
String info = "host:" + instance.getHost() + ",service_id:" + instance.getServiceId();
24+
log.info(info);
25+
return info;
26+
}
27+
28+
@GetMapping("/hello")
29+
public String hello() {
30+
return "hello world";
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.example.demo.controller;
2+
3+
import com.example.demo.domain.User;
4+
import org.slf4j.Logger;
5+
import org.slf4j.LoggerFactory;
6+
import org.springframework.web.bind.annotation.*;
7+
8+
import java.util.ArrayList;
9+
import java.util.List;
10+
11+
@RestController
12+
@RequestMapping("user")
13+
public class UserController {
14+
15+
private Logger log = LoggerFactory.getLogger(this.getClass());
16+
17+
@GetMapping("/{id:\\d+}")
18+
public User get(@PathVariable Long id) {
19+
log.info("获取用户id为 " + id + "的信息");
20+
return new User(id, "mrbird", "123456");
21+
}
22+
23+
@GetMapping("users")
24+
public List<User> get(String ids) {
25+
log.info("批量获取用户信息");
26+
List<User> list = new ArrayList<>();
27+
for (String id : ids.split(",")) {
28+
list.add(new User(Long.valueOf(id), "user" + id, "123456"));
29+
}
30+
return list;
31+
}
32+
33+
@GetMapping
34+
public List<User> get() {
35+
List<User> list = new ArrayList<>();
36+
list.add(new User(1L, "mrbird", "123456"));
37+
list.add(new User(2L, "scott", "123456"));
38+
log.info("获取用户信息 " + list);
39+
return list;
40+
}
41+
42+
@PostMapping
43+
public void add(@RequestBody User user) {
44+
log.info("新增用户成功 " + user);
45+
}
46+
47+
@PutMapping
48+
public void update(@RequestBody User user) {
49+
log.info("更新用户成功 " + user);
50+
}
51+
52+
@DeleteMapping("/{id:\\d+}")
53+
public void delete(@PathVariable Long id) {
54+
log.info("删除用户成功 " + id);
55+
}
56+
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.example.demo.domain;
2+
3+
import java.io.Serializable;
4+
5+
public class User implements Serializable {
6+
7+
private static final long serialVersionUID = 1339434510787399891L;
8+
private Long id;
9+
10+
private String username;
11+
12+
private String password;
13+
14+
public User() {
15+
}
16+
17+
public User(Long id, String username, String password) {
18+
this.id = id;
19+
this.username = username;
20+
this.password = password;
21+
}
22+
23+
public Long getId() {
24+
return id;
25+
}
26+
27+
public void setId(Long id) {
28+
this.id = id;
29+
}
30+
31+
public String getUsername() {
32+
return username;
33+
}
34+
35+
public void setUsername(String username) {
36+
this.username = username;
37+
}
38+
39+
public String getPassword() {
40+
return password;
41+
}
42+
43+
public void setPassword(String password) {
44+
this.password = password;
45+
}
46+
47+
@Override
48+
public String toString() {
49+
return "User{" +
50+
"id=" + id +
51+
", username='" + username + '\'' +
52+
", password='" + password + '\'' +
53+
'}';
54+
}
55+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
server:
2+
port: 8082
3+
4+
spring:
5+
application:
6+
name: Server-Provider
7+
8+
eureka:
9+
client:
10+
register-with-eureka: true
11+
fetch-registry: true
12+
serviceUrl:
13+
defaultZone: http://mrbird:123456@peer1:8080/eureka/,http://mrbird:123456@peer2:8081/eureka/
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.example</groupId>
7+
<artifactId>Eureka-Service</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
<packaging>jar</packaging>
10+
11+
<name>Eureka-Service</name>
12+
<description>Demo project for Spring Boot</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>1.5.13.RELEASE</version>
18+
<relativePath/> <!-- lookup parent from repository -->
19+
</parent>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24+
<java.version>1.8</java.version>
25+
</properties>
26+
27+
<dependencyManagement>
28+
<dependencies>
29+
<dependency>
30+
<groupId>org.springframework.cloud</groupId>
31+
<artifactId>spring-cloud-dependencies</artifactId>
32+
<version>Edgware.SR3</version>
33+
<type>pom</type>
34+
<scope>import</scope>
35+
</dependency>
36+
</dependencies>
37+
</dependencyManagement>
38+
39+
<dependencies>
40+
<dependency>
41+
<groupId>org.springframework.cloud</groupId>
42+
<artifactId>spring-cloud-starter-eureka-server</artifactId>
43+
</dependency>
44+
<dependency>
45+
<groupId>org.springframework.boot</groupId>
46+
<artifactId>spring-boot-starter-security</artifactId>
47+
</dependency>
48+
49+
</dependencies>
50+
51+
<repositories>
52+
<repository>
53+
<id>nexus-aliyun</id>
54+
<name>Nexus aliyun</name>
55+
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
56+
</repository>
57+
</repositories>
58+
59+
<build>
60+
<plugins>
61+
<plugin>
62+
<groupId>org.springframework.boot</groupId>
63+
<artifactId>spring-boot-maven-plugin</artifactId>
64+
</plugin>
65+
</plugins>
66+
</build>
67+
68+
69+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.example.demo;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
6+
7+
8+
@EnableEurekaServer
9+
@SpringBootApplication
10+
public class DemoApplication {
11+
public static void main(String[] args) {
12+
SpringApplication.run(DemoApplication.class, args);
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
server:
2+
port: 8080
3+
4+
spring:
5+
application:
6+
name: Eureka-Server
7+
8+
eureka:
9+
instance:
10+
hostname: peer1
11+
client:
12+
serviceUrl:
13+
defaultZone: http://mrbird:123456@peer2:8081/eureka/
14+
server:
15+
enable-self-preservation: false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
server:
2+
port: 8081
3+
4+
spring:
5+
application:
6+
name: Eureka-Server
7+
8+
eureka:
9+
instance:
10+
hostname: peer2
11+
client:
12+
serviceUrl:
13+
defaultZone: http://mrbird:123456@peer1:8080/eureka/
14+
server:
15+
enable-self-preservation: false
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
security:
2+
basic:
3+
enabled: true
4+
user:
5+
name: mrbird
6+
password: 123456
7+
spring:
8+
profiles:
9+
active: peer1

0 commit comments

Comments
 (0)