Skip to content

Commit

Permalink
BugFixes & SQS Connector Added
Browse files Browse the repository at this point in the history
- updated valid Auth Token
- set strict_slashes = False in Flask URL Map
- added SQS connector to service --> to notify Queue on Customer#Create
- updated package.json w/aws sdk
  • Loading branch information
mkornyev committed Apr 26, 2021
1 parent 20eef66 commit cf61b21
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 2 deletions.
3 changes: 2 additions & 1 deletion bookBFF/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from flask import Flask, request, json
import requests
app = Flask(__name__)
app.url_map.strict_slashes = False


# CONSTANTS
Expand All @@ -13,7 +14,7 @@

RECC_CIRCUIT_BREAKER_HOST = 'http://10.100.236.41:83/books'
BOOK_SERVICE_HOST = 'http://10.100.144.244:3002/books'
VALID_AUTH_TOKEN = 'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJLUkFNRVJTIiwibHVscyI6IktSQU1FUlMiLCJjcmVhdGVkIjoxNjE3MjMwNzUxM zIwLCJyb2xlcyI6W10sImlzcyI6InRjdS5nb3YuYnIiLCJlaW8iOiIxMC4xMDAuMTkyLjUxIiwibnVzIjoiSk9BTyBBTkR PTklPUyBTUFlSSURBS0lTIiwibG90IjoiU2VnZWMiLCJhdWQiOiJPUklHRU1fUkVRVUVTVF9CUk9XU0VSIiwidHVzIjoiV ENVIiwiY3VscyI6MjI1LCJjb2QiOjIyNSwiZXhwIjoxNjE3MjczOTUxMzIwLCJudWxzIjoiSk9BTyBBTkRPTklPUyBTUFl SSURBS0lTIn0.qtJ0Sf2Agqd_JmxGKfqiLw8SldOiP9e21OT4pKC8BqdXrJ0plqOWHf0hHbwQWp-foEBZzAUWX0J-QHtLy Q7SRw'
VALID_AUTH_TOKEN = 'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJLUkFNRVJTIiwibHVscyI6IktSQU1FUlMiLCJjcmVhdGVkIjoxNjE3MjMwNzUxMzIwLCJyb2xlcyI6W10sImlzcyI6InRjdS5nb3YuYnIiLCJlaW8iOiIxMC4xMDAuMTkyLjUxIiwibnVzIjoiSk9BTyBBTkRPTklPUyBTUFlSSURBS0lTIiwibG90IjoiU2VnZWMiLCJhdWQiOiJPUklHRU1fUkVRVUVTVF9CUk9XU0VSIiwidHVzIjoiVENVIiwiY3VscyI6MjI1LCJjb2QiOjIyNSwiZXhwIjoxNjE3MjczOTUxMzIwLCJudWxzIjoiSk9BTyBBTkRPTklPUyBTUFlSSURBS0lTIn0.qtJ0Sf2Agqd_JmxGKfqiLw8SldOiP9e21OT4pKC8BqdXrJ0plqOWHf0hHbwQWp-foEBZzAUWX0J-QHtLyQ7SRw'


# VALIDATIONS
Expand Down
3 changes: 2 additions & 1 deletion customerBFF/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from flask import Flask, request, json
import requests
app = Flask(__name__)
app.url_map.strict_slashes = False


# CONSTANTS
Expand All @@ -12,7 +13,7 @@
SERVER_PORT = 80

CUSTOMER_SERVICE_HOST = 'http://10.100.74.210:3001/customers'
VALID_AUTH_TOKEN = 'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJLUkFNRVJTIiwibHVscyI6IktSQU1FUlMiLCJjcmVhdGVkIjoxNjE3MjMwNzUxM zIwLCJyb2xlcyI6W10sImlzcyI6InRjdS5nb3YuYnIiLCJlaW8iOiIxMC4xMDAuMTkyLjUxIiwibnVzIjoiSk9BTyBBTkR PTklPUyBTUFlSSURBS0lTIiwibG90IjoiU2VnZWMiLCJhdWQiOiJPUklHRU1fUkVRVUVTVF9CUk9XU0VSIiwidHVzIjoiV ENVIiwiY3VscyI6MjI1LCJjb2QiOjIyNSwiZXhwIjoxNjE3MjczOTUxMzIwLCJudWxzIjoiSk9BTyBBTkRPTklPUyBTUFl SSURBS0lTIn0.qtJ0Sf2Agqd_JmxGKfqiLw8SldOiP9e21OT4pKC8BqdXrJ0plqOWHf0hHbwQWp-foEBZzAUWX0J-QHtLy Q7SRw'
VALID_AUTH_TOKEN = 'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJLUkFNRVJTIiwibHVscyI6IktSQU1FUlMiLCJjcmVhdGVkIjoxNjE3MjMwNzUxMzIwLCJyb2xlcyI6W10sImlzcyI6InRjdS5nb3YuYnIiLCJlaW8iOiIxMC4xMDAuMTkyLjUxIiwibnVzIjoiSk9BTyBBTkRPTklPUyBTUFlSSURBS0lTIiwibG90IjoiU2VnZWMiLCJhdWQiOiJPUklHRU1fUkVRVUVTVF9CUk9XU0VSIiwidHVzIjoiVENVIiwiY3VscyI6MjI1LCJjb2QiOjIyNSwiZXhwIjoxNjE3MjczOTUxMzIwLCJudWxzIjoiSk9BTyBBTkRPTklPUyBTUFlSSURBS0lTIn0.qtJ0Sf2Agqd_JmxGKfqiLw8SldOiP9e21OT4pKC8BqdXrJ0plqOWHf0hHbwQWp-foEBZzAUWX0J-QHtLyQ7SRw'


# VALIDATIONS
Expand Down
3 changes: 3 additions & 0 deletions customerService/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const express = require('express')
const bodyParser = require('body-parser')
const sqsConn = require('./sqs-connector')
const port = 3000

const conn = require('./db-connector')
Expand Down Expand Up @@ -34,6 +35,8 @@ app.post('/customers', (req, res) => {
res.statusCode = 201
res.location(`${req.headers.host}/customers/${customerId}`)
res.json(req.body)

sqsConn.sendNewCustomerMessage(req.body) // PING SQS QUEUE
})
})

Expand Down
1 change: 1 addition & 0 deletions customerService/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"author": "Maksym Kornyev",
"license": "ISC",
"dependencies": {
"aws-sdk": "^2.893.0",
"express": "^4.17.1",
"mysql": "^2.18.1"
}
Expand Down
38 changes: 38 additions & 0 deletions customerService/sqs-connector.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

//################ IMPORTS ################

const AWS = require('aws-sdk');

AWS.config.update({region: 'us-east-1'});
AWS.config.update({
accessKeyId: 'AKIAWQWWY3WMZBY2YZPJ',
secretAccessKey: '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',
region: 'us-east-1'
})


//################ CONSTANTS ################

var SQS = new AWS.SQS();
var SQS_QUEUE_URL = "https://sqs.us-east-1.amazonaws.com/448200760729/customers"

function sendNewCustomerMessage(messageJson) {
var sqsParams = {
MessageBody: JSON.stringify(messageJson),
QueueUrl: SQS_QUEUE_URL
}

SQS.sendMessage(sqsParams, function(err, data) {
if(err) {
console.log(err)
} else {
console.log("SQS Ping :: New Customer Created")
console.log(data)
}
})
}


//################ MODULE EXPORT ################

module.exports = { sendNewCustomerMessage }

0 comments on commit cf61b21

Please sign in to comment.