gorush: a push notification server written in go

104
A push notification server written in Go 1 Bo-Yi Wu Mopcon @ 2017.10.28

Upload: bo-yi-wu

Post on 22-Jan-2018

2.689 views

Category:

Technology


4 download

TRANSCRIPT

A push notification server written in Go

1

Bo-Yi WuMopcon @ 2017.10.28

Why I create the Gorush Project?

Detail implementation in Golang

Testing and deploy Go project.

Run Gorush in Kubernetes.

2

Mediatek Engineer DevOps Golang, PHP, Node.js ..

Some open source Gitea Gin Drone

appleboy @GitHub appleboy @twitter appleboy @slideshare appleboy46 @facebook

3

drone/drone go-gitea/gitea gin-gonic/gin appleboy/gorush

4

drone/drone go-gitea/gitea gin-gonic/gin appleboy/gorush

5

https://mcs.mediatek.com/6

MediatekCloud

Sandbox

Trigger

Push

Email

hook

MQTT

TCP

HTTP

7

MediatekCloud

Sandbox

Trigger

Push

Email

hook

MQTT

TCP

HTTP

8Forcus on Push notification

https://github.com/appleboy/gorush

9

A general push notification server

for smartphone application

10

Written in GoPush requests to APNs and FCMSimple HTTP APIs (JSON)RPC Protocol (gRPC)

11

Client

FCM

APNs

Gorush

POST /push

JSON Body

HTTPS

APNsProtocol

12

System RequirementGood PerformanceHigh Concurrency

Simple net/http Package

Easy to Learn

13

https://github.com/golang/go/wiki/FromXToGo

14

https://github.com/golangtw/jobs

15

16

FCM

APNs

API Server

API Server

API Server

PUSH

17

FCM

APNs

Worker

Worker

Worker

PUSHQueue

API

API

API

de-queue

Asynchronous Notification

AWSen-queue

18

NginxTraefik

FCM

APNs

Gorush

Gorush

Gorush

PUSH

API

API

API

HttpPost /push

Gorush = Queue + Worker19

How to implement simple notification service

20

Client

FCM

APNs

Gorush

POST /push

JSON Body

HTTPS

APNsProtocol

21

Http Server gRPC ServerPush API Worker

22

23

24

25

26

27

28

29

GET /api/stat/goGET /api/stat/appGET /sys/statsGET /metricsPOST /api/pushGET /healthz

30

31

32

33

34

$ for i in {1..99999}; do bat -b.N=1000 -b.C=100 POST local:8088/api/push35

36

https://github.com/appleboy/gorush/#post-apipush

37

Push API Support Sync Mode

38

Notification

Notification

Notification

Notification

worker

worker

worker

Client

Notificationworker

WaitGroup

39

Notification Log

Wait response

Send to Work Queue

40

41

$ gorush

42

$ gorush –c config.yml

43

$ GORUSH_CORE_PORT=8089 gorush

44

/etc/gorush/config.yml $HOME/.gorush/config.yml . (Current Folder)

45

Server Confg

Route Config46

Server Config

Route Config47

48

Integrate Let's Encrypt

49

https://goo.gl/pfeC5Q

50

Android Config

iOS Config

Log Config51

API Key From Request

52

53

Supports new Apple Token Based Authentication (JWT)

54

55

memory, blotdb, buntdb, leveldb, redis

56

57

58

package flg

59

60

Docker Container

61

62

$ gorush -android –m="message" -k="API Key" –t="token"

63

$ gorush -ios -m="message" -i="certificate path"

-t="token" -topic="topic"

64

write once run anywhere

65

https://github.com/mitchellh/gox

66

67

https://github.com/facebookgo/grace

68

How to resolve this problem?

69

// +build windows

https://golang.org/pkg/go/build/

70

71

72

$ docker build -t appleboy/gorush .

https://goo.gl/zQbhmu

73

74

75

Continuous Delivery system

built on container technology

76

77

Using .drone.yml file

Git Test Release Docker Notify

78

Testing Code

Analytic Code

Code Quality

Build Binary

Deploy Binary

Build Docker Image

Deploy Docker Container

Send Notification

79

Git Test Release Docker Notify

80

81

Git Test Release Docker Notify

82

Choose Image

Testing Process

83

84

85

86

87

$ coverage all

https://github.com/appleboy/golang-testing

88

Git Test Release Docker Notify

89

Choose Image

Step Name

Run on for Git tag event

90

91

92

Git Test Release Docker Notify

93

Drone Envars

Drone Secrets

Plugin Image

94

Git Test Release Docker Notify

95

Plugin Image

96

97

98

99

100

101

$ kubectl create -f k8s

$ kubectl get services

$ minikube service frontend

102

http://bit.ly/devops-drone

103

Thanks All coming.

104