Skip to content

Instantly share code, notes, and snippets.

@arehmandev
Last active February 25, 2022 08:28
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arehmandev/f4c5dd59fae12d66a1ec8a5f7d2ce5e6 to your computer and use it in GitHub Desktop.
Save arehmandev/f4c5dd59fae12d66a1ec8a5f7d2ce5e6 to your computer and use it in GitHub Desktop.
Store keyvalue pair in Consul using groovy (java Ecwid/consul-api)
@Grab( 'com.ecwid.consul:consul-api:1.2.4' )
import com.ecwid.consul.v1.*
client = new ConsulClient("172.20.20.10:8500")
setvalue("Abskey", "Absvalue")
println getvalue("Abskey")
def setvalue(String key, value){
def binaryvalue = value as byte[]
client.setKVBinaryValue(key, binaryvalue)
println("Value set")
}
def getvalue(String key) {
def keyValueResponse = client.getKVValue(key)
def response = keyValueResponse.getValue().getDecodedValue()
return response
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment