Beispiel #1
0
func NewApnsHttpServer(option Option) *ApnsHttpServer {

	feedbackChan := make(chan *entry.Feedback, 1000)
	var apnsClient *apns.ApnsClient
	if option.startMode == STARTMODE_MOCK {
		//初始化mock apns
		apnsClient = apns.NewMockApnsClient(option.cert,
			option.pushAddr, chan<- *entry.Feedback(feedbackChan), option.feedbackAddr, entry.NewCycleLink(3, option.storageCapacity))
		log.Info("MOCK APNS HTTPSERVER IS STARTING ....")
	} else {
		//初始化apns
		apnsClient = apns.NewDefaultApnsClient(option.cert,
			option.pushAddr, chan<- *entry.Feedback(feedbackChan), option.feedbackAddr, entry.NewCycleLink(3, option.storageCapacity))
		log.InfoLog("push_handler", "ONLINE APNS HTTPSERVER IS STARTING ....")
	}

	server := &ApnsHttpServer{feedbackChan: feedbackChan,
		apnsClient: apnsClient, expiredTime: option.expiredTime}

	//创建http
	server.httpserver = NewMomoHttpServer(option.bindAddr, nil)

	go server.dial(option.bindAddr)

	return server
}
Beispiel #2
0
func TestPoolSendMessage(t *testing.T) {
	cert, err := tls.LoadX509KeyPair(CERT_PATH, KEY_PATH)
	if nil != err {
		t.Logf("READ CERT FAIL|%s", err.Error())
		t.Fail()
		return
	}

	responseChan := make(chan *entry.Response, 10)
	feedbackChan := make(chan *entry.Feedback, 1000)

	body := "hello apns"
	payload, _ := entry.NewSimplePayLoad("ms.caf", 1, body)
	client := NewDefaultApnsClient(cert, PUSH_APPLE, feedbackChan, FEED_BACK_APPLE, entry.NewCycleLink(3, 100))
	for i := 0; i < 1; i++ {
		err := client.SendEnhancedNotification(1, math.MaxUint32, apnsToken, *payload)
		// err := client.SendSimpleNotification(apnsToken, payload)
		t.Logf("SEND NOTIFY|%s\n", err)
	}

	go func() {
		//测试feedback
		err := client.FetchFeedback(50)
		if nil != err {
			t.Logf("FETCH FEEDBACK|FAIL |%s\n", err)
		}

	}()

	for i := 0; i < 2; i++ {
		select {
		case <-time.After(20 * time.Second):
		case resp := <-responseChan:
			t.Logf("===============%t|EXIT", resp)
			//如果有返回错误则说明发送失败的
			t.Fail()
		case fb := <-feedbackChan:
			i := 0
			for i < 100 {
				t.Logf("FEEDBACK===============%s|EXIT", fb)
				i++
			}
			//如果有返回错误则说明发送失败的
		}
	}

	client.Destory() //
}
Beispiel #3
0
func main() {
	feedbackChan := make(chan *entry.Feedback, 1000)
	cert, _ := tls.LoadX509KeyPair(CERT_PATH, KEY_PATH)
	client := apns.NewMockApnsClient(cert, PUSH_APPLE, feedbackChan, FEED_BACK_APPLE, entry.NewCycleLink(3, 100000))

	payload := entry.NewSimplePayLoad("ms.caf", int(1), "hello")
	for i := 0; i < 100; i++ {
		go func(a int) {
			for j := 0; j < 1000000; j++ {
				client.SendEnhancedNotification(1, 1, apnsToken, *payload)
			}
			fmt.Printf("finish:%d\n", a)
		}(i)
	}

	select {}
}