The vote microservice stores feedback from the sessions and displays how well all sessions were liked in a pie chart. If the vote service is is running in a Cloud Foundry environment, or manually configured (via server.xml) to connect to a CouchDB database, the votes will be persisted. Otherwise, the vote data will simply be stored in-memory.
GET /health/ # Provide health check of service
GET /vote/ # Returns description of service
GET /vote/attendee # Create new attendee
POST /vote/attendee # Create new attendee
GET /vote/attendee/{id} # Get attendee by ID
POST /vote/attendee/{id} # Update existing attendee by ID
DELETE /vote/attendee/{id} # Remove attendee by ID
POST /vote/rate # Get a list of all session ratings
GET /vote/rate # Get list of all session ratings
PUT /vote/rate/{id} # Update session rating
GET /vote/rate/{id} # Get session rating by ID
DELETE /vote/rate/{id} # Delete session rating by ID
GET /vote/ratingsBySession # Get all session votes by session ID
GET /vote/averageRatingBySession # Get average session rating by session ID
GET /vote/ratingsByAttendee # Get all votes made by attendee ID
-
JAX-RS is used to to define the endpoints for the application, and performs JSON databinding on incoming and outgoing JSON data so that the rest of the code can utilize the data as POJOs.
-
CDI is used to instantiate data access objects (DAO’s) and manage invocation of lifecycle operations such as
@PostConstricut -
JSON-P is used to implement custom JAX-RS MessageBodyReader/Writer classes for binding between JSON and POJO
-
MicroProfile Config is used to inject an instance of
io.microprofile.showcase.vote.persistence.couch.Credentialswhen the microservice is running in Cloud Foundry -
MicroProfile Fault-Tolerance is used in the CouchAttendeeDAO and CouchSessionRatingDAO to:
-
impose timeouts on various operations using
@Timeout -
automatically retry failed operations using
@Retry -
limit the maximum resources allocated to parallel operations using
@Bulkhead
-
-
MicroProfile Health is used to provide an UP/DOWN health check of the service. The following health checks are implemented:
-
HashMapDAO to determine if the in-memory storage is accessible (which is always) and gives an example of an UP status
-
CouchAttendeeDAO to determine if it can connect to the CouchDB backend
-
CouchSessionDAO to determine if it can connect to the CouchDB backend
-
-
CouchDB is a NoSQL database. It’s not part of MicroProfile, but is used here to persist vote information
-
MicroProfile Metrics is used to gather metrics about the time it takes the HashMapDAO objects to complete their operations, and to keep a count of the amount of times each REST endpoint is requested
-
The metrics are available to view at https://localhost:9443/metrics. Sending a request that accepts
application/jsonwill receive a JSON response, otherwise a Prometheus-formatted response will be sent -
Metrics requires the username "confAdmin" and the password "microprofile". These can be configured in the
<quickStartSecurity>tag of the src/main/liberty/config/server.xml -
A sample prometheus config (
sample-prometheus-config.yml) is provided to use with the vote service. This can be used as-is with a locally running instance of the Vote service; metrics will be scraped every 5 seconds. To use this config, replace the defaultprometheus.ymlfile in any prometheus installation, or copy the job config into your own file.
-
cd microservice-vote
mvn package
java -jar target/microservice-vote.jarAccess the app at http://localhost:7070/vote
By default the microservice will start on port 7070. To set it to a different port use the following Maven properties:
-DtestServerHttpPort=9080 -DtestServerHttpsPort=9443Note: if you run the package command with the 'liberty' profile the jar file will be called microservice-vote-liberty.jar.