Microservice that exposes an API to manage information in Hazelcast Maps
- Write information in a Hazelcast map
- Read information from a Hazelcast map based on a key
See CHANGELOG.md
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 |
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 |
curl -X PUT http://localhost:6969/v1/map --header "Content-Type: application/json" -d '{"key":"foo","value":"myvalue2", "map-name":"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"}'
curl -X POST http://localhost:6969/v1/map --header "Content-Type: application/json" -d '{"key":"complexkey", "map-name": "mymap2"}'
Docker image is available on marcosflobo/hazelcast-api
docker run -it --rm --name my-hazelcast-api -p 6969:6969 marcosflobo/hazelcast-api:1.0.0
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
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
$ ./gradlew clean assemble && docker-compose up --build
- Prometheus is available on http://localhost:9090. Perform some tests on the app API (see chapter above) and wait 30s to query for some metric such as
http_server_requests_seconds_count
- Grafana is available on http://localhost:3000
- Hazelcast server is deployed on port 5701
- Hazelcast Management Center is available on http://localhost:8080
- And the hazelcast-api microservice is available on http://localhost:6969
To stop the docker-compose, just type Ctrl+c
. To remove the containers created, run docker-compose down
.
Endpoint | Description |
---|---|
/metrics | Metrics information in JSON format |
/prometheus | Metrics information in Prometheus format |
/health | Status health of the service in JSON format |
- Version 2.1.2. More info at Micronaut 2.1.2
- Official documentation