java -jar zipkin-server-
2.10
.
1
-exec.jar
|
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
|
<
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
>
<
parent
>
<
groupId
>cn.how2j.springcloud</
groupId
>
<
artifactId
>springcloud</
artifactId
>
<
version
>0.0.1-SNAPSHOT</
version
>
</
parent
>
<
artifactId
>product-data-service</
artifactId
>
<
dependencies
>
<
dependency
>
<
groupId
>org.springframework.cloud</
groupId
>
<
artifactId
>spring-cloud-starter-netflix-eureka-client</
artifactId
>
</
dependency
>
<
dependency
>
<
groupId
>org.springframework.boot</
groupId
>
<
artifactId
>spring-boot-starter-web</
artifactId
>
</
dependency
>
<
dependency
>
<
groupId
>org.springframework.cloud</
groupId
>
<
artifactId
>spring-cloud-starter-zipkin</
artifactId
>
</
dependency
>
</
dependencies
>
</
project
>
|
<
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
>
<
parent
>
<
groupId
>cn.how2j.springcloud</
groupId
>
<
artifactId
>springcloud</
artifactId
>
<
version
>0.0.1-SNAPSHOT</
version
>
</
parent
>
<
artifactId
>product-view-service-feign</
artifactId
>
<
dependencies
>
<
dependency
>
<
groupId
>org.springframework.cloud</
groupId
>
<
artifactId
>spring-cloud-starter-netflix-eureka-client</
artifactId
>
</
dependency
>
<
dependency
>
<
groupId
>org.springframework.cloud</
groupId
>
<
artifactId
>spring-cloud-starter-openfeign</
artifactId
>
</
dependency
>
<
dependency
>
<
groupId
>org.springframework.boot</
groupId
>
<
artifactId
>spring-boot-starter-web</
artifactId
>
</
dependency
>
<
dependency
>
<
groupId
>org.springframework.boot</
groupId
>
<
artifactId
>spring-boot-starter-thymeleaf</
artifactId
>
</
dependency
>
<
dependency
>
<
groupId
>org.springframework.cloud</
groupId
>
<
artifactId
>spring-cloud-starter-zipkin</
artifactId
>
</
dependency
>
</
dependencies
>
</
project
>
|
spring:
zipkin:
base-url: http:
//localhost:9411
|
# server:
# port: 由於會啓動多個 product-data-service, 因此端口號由用戶自動設置,推薦 8001,8002,8003
spring:
application:
name: product-data-service
zipkin:
base-url: http://localhost:9411
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
|
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
spring:
application:
name: product-view-service-feign
zipkin:
base-url: http://localhost:9411
thymeleaf:
cache: false
prefix: classpath:/templates/
suffix: .html
encoding: UTF-8
content-type: text/html
mode: HTML5
|
@Bean
public
Sampler defaultSampler() {
return
Sampler.ALWAYS_SAMPLE;
}
|
package
cn.how2j.springcloud;
import
java.util.Scanner;
import
java.util.concurrent.ExecutionException;
import
java.util.concurrent.Future;
import
java.util.concurrent.TimeUnit;
import
java.util.concurrent.TimeoutException;
import
org.springframework.boot.autoconfigure.SpringBootApplication;
import
org.springframework.boot.builder.SpringApplicationBuilder;
import
org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import
org.springframework.context.annotation.Bean;
import
brave.sampler.Sampler;
import
cn.hutool.core.convert.Convert;
import
cn.hutool.core.thread.ThreadUtil;
import
cn.hutool.core.util.NetUtil;
import
cn.hutool.core.util.NumberUtil;
@SpringBootApplication
@EnableEurekaClient
public
class
ProductDataServiceApplication {
public
static
void
main(String[] args) {
int
port =
0
;
int
defaultPort =
8001
;
Future<Integer> future = ThreadUtil.execAsync(() ->{
int
p =
0
;
System.out.println(
"請於5秒鐘內輸入端口號, 推薦 8001 、 8002 或者 8003,超過5秒將默認使用 "
+ defaultPort);
Scanner scanner =
new
Scanner(System.in);
while
(
true
) {
String strPort = scanner.nextLine();
if
(!NumberUtil.isInteger(strPort)) {
System.err.println(
"只能是數字"
);
continue
;
}
else
{
p = Convert.toInt(strPort);
scanner.close();
break
;
}
}
return
p;
});
try
{
port=future.get(
5
,TimeUnit.SECONDS);
}
catch
(InterruptedException | ExecutionException | TimeoutException e){
port = defaultPort;
}
if
(!NetUtil.isUsableLocalPort(port)) {
System.err.printf(
"端口%d被佔用了,沒法啓動%n"
, port );
System.exit(
1
);
}
new
SpringApplicationBuilder(ProductDataServiceApplication.
class
).properties(
"server.port="
+ port).run(args);
}
@Bean
public
Sampler defaultSampler() {
return
Sampler.ALWAYS_SAMPLE;
}
}
|
package
cn.how2j.springcloud;
import
java.util.Scanner;
import
java.util.concurrent.ExecutionException;
import
java.util.concurrent.Future;
import
java.util.concurrent.TimeUnit;
import
java.util.concurrent.TimeoutException;
import
org.springframework.boot.autoconfigure.SpringBootApplication;
import
org.springframework.boot.builder.SpringApplicationBuilder;
import
org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import
org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import
org.springframework.cloud.openfeign.EnableFeignClients;
import
org.springframework.context.annotation.Bean;
import
brave.sampler.Sampler;
import
cn.hutool.core.convert.Convert;
import
cn.hutool.core.thread.ThreadUtil;
import
cn.hutool.core.util.NetUtil;
import
cn.hutool.core.util.NumberUtil;
@SpringBootApplication
@EnableEurekaClient
@EnableDiscoveryClient
@EnableFeignClients
public
class
ProductViewServiceFeignApplication {
public
static
void
main(String[] args) {
int
port =
0
;
int
defaultPort =
8012
;
Future<Integer> future = ThreadUtil.execAsync(() ->{
int
p =
0
;
System.out.println(
"請於5秒鐘內輸入端口號, 推薦 8012 、 8013 或者 8014,超過5秒將默認使用"
+defaultPort);
Scanner scanner =
new
Scanner(System.in);
while
(
true
) {
String strPort = scanner.nextLine();
if
(!NumberUtil.isInteger(strPort)) {
System.err.println(
"只能是數字"
);
continue
;
}
else
{
p = Convert.toInt(strPort);
scanner.close();
break
;
}
}
return
p;
});
try
{
port=future.get(
5
,TimeUnit.SECONDS);
}
catch
(InterruptedException | ExecutionException | TimeoutException e){
port = defaultPort;
}
if
(!NetUtil.isUsableLocalPort(port)) {
System.err.printf(
"端口%d被佔用了,沒法啓動%n"
, port );
System.exit(
1
);
}
new
SpringApplicationBuilder(ProductViewServiceFeignApplication.
class
).properties(
"server.port="
+ port).run(args);
}
@Bean
public
Sampler defaultSampler() {
return
Sampler.ALWAYS_SAMPLE;
}
}
|