Skip to content

Getting Started ​

8.0 is in beta

It is complete, but there is no compatibility promise before the release candidate: until 8.0.0-rc.1 freezes them, its API, wire format, configuration and Redis data may still change. It is still a preview, not yet for real traffic. ahoowang/cosky:latest is still 6.x, whose documentation is in the v6 branch.

This takes a server in development mode and a Spring Boot 4 application. Requirements lists the versions.

1. Start a server ​

bash
docker run -p 8080:8080 -p 9090:9090 ahoowang/cosky:8.0.0-beta.11 --dev

--dev needs no Redis and no sign-in. Nothing survives a restart, so never run it for real: Deployment shows how. Port 9090 serves applications over gRPC. Port 8080 serves the REST API and the Dashboard, at http://localhost:8080.

2. Add the starter ​

kotlin
dependencies {
    implementation(platform("org.springframework.boot:spring-boot-dependencies:4.2.0"))
    implementation(platform("org.springframework.cloud:spring-cloud-dependencies:2026.0.0"))
    implementation(platform("me.ahoo.cosky:cosky-bom:8.0.0-beta.11"))
    implementation("me.ahoo.cosky:cosky-spring-boot-starter")
    implementation("org.springframework.boot:spring-boot-starter-webflux")
    implementation("org.springframework.cloud:spring-cloud-context") // for live refresh
}

In Kotlin, add the kotlin("plugin.spring") Gradle plugin as well: the bean in @RefreshScope below has to be open.

3. Configure the application ​

yaml
# application.yaml
server:
  port: 8081 # 8080 is the CoSky server
spring:
  application:
    name: provider
  config:
    import: "optional:cosky:provider.yaml"
cosky:
  endpoints: localhost:9090
  namespace: default

The application registers itself as the service provider once its web server is up, and imports the Config provider.yaml. optional: lets it start while that Config does not exist yet.

4. Create a Config ​

bash
curl -X PUT localhost:8080/v1/namespaces/default/configs/provider.yaml \
  -H 'Content-Type: application/json' \
  -d '{"config":{"format":"CONFIG_FORMAT_YAML","content":"example:\n  greeting: Bonjour"}}'

A bean in @RefreshScope sees the new value without a restart:

kotlin
@RestController
@RefreshScope
class HelloController(@Value("\${example.greeting:Hello}") private val greeting: String) {
    @GetMapping("/hello/{name}", produces = [MediaType.TEXT_PLAIN_VALUE])
    fun hello(@PathVariable name: String): String = "$greeting, $name"
}

5. Find it from another application ​

Add spring-cloud-starter-loadbalancer to a second application with the same settings and its own name and port, and call the provider by its service name:

kotlin
@Bean
@LoadBalanced
fun webClientBuilder(): WebClient.Builder = WebClient.builder()

// ...
builder.baseUrl("http://provider").build().get().uri("/hello/World").retrieve().awaitBody<String>()

On a Mac with Apple silicon, this application logs an error at start that Netty cannot load MacOSDnsServerAddressStreamProvider. Reactor Netty brings the Intel build of that library only. Add the other to quiet it:

kotlin
runtimeOnly("io.netty:netty-resolver-dns-native-macos::osx-aarch_64")

On a Mac with a system proxy, the call fails, often with a 503 from the proxy. The JDK on macOS takes the system's proxy as http.proxyHost, and Spring Boot 4.2's WebClient follows it, so the call to the provider goes through the proxy, which cannot reach the address the provider registered. Start this application with the proxy left out:

bash
-Dhttp.nonProxyHosts='*'

6. Look around ​

Open the Dashboard at http://localhost:8080. Instances show up under Service, with Leased next to them, and the topology on the first page shows who calls whom. The server records the topology every 30 seconds (cosky.view.topology-flush-interval), so the consumer shows up there, and here, up to half a minute after it starts:

bash
curl localhost:8080/v1/namespaces/default/views/topology

See it run ​

The repository holds this as a working example. examples/README.md walks through it:

bash
./gradlew :server:run --args='--dev'
bash
./gradlew :examples:provider:run
bash
./gradlew :examples:consumer:run

Next steps ​

Released under the Apache License 2.0.