Пример #1
0
func main() {
	rand.Seed(time.Now().UnixNano()) // takes the current time in nanoseconds as the seed

	var pub = os.Getenv("AWSPUB")
	var secret = os.Getenv("AWSSecret")
	auth := aws.Auth{AccessKey: pub, SecretKey: secret}
	K := kinesis.New(auth, aws.USEast)
	var wg sync.WaitGroup
	for i := 0; i < 10; i++ {
		problemMap := make(map[string]int)
		problemMap["Num1"] = rand.Intn(100)
		problemMap["Num2"] = rand.Intn(100)
		jsonData, jsonErr := json.Marshal(problemMap)
		if jsonErr != nil {
			log.Println("Error:", jsonErr)
			continue
		}
		wg.Add(1)
		go func() {
			defer wg.Done()
			_, err2 := K.PutRecord("math-problems", "math-p", jsonData, "", "")
			log.Println("[", problemMap["Num1"], ",", problemMap["Num2"], "] ...sent!")
			if err2 != nil {
				log.Println("Error:", err2)
			}
		}()
		wg.Wait()
	}
}
Пример #2
0
func main() {
	pub, secret, _ := getSettings()
	auth := aws.Auth{AccessKey: pub, SecretKey: secret}
	K := kinesis.New(auth, aws.USEast)
	tm := topicMessage{}
	tm.TopicID = 1
	tm.Message = "THIS IS THIS MESSAGE PAYLOAD THAT WILL GO TO THE USER!!!!!"

	jsonData, jsonErr := json.Marshal(&tm)
	if jsonErr != nil {
		log.Println("Error:", jsonErr)
		return
	}

	_, err := K.PutRecord("topic-message", "topic-msg", jsonData, "", "")
	if err != nil {
		log.Println("Error:", err)
	}
	log.Println("Done!")

}
Пример #3
0
func main() {
	var errIP error
	if lambdaIP, errIP = getlambdaIP(); errIP != nil {
		log.Println(errIP)
		return
	}
	pub, secret, sg, _ := getSettings()
	auth := aws.Auth{AccessKey: pub, SecretKey: secret}
	K := kinesis.New(auth, aws.USEast)
	for k, v := range os.Args {
		log.Println(k, v)
	}
	log.Println("-----")
	if len(os.Args) > 1 {
		rawData := os.Args[1]

		var kpayload KinesisPayload
		err := json.Unmarshal([]byte(rawData), &kpayload)
		if err != nil {
			log.Println("Error Kinesisis Payload:", err)
		}
		for _, v := range kpayload.Records {
			log.Println("Record:", v)
			var tm topicMessage
			sDec, errDec := base64.StdEncoding.DecodeString(v.Kinesis.Data)
			if errDec != nil {
				log.Println("Error:", errDec)
			} else {
				log.Println(string(sDec))
				errJSON := json.Unmarshal(sDec, &tm)
				if errJSON != nil {
					log.Println("Error:", errJSON)
					return
				}
				AddIPToGroup(pub, secret, sg)
				pageCount := getDevicesByTopicIDPageCount(tm.TopicID)
				RemoveIPFromGroup(pub, secret, sg)
				publishMessage("Count: 1st page sent")
				for i := 0; i < pageCount; i++ {
					tpm := topicPageMessage{}
					tpm.Message = tm.Message
					tpm.TopicID = tm.TopicID
					tpm.PageNum = i + 1
					if i+1 == pageCount {
						tpm.LastPage = true
						log.Println("LastPage is", i+1)
					}
					jsonData, jsonErr := json.Marshal(&tpm)
					if jsonErr != nil {
						log.Println("Error:", jsonErr)
						break
					}
					_, err := K.PutRecord("topic-message-page", "topic-page", jsonData, "", "")
					if tpm.LastPage {
						publishMessage(fmt.Sprintf("Count: Last Page Sent: %v", pageCount))
					}
					if err != nil {
						log.Println("Error:", err)
					}
					log.Println("Sent...", tpm)
				}
				log.Println("All done!")
			}
		}
		return

	}
	log.Println("Error: os.Args was 1 length.")
}