marcosflobo / hazelcast-api

Microservice, based on Micronaut Framework, that exposes an API to manage information in Hazelcast

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

hazelcast-api

Codacy Badge Codacy Badge

Microservice that exposes an API to manage information in Hazelcast Maps

Features

  • Write information in a Hazelcast map
  • Read information from a Hazelcast map based on a key

Change Log

See CHANGELOG.md

Configuration

Property Default value Description
MICRONAUT_SERVER_PORT 6969 The port on the API is listening
MICRONAUT_SERVER_MAX_REQUEST_SIZE 1024 Max size, in bytes, allowed for an incoming request
HAZELCAST_NETWORK_ADDRESSES localhost:5701 The DNS and port of the Hazelcast cluster
HAZELCAST_CLIENT_NAME hazelcastApi The name representing this microservice the list of clients from Hazelcast connections
HAZELCAST_CLIENT_CLUSTERNAME dev The name of the Hazelcast cluster to connect
MICRONAUT_METRICS_ENABLED true Enable or disable the Micronaut metrics endpoint

API Endpoints

Endpoint Method Produces Consumes Body Description
/v1/map PUT application/json application/json {"key":"foo", "value":"myvalue", "map-name":"mymap"} Write a key/value on a specific Hazelcast Map
/v1/map POST application/json application/json {"key":"foo", "map-name":"mymap"} Get the value from a key on a specific Hazelcast Map

Examples

Write simple key/value in Map named "mymap2"

curl -X PUT http://localhost:6969/v1/map --header "Content-Type: application/json" -d '{"key":"foo","value":"myvalue2", "map-name":"mymap2"}'

Write a complex key/value in Map named "mymap2"

curl -X PUT http://localhost:6969/v1/map --header "Content-Type: application/json" -d '{"key":"foo","value":"{\"internal_key\": \"internal_value\"}", "map-name":"mymap2"}'

Get a value from a key in Map named "mymap2"

curl -X POST http://localhost:6969/v1/map --header "Content-Type: application/json" -d '{"key":"complexkey", "map-name": "mymap2"}'

Docker

Docker image is available on marcosflobo/hazelcast-api

Run simple hazelcast-api container

docker run -it --rm --name my-hazelcast-api -p 6969:6969 marcosflobo/hazelcast-api:1.0.0

Run hazelcast-api container with concrete configuration for Hazelcast cluster

docker run -it --rm --name my-hazelcast-api -p 6969:6969 --env HAZELCAST_NETWORK_ADDRESSES=hazelcast:5701 --env HAZELCAST_CLIENT_NAME=hazelcast-api-docker --env HAZELCAST_CLIENT_CLUSTERNAME=dev --env MICRONAUT_SERVER_PORT=6969 marcosflobo/hazelcast-api:1.0.0 

Development

During development, it's very important test and test fast, not only the application but also how it will work when it's deployed in production. For that, it's important to test via Docker container and, for doing so, we can use a docker-compose file.

The docker-compose.yml file will run:

  • Container with the last assembled version of this hazelcast-api app
  • Container with Prometheus service, to scrape the metrics exposed by the app
  • Container with Grafana service, to visualize the metrics scraped by Prometheus from the app

Run docker-compose

$ ./gradlew clean assemble && docker-compose up --build

To stop the docker-compose, just type Ctrl+c. To remove the containers created, run docker-compose down.

Metrics

Endpoint Description
/metrics Metrics information in JSON format
/prometheus Metrics information in Prometheus format
/health Status health of the service in JSON format

Micronaut

Feature cache-hazelcast documentation

Feature management documentation

Feature http-client documentation

About

Microservice, based on Micronaut Framework, that exposes an API to manage information in Hazelcast

License:Apache License 2.0


Languages

Language:Java 60.1%Language:Groovy 38.4%Language:Dockerfile 1.5%