When developing light-portal services, it is crucial to ensure that each endpoint works before loading them from the hybrid server. The best approach is to debug and test with JUnit tests within each service. In this tutorial, we are going to walk through the process with light-portal user-command and user-query services.
This approach has its limitations. It requires that the endpoint tested is working independently without access to other services. If it requires additional services, you need to start one of the hybrid-command or hybrid-query servers. For example, when you are running updateUserById on the user-command service through JUnit, you might need to start the hybrid-query server with user-query service loaded for the query. Another example is when debugging the streams processing on the user-query, you might need to either run a JUnit test case from user-command to publish an event to Kafka or start a hybrid-command server and push an event from curl command line or postman.
In different combinations, we need to ensure the local environment is ready for debugging or testing.
Almost all services in light-portal need Kafka for event sourcing and CQRS. We need to start the Confluent platform locally. I have it installed in my tool folder.
confluent local services start
To check the status.
confluent local services status
To stop the Confluent platform.
confluent local services stop
When you need two or more servers to interact with each other, it is better to have a Consul docker instance running locally for flexibility. Of course, you can use the DirectRegistry in the service.yml to pin each server to a specific IP and port number.
To start a Consul instance with Docker.
docker-compose -f docker-compose-consul.yml up -d
If there are any interactions between the command side and the query side, we need the light-oauth2 services running locally to provide client credentials tokens. For all portal services, we have security enabled by default, as most of them need the user_id and roles in the JWT token to complete the logic. For command side services, we need the user_id in JWT to generate the eventId object to indicate the owner of the events.
To start the light-oauth2 and register them to the Consul.
docker-compose up -d
With most of the user services depending on the user_id and roles from the JWT token, please set hybrid-security.yml enableVerifyJwt to true. It requires all tests must contain authorization header with a long-lived token.