Beispiel #1
0
/*
Takes message from a device in the form of a string. It should be formatted with JSON. It should follow the format of the structure defined in typeDefinitions
*/
func handleRepMessageEvent(pool *redis.Pool, msg []byte) {
	conn := pool.Get()

	var m common.Message //create an empty Message

	//recieve a message from a device
	if err := json.Unmarshal(msg, &m); err != nil { //unpack the message into m, check for an error
		fmt.Println(err)
	} //end if

	m.MessageID = m.GenerateMessageID(m.GenerateRefID()) //fill in the extra stuff

	//publish to the database we got an event
	if _, err := conn.Do("PUBLISH", "ASMS::Receipt::"+m.GenerateRefID()+"::message:", msg); err != nil {
		panic(err)
	} //end if
} //end handleRepMessageEvent