Skip to content

Latest commit

 

History

History
363 lines (234 loc) · 11 KB

README.md

File metadata and controls

363 lines (234 loc) · 11 KB

SpringStarterProject

Contents:

Cassandra db setup:

Following are the steps I used to install cassandra db on my macbook.

Step 1: Install Homebrew

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

The output if the installation looks like this:

image

Run the commands in the last line of the ouput to set homebrew to the PATH. In this case:

(echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> /Users/shantanushinde/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"

Step 2: Install OpenJDK 11

brew install openjdk@11

Step 3: Set up Java environment variable

Determine which shell profile file you are using. Common shell profile files are ~/.bash_profile for Bash, ~/.zshrc for Zsh, and ~/.bashrc for Bash (on some systems). In my case it was ~/.zshrc. Run the following command to open the shell profile file using a text editor (replace ~/.zshrc with the appropriate file if you're using a different shell):

open -a TextEdit ~/.zshrc

Add the following lines at the end of the file:

export JAVA_HOME="/usr/local/opt/openjdk@11"
export PATH="$JAVA_HOME/bin:$PATH"

These lines set the JAVA_HOME environment variable to the OpenJDK 11 installation path and add it to the PATH variable. Save the file and close the text editor. To apply the changes, run the following command in the Terminal:

source ~/.zshrc

Step 4: Install Cassandra

To install Cassandra run:

brew install cassandra

To start cassandra and restart at login run:

brew services start cassandra

Check installation using the following command:

brew services list

It should show an output similar to:

image

Alternatively, to check installation you can also run:

cqlsh

This should open up the CQL shell.

Step 4: Create the keyspace

Launch the CQL shell using:

cqlsh

Create the customerDB keyspace:

CREATE KEYSPACE customerDB WITH replication = {'class':'SimpleStrategy', 'replication_factor':1};

Deploying Cassandra on Minikube:

If you want to deploy Cassandra DB on Minikube instead of running it locally, checkout this link. Not implemented here as my local machine ran out of memory!!!.

Setup Solace for JMS log message queuing

Follwing steps are for setting up Solace for JMS messaging to a loggingQueue

Step 1: Install prerequisites

You need have Docker installed. Installation can be found here. Install Minikube.

Step 2: Download the Docker Compose Template

Clone the GitHub repository containing the Docker Compose template.

git clone https://github.com/SolaceLabs/solace-single-docker-compose.git
cd solace-single-docker-compose/template

Step 3 (Optional): Change the ports before composing

This step is optional and is mostly required in development as the default port for spring boot apllication is 8080. The JMS solace application also used the 8080 port for it's SEMP/PubSub+ Manager. In order to do this, open the template/PubSubStandard_singleNode.yml file in the cloned repository and change the line:

...
#SEMP / PubSub+ Manager
- '8080:8080'
...

to:

...
#SEMP / PubSub+ Manager
- '8081:8080'
...

Step 4: Create a PubSub+ Software Event Broker

Run the following command to create a PubSub+ software event broker using the Compose template:

docker-compose -f PubSubStandard_singleNode.yml up -d

Step 5: Manage the PubSub+ Software Event Broker

To start issuing configuration or monitoring commands on the event broker, you can access Broker Manager or the Solace CLI. To access PubSub+ Broker Manager:

  1. Open a browser and enter http://localhost:8080. (8081 if you changed it)
  2. Log in as user admin with password admin.

Step 6: Setup a new Message VPN:

In Messaging -> Message VPNs select + Message VPN and fill out the following:

image

The select Set up Default User -> and set admin as username and password then press Create.

Step 7: Setup the queue:

Open the CustomerApplicationMessages. Got to System -> Uset Mgmt -> Users and add a user with admin as password and user name with all accesses granted if not already present.

Go to Messaging -> Queues and Select + Queue. Give it a name loggingQueue and add admin as owner.

Solace Queue demonstration:

To check out how Solace queues work open Messaging -> Try Me!. Also refer this.

Deployment on minikube:

Follwing steps can be used to deploy a Spring Boot application on Minikube capable of querying a locally hosted cassandra db and a Solace queue.

Step 1: Install prerequisites

You need have Docker installed. Installation can be found here. Install Minikube.

Step 2: Start the Minikube Cluster

Start your cluster using:

minikube start --driver=docker

Here's how the output looks:

image

Check the status using:

minikube status

It should display something close to the following:

image

Step 3: Configure demoCustomer and generate jar file

Run the following command to retreive the ip address of the Docker host machine:

minikube ssh -- cat /etc/hosts | grep host.minikube.internal | awk '{print $1}'

Use the ip address return in the above command to configure the Spring Boot Application. In the src/main/resources/application.properties file apdate the following properties:

# Cassandra Connection Configuration
cassandra.contactPoints=<enter docker host ip>
...

#Solace Connection Configuration
solace.host=<enter docker host ip>
...

Run mvn clean install in the spring project to generate the jar files. In case mvn clean install does not work, you need to skip tests using the command:

mvn clean install -DskipTests

Step 4: Use Docker daemon inside Minikube

Run the following command to list the Docker images present in your local Docker environment:

docker images

In my case I get the following output:

image

Minikube comes with a docker daemon preinstalled on it. So the Minikube cluster is running on a Docker virtual machine and a Docker version is installed on this minikube cluster. In order to deploy the Spring boot application docker we need to perform the following steps:

minikube docker-env

This will give an output similar to the following:

image

Run the command in the last line of this output to activate the docker commands on the minikube cluster. For eg; in this case:

eval $(minikube -p minikube docker-env)

Now if run docker images again, we will see the docker images present in the minikube environment. For eg;

image

A change in output here represents that the previous commands worked.

Step 5: Deploy Spring boot image pn minikube

cd into the demoCustomer folder which has the Dockerfile and run the following command to build the docker image on minikube:

docker build -t springstarterproject:1.0 .

Here's how the output looks:

image

Now if we run docker images we see that springstarterproject is added with tag 1.0:

image

Next we need to create a deployment on kubernetes using the kubectl commands.

kubectl create deployment springstarterproject-dep --image=springstarterproject:1.0 --port=8080

Now if we run:

kubectl get all

we see that a pod and a deployment is created with springstarterproject in their names:

image

Inorder to check if the pod is running properly, run:

kubectl logs <pod_name>

In my case it was:

kubectl logs springstarterproject-dep-6f897d5f46-qlf6c

The output should look like the following with Started DemoCustomerApplication displayed:

image

Now we need to create a service for the deployment using:

kubectl expose deployment springstarterproject-dep --port=8080 --type=NodePort --name=springstarterproject-service

Now if we run kubectl get all we see that springstarterproject-service is added in services:

image

Now that we have created a service, we can retrive the url for the service using:

minikube service springstarterproject-service --url

The displayed url is the host and port that we can query using postman or a web browser to run our microservices.

Access Swagger UI

Inorder to access Swagger-UI after deploying on Minikube use the url returned by the baove command followed by swagger-ui.html. Use the follwowing format:

http://localhost:<port>/swagger-ui.html

To Do

Stuff left to do on this project:

  • Develop small UI page to capture that form data from frontend
  • Integrate UI with backend
  • Deploy UI into minikube
  • Make documentation conataining:
    1. Overall architecture diagram showing front end and backend components
    2. Physical architecture
    3. Sequence diagram
    4. Technical documentation