Skip to content
This repository was archived by the owner on May 27, 2025. It is now read-only.

Latest commit

ย 

History

History
141 lines (125 loc) ยท 3.73 KB

File metadata and controls

141 lines (125 loc) ยท 3.73 KB

Solapi Agent

๐Ÿ›‘ ์ฃผ์˜์‚ฌํ•ญ ๐Ÿ›‘

  • ๋” ์ด์ƒ ์†”๋ผํ”ผ DB ์—ฐ๋™ํ˜• ์—์ด์ „ํŠธ๋Š” ์œ ์ง€๋ณด์ˆ˜ ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
  • ๋ฌธ์„œ๋ฅผ ํ†ตํ•ด API ๊ฐœ๋ฐœ์—ฐ๋™์„ ์ง„ํ–‰ํ•ด์ฃผ์‹œ๊ฑฐ๋‚˜, SOLAPI Github ๋‚ด SDK๋ฅผ ํ†ตํ•ด ๊ฐœ๋ฐœ์—ฐ๋™์„ ์ง„ํ–‰ํ•ด์ฃผ์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.

๊ฐœ์š”

DB INSERT๋กœ ์นด์นด์˜คํ†ก ๋ฐ ๋ฌธ์ž๋ฅผ ๋ฐœ์†ก ํ•  ์ˆ˜ ์žˆ๋„๋ก go์–ธ์–ด๋กœ ์ž‘์„ฑ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.
ํ˜„์žฌ Agent๋Š” go ์ปดํŒŒ์ผ๋Ÿฌ(go 1.18 ๊ธฐ์ค€)๋กœ ์ƒˆ๋กœ ๋นŒ๋“œํ•˜์…”์•ผ ํ•ฉ๋‹ˆ๋‹ค.

DB ์ค€๋น„

MySQL ๋ฒ„์ „ 5.7.14 ์ด์ƒ์„ ์ค€๋น„ํ•ด์ฃผ์„ธ์š”. ํ˜น์€ MariaDB ๋ฒ„์ „ 10.2 ์ด์ƒ์„ ์ค€๋น„ํ•ด์ฃผ์„ธ์š”.

์•„๋ž˜ ๋‚ด์šฉ์œผ๋กœ DB ๋ฐ ๊ณ„์ •์„ ๋งŒ๋“ค์–ด ์ฃผ์„ธ์š”.

CREATE DATABASE msg;
CREATE USER 'msg'@'localhost' IDENTIFIED BY 'msg';
GRANT ALL PRIVILEGES ON msg.* TO 'msg'@'localhost';

์•„๋ž˜ ์Šคํ‚ค๋งˆ๋กœ ํ…Œ์ด๋ธ”์„ ๋งŒ๋“ค์–ด ์ฃผ์„ธ์š”. (MariaDB๋Š” create_table_maria.sql ์ฐธ๊ณ )

CREATE TABLE msg (
  id integer  AUTO_INCREMENT primary key,
  createdAt DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updatedAt DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  scheduledAt DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  sendAttempts SMALLINT NOT NULL DEFAULT 0,
  reportAttempts SMALLINT NOT NULL DEFAULT 0,
  `to` VARCHAR(20) AS (payload->>'$.to') STORED,
  `from` VARCHAR(20) AS (payload->>'$.from') STORED,
  groupId VARCHAR(255) AS (result->>'$.groupId') STORED,
  messageId VARCHAR(255) AS (result->>'$.messageId') STORED,
  status VARCHAR(20) AS (result->>'$.status') STORED,
  statusCode VARCHAR(255) AS (result->>'$.statusCode') STORED,
  statusMessage VARCHAR(255) AS (result->>'$.statusMessage') STORED,
  payload JSON,
  result JSON default NULL,
  sent BOOLEAN NOT NULL default false,
  KEY (`createdAt`),
  KEY (`updatedAt`),
  KEY (`scheduledAt`),
  KEY (`sendAttempts`),
  KEY (`reportAttempts`),
  KEY (`to`),
  KEY (`from`),
  KEY (groupId),
  KEY (messageId),
  KEY (status),
  KEY (statusCode),
  KEY (sent)
) DEFAULT CHARSET=utf8mb4;

์†Œ์Šค ์ฝ”๋“œ ๋นŒ๋“œ

์•„๋ž˜ ๋ช…๋ น์œผ๋กœ ๋นŒ๋“œํ•˜๋ฉด agent ์‹คํ–‰ํŒŒ์ผ์ด ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.

go build ./cmd/agent/agent.go

์„œ๋น„์Šค ๋ฐ๋ชฌ ์„ค์น˜

๋นŒ๋“œ๋œ agent ํŒŒ์ผ์„ /opt/agent ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ๋งŒ๋“ค๊ณ  ์•„๋ž˜๋กœ ๋ณต์‚ฌํ•ฉ๋‹ˆ๋‹ค.

mkdir -p /opt/agent
cp ./agent /opt/agent/agent

/opt/agent/db.json ํŒŒ์ผ์„ ๋งŒ๋“ค๊ณ  DB์ ‘์† ์ •๋ณด๋ฅผ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.

vi /opt/agent/db.json

db.json ์˜ˆ์‹œ

{
  "provider": "mysql",
  "dbname": "msg",
  "table": "msg",
  "user": "root",
  "password": "root-password",
  "host": "localhost",
  "port": 3306
}

/opt/agent/config.json ํŒŒ์ผ์„ ๋งŒ๋“ค๊ณ  API Key์ •๋ณด๋ฅผ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.

vi /opt/agent/config.json

config.json ์˜ˆ์‹œ

{
  "APIKey": "๋ฐœ๊ธ‰๋ฐ›์€ API Key ์ž…๋ ฅ",
  "APISecret": "๋ฐœ๊ธ‰๋ฐ›์€ API Secret Key ์ž…๋ ฅ",
  "Protocol": "https",
  "Domain": "api.solapi.com",
  "Prefix": "",
  "AppId": "",
  "AllowDuplicates": true
}

Prefix, AppId๋Š” ๋น„์›Œ๋‘์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค. AllowDuplicates๊ฐ’์ด true์ด๋ฉด ๋™์‹œ๊ฐ„๋Œ€ ๊ฐ™์€ ์ˆ˜์‹ ๋ฒˆํ˜ธ๋กœ ์—ฌ๋Ÿฌ๊ฑด ๋ฐœ์†ก์ด ๊ฐ€๋Šฅํ•˜๊ณ , false์ด๋ฉด ํ•œ๊ฑด๋งŒ ๋ฐœ์†ก๋˜๊ณ  ๋‚˜๋จธ์ง€๋Š” ์ค‘๋ณต๊ฑด์œผ๋กœ ๋ฐœ์†ก ์‹คํŒจ๋ฉ๋‹ˆ๋‹ค.

์„œ๋น„์Šค ๋ฐ๋ชฌ ์‹คํ–‰

์„œ๋น„์Šค ๋ฐ๋ชฌ์„ ์‹œ์Šคํ…œ์— ๋“ฑ๋ก ๋ฐ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค. (๋ชจ๋“  ๋ช…๋ น์€ root ๊ถŒํ•œ์œผ๋กœ ์‹คํ–‰ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.)

./agent install
./agent start

๊ธฐ๋ณธ ์„ค์น˜ ๊ฒฝ๋กœ(/opt/agent)์™€ ๋‹ค๋ฅด๊ฒŒ ์„ค์น˜ํ•œ ๊ฒฝ์šฐ ์•„๋ž˜์™€ ๊ฐ™์ด AGENT_HOME ํ™˜๊ฒฝ๋ณ€์ˆ˜๋ฅผ ์„ค์ •ํ•ด ์ฃผ์„ธ์š”

export AGENT_HOME=/home/ubuntu/agent

์„œ๋น„์Šค ๋ฐ๋ชฌ ๋ช…๋ น

์‹œ์Šคํ…œ์— ๋“ฑ๋ก

./agent install

๋ฐ๋ชฌ ์‹คํ–‰

./agent start

๋ฐ๋ชฌ ์ƒํƒœ

./agent status

๋ฐ๋ชฌ ์ •์ง€

./agent stop

์‹œ์Šคํ…œ์—์„œ ์ œ๊ฑฐ

./agent remove