-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add examples (Service-Consumer--- RPC ->> Service-Provider)
- Loading branch information
Showing
12 changed files
with
214 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
plugins { | ||
application | ||
} | ||
|
||
java { | ||
toolchain { | ||
languageVersion.set(JavaLanguageVersion.of(8)) | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation(project(":examples:cosky-service-provider-api")) | ||
|
||
implementation(platform(project(":cosky-dependencies"))) | ||
implementation("io.springfox:springfox-boot-starter") | ||
implementation("org.springframework.boot:spring-boot-starter-actuator") | ||
implementation(project(":spring-cloud-starter-cosky-config")) | ||
implementation(project(":spring-cloud-starter-cosky-discovery")) | ||
implementation("com.google.guava:guava") | ||
implementation("org.springframework.cloud:spring-cloud-starter-loadbalancer") | ||
implementation("org.springframework.cloud:spring-cloud-starter-openfeign") | ||
compileOnly("org.projectlombok:lombok:${rootProject.ext.get("lombokVersion")}") | ||
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor:${rootProject.ext.get("springBootVersion")}") | ||
annotationProcessor("org.projectlombok:lombok:${rootProject.ext.get("lombokVersion")}") | ||
testImplementation("org.springframework.boot:spring-boot-starter-test") | ||
} | ||
|
||
tasks.withType<Test> { | ||
useJUnitPlatform() | ||
} |
37 changes: 37 additions & 0 deletions
37
...ervice-consumer/src/main/java/me/ahoo/cosky/examples/service/consumer/ConsumerServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package me.ahoo.cosky.examples.service.consumer; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import lombok.var; | ||
import me.ahoo.cosky.examples.service.provider.client.HelloClient; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.CommandLineRunner; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.cloud.openfeign.EnableFeignClients; | ||
|
||
/** | ||
* @author ahoo wang | ||
*/ | ||
@Slf4j | ||
@SpringBootApplication | ||
@EnableFeignClients(basePackages = {"me.ahoo.cosky.examples.service.provider.client"}) | ||
public class ConsumerServer implements CommandLineRunner { | ||
public static void main(String[] args) { | ||
SpringApplication.run(ConsumerServer.class, args); | ||
} | ||
|
||
@Autowired | ||
private HelloClient helloClient; | ||
|
||
/** | ||
* Callback used to run the bean. | ||
* | ||
* @param args incoming main method arguments | ||
* @throws Exception on error | ||
*/ | ||
@Override | ||
public void run(String... args) throws Exception { | ||
var rpcResponse = helloClient.hi("consumer"); | ||
log.warn(rpcResponse); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
examples/cosky-service-consumer/src/main/resources/bootstrap.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
spring: | ||
application: | ||
name: ${service.name:example-consumer} | ||
cloud: | ||
cosky: | ||
namespace: ${cosky.namespace:{dev}} | ||
config: | ||
config-id: ${spring.application.name}.yaml | ||
redis: | ||
mode: ${cosky.redis.mode:standalone} | ||
url: ${cosky.redis.uri:redis://localhost:6379} | ||
logging: | ||
file: | ||
name: logs/${spring.application.name}.log | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
plugins { | ||
`java-library` | ||
} | ||
|
||
dependencies { | ||
api("org.springframework.cloud:spring-cloud-openfeign-core") | ||
} |
9 changes: 9 additions & 0 deletions
9
...service-provider-api/src/main/java/me/ahoo/cosky/examples/service/provider/Constants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package me.ahoo.cosky.examples.service.provider; | ||
|
||
/** | ||
* @author ahoo wang | ||
*/ | ||
public final class Constants { | ||
public static final String SERVICE_NAME = "example-provider"; | ||
public static final String SERVICE_NAME_PREFIX = SERVICE_NAME + "."; | ||
} |
15 changes: 15 additions & 0 deletions
15
...vice-provider-api/src/main/java/me/ahoo/cosky/examples/service/provider/api/HelloApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package me.ahoo.cosky.examples.service.provider.api; | ||
|
||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
|
||
/** | ||
* @author ahoo wang | ||
*/ | ||
public interface HelloApi { | ||
String PATH = "hello"; | ||
|
||
@GetMapping("hi/{name}") | ||
String hi(@PathVariable("name") String name); | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
...rovider-api/src/main/java/me/ahoo/cosky/examples/service/provider/client/HelloClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package me.ahoo.cosky.examples.service.provider.client; | ||
|
||
import me.ahoo.cosky.examples.service.provider.Constants; | ||
import me.ahoo.cosky.examples.service.provider.api.HelloApi; | ||
import org.springframework.cloud.openfeign.FeignClient; | ||
|
||
/** | ||
* @author ahoo wang | ||
*/ | ||
@FeignClient(name = Constants.SERVICE_NAME, contextId = Constants.SERVICE_NAME_PREFIX + "HelloClient", path = HelloApi.PATH) | ||
public interface HelloClient extends HelloApi { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
plugins { | ||
application | ||
} | ||
|
||
java { | ||
toolchain { | ||
languageVersion.set(JavaLanguageVersion.of(8)) | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation(project(":examples:cosky-service-provider-api")) | ||
|
||
implementation(platform(project(":cosky-dependencies"))) | ||
implementation("io.springfox:springfox-boot-starter") | ||
implementation("org.springframework.boot:spring-boot-starter-actuator") | ||
implementation(project(":spring-cloud-starter-cosky-config")) | ||
implementation(project(":spring-cloud-starter-cosky-discovery")) | ||
implementation("com.google.guava:guava") | ||
implementation("org.springframework.boot:spring-boot-starter-web") | ||
implementation("org.springframework.cloud:spring-cloud-starter-openfeign") | ||
compileOnly("org.projectlombok:lombok:${rootProject.ext.get("lombokVersion")}") | ||
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor:${rootProject.ext.get("springBootVersion")}") | ||
annotationProcessor("org.projectlombok:lombok:${rootProject.ext.get("lombokVersion")}") | ||
testImplementation("org.springframework.boot:spring-boot-starter-test") | ||
} | ||
|
||
tasks.withType<Test> { | ||
useJUnitPlatform() | ||
} |
14 changes: 14 additions & 0 deletions
14
...ervice-provider/src/main/java/me/ahoo/cosky/examples/service/provider/ProviderServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package me.ahoo.cosky.examples.service.provider; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
/** | ||
* @author ahoo wang | ||
*/ | ||
@SpringBootApplication | ||
public class ProviderServer { | ||
public static void main(String[] args) { | ||
SpringApplication.run(ProviderServer.class, args); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...der/src/main/java/me/ahoo/cosky/examples/service/provider/controller/HelloController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package me.ahoo.cosky.examples.service.provider.controller; | ||
|
||
import me.ahoo.cosky.examples.service.provider.api.HelloApi; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
/** | ||
* @author ahoo wang | ||
*/ | ||
@RestController | ||
@RequestMapping(HelloApi.PATH) | ||
public class HelloController implements HelloApi { | ||
|
||
@Override | ||
public String hi(String name) { | ||
return "hello " + name; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
examples/cosky-service-provider/src/main/resources/bootstrap.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
server: | ||
port: 8099 | ||
spring: | ||
application: | ||
name: ${service.name:example-provider} | ||
cloud: | ||
cosky: | ||
namespace: ${cosky.namespace:{dev}} | ||
config: | ||
config-id: ${spring.application.name}.yaml | ||
redis: | ||
mode: ${cosky.redis.mode:standalone} | ||
url: ${cosky.redis.uri:redis://localhost:6379} | ||
logging: | ||
file: | ||
name: logs/${spring.application.name}.log | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters