|
| 1 | +# Deployment & Verification Guide |
| 2 | + |
| 3 | +> This guide is prepared for Linux OS, npm install command fails for Windows. |
| 4 | +> Please switch to Node.js version 8.x before proceed. |
| 5 | +
|
| 6 | +1. I prepared a docker-compose file for local deployment. It will start the following services: |
| 7 | + * postgres |
| 8 | + * zookeeper |
| 9 | + * kafka |
| 10 | + * bus-api |
| 11 | +2. Run following commands to start dependency services: |
| 12 | + ```bash |
| 13 | + cd local |
| 14 | + docker-compose build --no-cache |
| 15 | + docker-compose up -d |
| 16 | + ``` |
| 17 | +3. After services have started successfully, set environment variables for notifications api: |
| 18 | + ```sh |
| 19 | + # you need to provide the values for the next variables |
| 20 | + export AUTH0_CLIENT_ID |
| 21 | + export AUTH0_CLIENT_SECRET |
| 22 | + export SLACK_BOT_TOKEN |
| 23 | + |
| 24 | + # for other variables can uses these ones |
| 25 | + export AUTH0_URL='https://topcoder-dev.auth0.com/oauth/token' |
| 26 | + export AUTH0_AUDIENCE='https://m2m.topcoder-dev.com/' |
| 27 | + export AUTH0_AUDIENCE_UBAHN='https://u-bahn.topcoder.com' |
| 28 | + export AUTH_SECRET='mysecret' |
| 29 | + export VALID_ISSUERS='["https://api.topcoder-dev.com", "https://api.topcoder.com", "https://topcoder-dev.auth0.com/", "https://auth.topcoder-dev.com/"]' |
| 30 | + export DATABASE_URL='postgres://postgres:postgres@localhost:5432/postgres' |
| 31 | + export PORT=4000 |
| 32 | + export TC_API_V5_BASE_URL='http://localhost:8002/v5' |
| 33 | + export KAFKA_URL='localhost:9092' |
| 34 | + export KAFKA_GROUP_ID='tc-notifications' |
| 35 | + export SLACK_NOTIFY='true' |
| 36 | + export ENABLE_DEV_MODE='false' |
| 37 | + ``` |
| 38 | + |
| 39 | +4. Run command `npm install` |
| 40 | +5. Run command `npm run reset:db` to initialize tables. |
| 41 | +6. Run command `npm run startConsumer` to start kafka consumer. |
| 42 | +7. Wait to see following logs: |
| 43 | + ```bash |
| 44 | + 2021-07-24T15:11:01.512Z INFO no-kafka-client Joined group tc-notifications generationId 1 as no-kafka-client-2689c63f-9850-448a-a3f0-11d2ec8e49ce |
| 45 | + 2021-07-24T15:11:01.512Z INFO no-kafka-client Elected as group leader |
| 46 | + 2021-07-24T15:11:01.583Z DEBUG no-kafka-client Subscribed to notifications.autopilot.events:0 offset 0 leader localhost:9092 |
| 47 | + 2021-07-24T15:11:01.583Z DEBUG no-kafka-client Subscribed to challenge.notification.events:0 offset 0 leader localhost:9092 |
| 48 | + 2021-07-24T15:11:01.584Z DEBUG no-kafka-client Subscribed to notification.action.create:0 offset 0 leader localhost:9092 |
| 49 | + 2021-07-24T15:11:01.584Z DEBUG no-kafka-client Subscribed to admin.notification.broadcast:0 offset 0 leader localhost:9092 |
| 50 | + ``` |
| 51 | +8. Now, we will prepare terminals to be used later for verifying api. |
| 52 | + * 1 terminal to watch kafka topic for email notifications. |
| 53 | + * 1 terminal to query Notifications table for web notifications. |
| 54 | + * Slack app, web or mobile application. |
| 55 | +9. Open a new terminal for watching kafka topic `external.action.email` |
| 56 | + ```bash |
| 57 | + docker exec notification-kafka /opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic external.action.email |
| 58 | + ``` |
| 59 | +10. **Alternative-1:** Open a new terminal for postgres. It will be used to check if notifications are getting created. |
| 60 | + ```bash |
| 61 | + docker exec -it notification-postgres psql -U postgres |
| 62 | + \c postgres |
| 63 | + SELECT * FROM "Notifications"; |
| 64 | + ``` |
| 65 | + **Alternative-2:** Start notifications api and use postman to list notifications. Open a new terminal and change PORT to 3000 |
| 66 | + ```bash |
| 67 | + . ./environment.sh |
| 68 | + export PORT=3000 |
| 69 | + npm run startAPI |
| 70 | + ``` |
| 71 | + Open postman and use following collection and environment: |
| 72 | + * collection: docs/tc-notifications.postman_collection.json |
| 73 | + * environment: docs/tc-notifications.postman_environment.json |
| 74 | + |
| 75 | + Existing postman collections are outdated and need to be converted to version 2.0.0. So, I had to create a new collection. |
| 76 | + |
| 77 | +11. To verify slack messages, you can use following workspace and user credentials. Token for posting messages to slack was already shared inside environment variables and has been set at step 3. |
| 78 | + `https://tc-notifications.slack.com/` |
| 79 | + username: `tc.notification.slack@gmail.com` |
| 80 | + password: `@Topcoder123` |
| 81 | + |
| 82 | + |
| 83 | +12. Now we can start testing. Open a new terminal for producing kafka messages for the topic `notification.action.create` |
| 84 | + ```bash |
| 85 | + docker exec -it notification-kafka /opt/kafka/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic notification.action.create |
| 86 | + ``` |
| 87 | +13. You can copy and paste the following messages to the terminal we opened for producing kafka messages. |
| 88 | + send messages successfully |
| 89 | + ```json |
| 90 | + {"topic":"notification.action.create","originator":"tc-direct","timestamp":"2018-02-16T00:00:00","mime-type":"application\/json","payload":[{"serviceId":"email","type":"taas.notification.request-submitted","details":{"from":"example@example.com","recipients":[{"userId":123,"email":"test1@test.com"},{"userId":456,"email":"test2@test.com"}],"cc":[{"userId":789,"email":"test3@test.com"},{"userId":987,"email":"test4@test.com"}],"data":{"subject":"...","body":"...","field1":"...","field2":"...","filedN":"..."},"sendgridTemplateId":"...","version":"v3"}},{"serviceId":"slack","type":"taas.notification.request-submitted","details":{"channel":"general","text":"test message"}},{"serviceId":"web","type":"taas.notification.request-submitted","details":{"userId":40152856,"contents":{},"version":1}}]} |
| 91 | + ``` |
| 92 | + email: fail (invalid email), web: success, slack: success |
| 93 | + ```json |
| 94 | + {"topic":"notification.action.create","originator":"tc-direct","timestamp":"2018-02-16T00:00:00","mime-type":"application\/json","payload":[{"serviceId":"email","type":"taas.notification.request-submitted","details":{"from":"example.com","recipients":[{"userId":123,"email":"test1@test.com"},{"userId":456,"email":"test2@test.com"}],"cc":[{"userId":789,"email":"test3@test.com"},{"userId":987,"email":"test4@test.com"}],"data":{"subject":"...","body":"...","field1":"...","field2":"...","filedN":"..."},"sendgridTemplateId":"...","version":"v3"}},{"serviceId":"slack","type":"taas.notification.request-submitted","details":{"channel":"random","text":"test message"}},{"serviceId":"web","type":"taas.notification.request-submitted","details":{"userId":40152856,"contents":{},"version":1}}]} |
| 95 | + ``` |
0 commit comments