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

Gorush: A push notification server written in Go

Jan 22, 2018

Download

Technology

Bo-Yi Wu
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Gorush: A push notification server written in Go

A push notification server written in Go

1

Bo-Yi WuMopcon @ 2017.10.28

Page 2: Gorush: A push notification server written in Go

Why I create the Gorush Project?

Detail implementation in Golang

Testing and deploy Go project.

Run Gorush in Kubernetes.

2

Page 3: Gorush: A push notification server written in Go

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

Some open source Gitea Gin Drone

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

3

Page 4: Gorush: A push notification server written in Go

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

4

Page 5: Gorush: A push notification server written in Go

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

5

Page 6: Gorush: A push notification server written in Go

https://mcs.mediatek.com/6

Page 7: Gorush: A push notification server written in Go

MediatekCloud

Sandbox

Trigger

Push

Email

hook

MQTT

TCP

HTTP

7

Page 8: Gorush: A push notification server written in Go

MediatekCloud

Sandbox

Trigger

Push

Email

hook

MQTT

TCP

HTTP

8Forcus on Push notification

Page 9: Gorush: A push notification server written in Go

https://github.com/appleboy/gorush

9

Page 10: Gorush: A push notification server written in Go

A general push notification server

for smartphone application

10

Page 11: Gorush: A push notification server written in Go

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

11

Page 12: Gorush: A push notification server written in Go

Client

FCM

APNs

Gorush

POST /push

JSON Body

HTTPS

APNsProtocol

12

Page 13: Gorush: A push notification server written in Go

System RequirementGood PerformanceHigh Concurrency

Simple net/http Package

Easy to Learn

13

Page 14: Gorush: A push notification server written in Go

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

14

Page 15: Gorush: A push notification server written in Go

https://github.com/golangtw/jobs

15

Page 16: Gorush: A push notification server written in Go

16

Page 17: Gorush: A push notification server written in Go

FCM

APNs

API Server

API Server

API Server

PUSH

17

Page 18: Gorush: A push notification server written in Go

FCM

APNs

Worker

Worker

Worker

PUSHQueue

API

API

API

de-queue

Asynchronous Notification

AWSen-queue

18

Page 19: Gorush: A push notification server written in Go

NginxTraefik

FCM

APNs

Gorush

Gorush

Gorush

PUSH

API

API

API

HttpPost /push

Gorush = Queue + Worker19

Page 20: Gorush: A push notification server written in Go

How to implement simple notification service

20

Page 21: Gorush: A push notification server written in Go

Client

FCM

APNs

Gorush

POST /push

JSON Body

HTTPS

APNsProtocol

21

Page 22: Gorush: A push notification server written in Go

Http Server gRPC ServerPush API Worker

22

Page 23: Gorush: A push notification server written in Go

23

Page 24: Gorush: A push notification server written in Go

24

Page 25: Gorush: A push notification server written in Go

25

Page 26: Gorush: A push notification server written in Go

26

Page 27: Gorush: A push notification server written in Go

27

Page 28: Gorush: A push notification server written in Go

28

Page 29: Gorush: A push notification server written in Go

29

Page 30: Gorush: A push notification server written in Go

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

30

Page 31: Gorush: A push notification server written in Go

31

Page 32: Gorush: A push notification server written in Go

32

Page 33: Gorush: A push notification server written in Go

33

Page 34: Gorush: A push notification server written in Go

34

Page 35: Gorush: A push notification server written in Go

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

Page 36: Gorush: A push notification server written in Go

36

Page 37: Gorush: A push notification server written in Go

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

37

Page 38: Gorush: A push notification server written in Go

Push API Support Sync Mode

38

Page 39: Gorush: A push notification server written in Go

Notification

Notification

Notification

Notification

worker

worker

worker

Client

Notificationworker

WaitGroup

39

Page 40: Gorush: A push notification server written in Go

Notification Log

Wait response

Send to Work Queue

40

Page 41: Gorush: A push notification server written in Go

41

Page 42: Gorush: A push notification server written in Go

$ gorush

42

Page 43: Gorush: A push notification server written in Go

$ gorush –c config.yml

43

Page 44: Gorush: A push notification server written in Go

$ GORUSH_CORE_PORT=8089 gorush

44

Page 45: Gorush: A push notification server written in Go

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

45

Page 46: Gorush: A push notification server written in Go

Server Confg

Route Config46

Page 47: Gorush: A push notification server written in Go

Server Config

Route Config47

Page 48: Gorush: A push notification server written in Go

48

Integrate Let's Encrypt

Page 49: Gorush: A push notification server written in Go

49

Page 50: Gorush: A push notification server written in Go

https://goo.gl/pfeC5Q

50

Page 51: Gorush: A push notification server written in Go

Android Config

iOS Config

Log Config51

Page 52: Gorush: A push notification server written in Go

API Key From Request

52

Page 53: Gorush: A push notification server written in Go

53

Supports new Apple Token Based Authentication (JWT)

Page 54: Gorush: A push notification server written in Go

54

Page 55: Gorush: A push notification server written in Go

55

Page 56: Gorush: A push notification server written in Go

memory, blotdb, buntdb, leveldb, redis

56

Page 57: Gorush: A push notification server written in Go

57

Page 58: Gorush: A push notification server written in Go

58

Page 59: Gorush: A push notification server written in Go

package flg

59

Page 60: Gorush: A push notification server written in Go

60

Page 61: Gorush: A push notification server written in Go

Docker Container

61

Page 62: Gorush: A push notification server written in Go

62

Page 63: Gorush: A push notification server written in Go

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

63

Page 64: Gorush: A push notification server written in Go

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

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

64

Page 65: Gorush: A push notification server written in Go

write once run anywhere

65

Page 66: Gorush: A push notification server written in Go

https://github.com/mitchellh/gox

66

Page 67: Gorush: A push notification server written in Go

67

Page 68: Gorush: A push notification server written in Go

https://github.com/facebookgo/grace

68

Page 69: Gorush: A push notification server written in Go

How to resolve this problem?

69

Page 70: Gorush: A push notification server written in Go

// +build windows

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

70

Page 71: Gorush: A push notification server written in Go

71

Page 72: Gorush: A push notification server written in Go

72

Page 73: Gorush: A push notification server written in Go

$ docker build -t appleboy/gorush .

https://goo.gl/zQbhmu

73

Page 74: Gorush: A push notification server written in Go

74

Page 75: Gorush: A push notification server written in Go

75

Page 76: Gorush: A push notification server written in Go

Continuous Delivery system

built on container technology

76

Page 77: Gorush: A push notification server written in Go

77

Using .drone.yml file

Page 78: Gorush: A push notification server written in Go

Git Test Release Docker Notify

78

Page 79: Gorush: A push notification server written in Go

Testing Code

Analytic Code

Code Quality

Build Binary

Deploy Binary

Build Docker Image

Deploy Docker Container

Send Notification

79

Page 80: Gorush: A push notification server written in Go

Git Test Release Docker Notify

80

Page 81: Gorush: A push notification server written in Go

81

Page 82: Gorush: A push notification server written in Go

Git Test Release Docker Notify

82

Page 83: Gorush: A push notification server written in Go

Choose Image

Testing Process

83

Page 84: Gorush: A push notification server written in Go

84

Page 85: Gorush: A push notification server written in Go

85

Page 86: Gorush: A push notification server written in Go

86

Page 87: Gorush: A push notification server written in Go

87

Page 88: Gorush: A push notification server written in Go

$ coverage all

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

88

Page 89: Gorush: A push notification server written in Go

Git Test Release Docker Notify

89

Page 90: Gorush: A push notification server written in Go

Choose Image

Step Name

Run on for Git tag event

90

Page 91: Gorush: A push notification server written in Go

91

Page 92: Gorush: A push notification server written in Go

92

Page 93: Gorush: A push notification server written in Go

Git Test Release Docker Notify

93

Page 94: Gorush: A push notification server written in Go

Drone Envars

Drone Secrets

Plugin Image

94

Page 95: Gorush: A push notification server written in Go

Git Test Release Docker Notify

95

Page 96: Gorush: A push notification server written in Go

Plugin Image

96

Page 97: Gorush: A push notification server written in Go

97

Page 98: Gorush: A push notification server written in Go

98

Page 99: Gorush: A push notification server written in Go

99

Page 100: Gorush: A push notification server written in Go

100

Page 101: Gorush: A push notification server written in Go

101

Page 102: Gorush: A push notification server written in Go

$ kubectl create -f k8s

$ kubectl get services

$ minikube service frontend

102

Page 103: Gorush: A push notification server written in Go

http://bit.ly/devops-drone

103

Page 104: Gorush: A push notification server written in Go

Thanks All coming.

104