Uses wordsapi.com to retrieve and store synonyms of words
Ensure to setup a docker container for Neo4j: docker create --name <CONTAINER_NAME> neo4j
Once the container is created, use the following docker switch to disable Neo4j authentication: --env=NEO4J_AUTH=none
docker run \
--publish=7474:7474 --publish=7687:7687 \
--volume=$HOME/neo4j/data:/data \
--volume=$HOME/neo4j/logs:/logs \
--env=NEO4J_AUTH=none \
<CONTAINER_NAME>
If implementing, a possible table schema would be as follows:
CREATE TABLE IF NOT EXISTS WORDS (
ID BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
NAME VARCHAR NOT NULL UNIQUE,
PRIMARY KEY (ID)
);
CREATE TABLE IF NOT EXISTS SYNONYMS (
FROM_WORD BIGINT NOT NULL,
TO_WORD BIGINT NOT NULL,
UNIQUE INDEX (FROM_WORD, TO_WORD)
);
NOTE:
- I did not test these scripts... a good possibility that I have the syntax incorrect.
- If doing this, it might be wise to create two mapping rows, one for TO and one for FROM.
- Inside of
application.properties, you will find a property namedorg.ygrene.demos.synonyms.mashape.token. This property must be set in order to access thewordsapi.comAPI. - Run
mvn spring-boot:runto run the service.
- Ensure you have your
~/.dockercfgsetup for pulling, pushing, building images - Update the POM file to uncomment the
pushline in thedockerfile-maven-pluginplugin - Run
mvn install - Run the docker container with the command line variable or environment variable
org.ygrene.demos.synonyms.mashape.token. This property must be set in order to access thewordsapi.comAPI.
The code is formatted in a way where one can swap out the different database implementations.
For example, one would need to implement:
- Add database specific dependencies to the POM file
- The interface
org.ygrene.demos.synonyms.dal.api.WordStoreDataService - Create a
Repositoryfor the specific database type - Create model entities for the specific database type
- Modifying the spring configuration to point to the new interface
- Start the Docker Neo4j container.
- In your browser, go to
localhost:7474 - In the top bar, type the following:
match (n) return n - Click the
Right Arrow, or hitCtrl + Enter(Windows) orCommand + Enter(Mac) - You can use the
Graph,Table, orTextbuttons to view the results - If you want to clear your database, you can enter the following:
match (n) detach delete n
- Use
pactfor the JVM for Contract Management of for external users. This is very important for a micro-service. - Use
WireMockfor mocking out the Words API requests to do fullController -> Service -> DBtests. - Create valid exception / error pages instead of using the standard Spring Boot error page.
- Use
Spring Boot Securityin order to make secure endpoints. - Add
Spring Eureka Discoveryfor micro-service auto discovery. - Implement
Spring Cachemechanism so we don't need to go to the database every time.
NOTE: If I had more time, I would have at least done #2 as I have used WireMock before. I would like to try #1, but I have never used Pact. I just read about this last week and it looks promising and well constructed.