Photo by Jason Cooper on Unsplash

Layered Architecture

Photo by Denys Nevozhai on Unsplash

網路的組成

什麼是message queue?

為何使用?

Fault tolerance

Decoupling

Photo by Melanie Pongratz on Unsplash

Outline

  1. Deploy a redis database using Docker.
  2. Introduction to Kue.js

Deploy Redis

Photo by Melanie Pongratz on Unsplash

Outline

  1. 部署Redis,使用Docker,在本地起一台Redis
  2. 介紹Kue.js

部署Redis

export PG_PORT=5432
export PG_USER=admin
export PG_PWD=secretpwd
#!/bin/shdocker run                                  \
-d \
-p $PG_PORT:5432 \
-e POSTGRES_USER="$PG_USER" \
-e POSTGRES_PASSWORD="$PG_PASSWORD" \
-v "$PWD/pgdata":/var/lib/postgresql/data \
postgres
  1. -d 在背景執行
  2. -p $PG_PORT:5432 將容器內的5432port映射到本機的$PG_PORT
  3. -e 注入環境變數到容器裏,有哪些環境變數可用,可以參考官方連結https://hub.docker.com/_/postgres/
  4. -v 將容器內的檔案掛載到本機,此處將容器內存放postgres 資料的資料夾 /var/lib/postgresql/data 掛載到$PWD/pgdata,也就是當前目錄的pgdata資料夾
  5. postgres為image的名稱,可以用例如postgres:latest, postgres:9.6,後面加上版本號,沒加就是latest,可用的版本及latest是哪一版可以從此連結查詢https://hub.docker.com/_/postgres/
  1. GET https://notify-bot.line.me/oauth/authorize
  • 帶著你的client id及redirect_uri,GET上面的url,使用者就會被導到line的登入頁面
  • 登入成功之後,line那邊會倒回上述的redirect_uri並且query string帶著code
  • 將第一步得到的code,post到上述url,就可以拿到一個token
  • 帶著上面步驟所取得的token及訊息,post上面的url,使用者就可以收到消息拉~
  1. npm install express-line-notify
  2. 傳入config物件,需要clientId及clientSecret
  3. 選個endpoint來走以上oauth2流程,記得endpoint要加在callbackurl裡
const express = require('express');
const lineNotify = require('express-line-notify');
const config = {
clientId: 'your-client-id',
clientSecret: 'your-client-secret',
}
const app = express();app.use(
'/endpoint_u_want_to_use',
lineNotify(config),
otherMiddleware
);
app.listen(3000);

HoMuChen

陳河穆,Software Engineer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store