Skip to content

This plugin allows easy integration of Consul for service discovery and registration in Ktor applications.

Notifications You must be signed in to change notification settings

leejay001/ktor-consul

Repository files navigation

Ktor Consul Plugin

This plugin allows easy integration of Consul for service discovery and registration in Ktor applications.

Requirements

Before using this plugin, please make sure you have Consul installed and running properly. See Consul Installation Guide for details.

And In your Ktor application.conf file:

microservice{

 config {
    name = "your-service-name"
    host = "your-serivce-host"
    port = your-service-post
    consul_url = "http://localhost:8500"
 }

}

Usage

To use the plugin, call the consul function and configure as needed:

fun Application.configureConsul(){

    consul {
        config.withHttps(false) 
            .withConsulBuilder {
               // consul builder config
            }
            
            .withRegistrationBuilder {
               // registration builder config
            }
    }

}

This will register the Ktor service in Consul for service discovery.

See Consul.kt for more details on configuration options.

Additionally, you can use consulConnect to integrate with Consul service mesh:

implementation("io.ktor:ktor-client-cio:$ktor_version")
fun Application.configureConsulMesh(){
    consulConnect(
        engineFactory = CIO,
        serviceName = "account"
    ){
        // client config
    }
}

The consulConnect function creates an HTTP client with the CIO engine to call Consul Connect APIs.

Installation

Add the following dependency in your build.gradle:

implementation 'com.lee.consul:consul:0.0.1'

Or in your pom.xml:

<dependency>
  <groupId>com.lee.consul</groupId>
  <artifactId>consul</artifactId>
  <version>0.0.8-beta</version>
</dependency>

Contributing

Contributions are welcome! Please create an issue or submit a pull request.

License

This project is licensed under the MIT License.

About

This plugin allows easy integration of Consul for service discovery and registration in Ktor applications.

Topics

Resources

Stars

Watchers

Forks

Languages