- Endpoint
/newusermakes a GET request to a userservice and must be connected to the service that provides the user information. The user information is saved in the elasticsearch-cluster.
Let's say we are provided with three users:
[
{
"name": "Olle",
"userID": "11111"
},
{
"name": "Ulla",
"userID": "22222"
},
{
"name": "Ella",
"userID": "33333"
}
]
-
Endpoint
/searchtakes a requestparam and searches for namesTHAT STARTS WITHthe value of the requestparam.
/search?query=llawould not find any because no name starts with "lla". -
Endpoint
/search/containstakes a requestparam and searches for namesCONTAININGthe value of the requestparam.
/search/contains?query=llawould find "Ulla" and "Ella" because they both contain "lla".
- ELASTICSEARCH_URI is the location of the elasticsearch cluster. This is where the data will be saved and requested from by the endpoints.
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:8.13.0
container_name: elasticsearch2
restart: on-failure
ports:
- "9200:9200"
volumes:
- elastic_data:/usr/share/elasticsearch/data/
environment:
- xpack.security.enabled=false
- discovery.type=single-node
When running as a service with docker compose like the code above, the variable should be set to http://elasticsearch:9200 since the servicename is elasticsearch and the port of the service is 9200.
- GET_USERS is the location where you will get the userdata from.
usersapp:
image: ghcr.io/chatgut/userservice:1.0
restart: on-failure
container_name: userservice
ports:
- "8002:8002"
depends_on:
- dbUsers
environment:
DB_URL: jdbc:mysql://dbUsers:3306/userService
DB_USER: developer
DB_PASSWORD: password
When running the userservice with docker compose like the code above, the variable should be set to http://usersapp:8002/users/all since the servicename is usersapp and the port of the service is 8002 and this particular user app has an endpoint called /users/all
that returns a list of users.
An implementation of this application as a service would look like this:
search-service:
image: search:1
ports:
- "8006:8080"
environment:
GET_USERS: http://usersapp:8002/users/all
ELASTICSEARCH_URI: http://elasticsearch:9200
restart: on-failure
Clone the repository and run the following command:
docker compose up to run with the examples above.