Git Product home page Git Product logo

gcp-training-cashier-service's Introduction

Cashier Service

This Microservice allows the cashier to create new transactions by exposing an HTTP endpoint and then sending transactions to PubSub queues for further processing.

POST - http://localhost:5004/cashier/create to create a transaction of 'debit' or 'credit' type and accept below request body with just "customerId":

 {
   "accountNumber":"92887275",
   "amount":20,
   "operation":"debit"
 }

Response:

{
  "accountNumber": "92887275",
  "amount": 20,
  "created": "2020-01-23T17:41:40Z",
  "id": "ed4b1ef1-74c2-4c49-93f7-a45ba9e6c57b",
  "operation": "debit",
  "status": "accepted"
}

Fork this repository in your github account to continue the rest of exercise.

Requirements

  • A Pub/Sub topic for transactions, up and running in your Google Cloud account
  • Ideally, the Transaction service up and running and subscribed to the topic we will use with service

Environment variables

The Cashier and Transaction services communicate via a pub sub topic on GCP, so make sure that the same topic name is used for both services.

The service uses the below variables in its configuration. They all have default values as shown below if they are not otherwise specified:

PORT=5004(default)

The transactions topic ID is also required for the cashier service to publish to the correct channel and interact with the transactions service. This must be set into the below variable:

TRANSACTIONS_TOPIC_ID=[TRANSACTION_TOPIC_ID]

To run linter

make lint

To run tests

make test

To run service locally

Before running the application locally you must set credentials json file locally to authenticate as we did for other Microservices.

export GOOGLE_APPLICATION_CREDENTIALS=[PATH_TO_CREDENTIALS_FILE]/[SERVICE_ACCOUNT_CREDENTIALS_FILENAME].json 
make run

Deployment

CLI Deployment

This repository contains a cloudbuild.yaml file to deploy service on to Cloud Run. Execute the below command to trigger a Cloud Build Deployment after replacing the variables with appropriate values.

gcloud builds submit --substitutions=_TRANSACTIONS_TOPIC_ID="[TRANSACTIONS_TOPIC_ID]"

where [TRANSACTIONS_TOPIC_ID] is the ID of the Pub/Sub topic that publishes messages to the Transaction service.

If you have used the gcp-infrastructure-script to provision the required resources and have not changed any values than the default topic id would be "transactions". If not kindly replace with an appropriate value.

Setup Cloud Build Trigger to deploy Microservice on each commit

Now let us set up a Cloud Build Trigger to deploy the changes automatically with each commit.

  1. Navigate to the Cloud Build page in the console and click Triggers
  2. Click Create Trigger and should open a new page.
  3. Enter all the information highlighted in the below image.
  4. Set the substitutions variables appropriately (preferably the same as the CLI step). As explained earlier if you wish you change the variable name you must change in the "cloudbuild.yaml" as well.
  5. The values specified here will override any default values defined in the "cloudbuild.yaml". If you wish to change the value make a note of it.

  1. Click Create Trigger and your trigger should be ready to use.
  2. Make a commit and observe Cloud Build to confirm the trigger is working fine.

API documentation

You can access the swagger API documentation by launching the application by adding 'cashier/docs' in the service endpoint

gcp-training-cashier-service's People

Contributors

abhisheksr01 avatar jnonino avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.