Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Ticket Monster Backend V2

This backend module contains the monolith Ticket Monster service without the UI. (Use an external UI to connect to the REST API that this service exposes.) Besides, this backend version implements the functionality to call the external service OrdersService (see project orders-service). This is controlled using a feature flag defined by FF4J.

Prerequisites

  • Requires access to a PCF Cluster
  • Make sure you have Cloud Foundry CLI installed
  • You need Maven to build the monolith
  • You need Docker to create a Docker image
  • Sign In to your DockerHub Account

How to use Feature Flags for Java (FF4J)

1. Add FF4J dependency to pom.xml

<dependency>
    <groupId>org.ff4j</groupId>
    <artifactId>ff4j-core</artifactId>
    <version>${ffj4.version}</version>
</dependency>

2. Define feature flag(s) in ./src/main/resources/ff4j.xml

<?xml version="1.0" encoding="UTF-8" ?>
<features xmlns="http://ff4j.org/schema"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://ff4j.org/schema http://ff4j.org/schema/ff4j-1.4.0.xsd">
  <feature uid="orders-internal" enable="false"  description="Continue with legacy orders implementation" />
  <feature uid="orders-service" enable="true"  description="Call new orders microservice" />
</features>

3. Add class FF4jFactory.java to package ./src/main/java/org/jboss/examples/ticketmonster/util

@ApplicationScoped
public class FF4jFactory implements FF4jProvider{

    private static FF4j rc = new FF4j("ff4j.xml");

    @Produces
    public static FF4j ff4j(){
        return rc;
    }

    @Override
    public FF4j getFF4j() {
        return rc;
    }
}

4. (After a re-deployment of backend-v2) See FF4J console

https://backend-v2.YOUR-SYSTEM-DOMAIN/ff4j-console

FF4J Embedded Admin Console

Instructions

0. Clone the repository and change directory

$ cd backend-v2

1. Make sure to have a mysql Cloud Foundry service instance described here

If you don't have a ticketMonster-mysql service, create one using:

$ cf create-service p-mysql 100mb ticketMonster-mysql

2. Build the latest version of the backend-v1 as Docker image

$ mvn clean install -P mysql fabric8:build -D docker.image.name=<your dockerhub account>/backend:v2

3. Move to Dockerfile and push Docker image to DockerHub

$ cd .\target\docker\<your dockerhub account>\backend\v2\build\
$ docker push <your dockerhub account>/backend:v2

4. Push the application to Cloud Foundry by refering to the container image on DockerHub

cf push backend-v2 -o <your dockerhub account>/backend:v2

5. Bind the mysql service instance to the application

$ cf bind-service backend-v2 ticketMonster-mysql

6. Get binding information (jdbcUrl, name and password) and set environment variables: database connection-url, user-name, and password to these values

$ cf env backend-v2
$ cf set-env backend-v2 CONNECTION-URL jdbc:mysql://***
$ cf set-env backend-v2 USER-NAME ***
$ cf set-env backend-v2 PASSWORD ***

7. Restage application to ensure your environment variable changes take effect

$ cf restage backend-v2