This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
JISQueueing/clientServer/main.go

42 lines
729 B
Go

2020-01-31 03:24:23 +07:00
package main
import (
"encoding/json"
2020-01-31 03:24:23 +07:00
"github.com/go-redis/redis/v7"
"os/exec"
"time"
2020-01-31 03:24:23 +07:00
)
type Message struct {
ID string
Name string
Email string
}
2020-01-31 03:24:23 +07:00
func main() {
client := redis.NewClient(&redis.Options{
Addr: "10.1.3.100:6379",
Password: "",
DB: 0,
})
println("waiting for messages...")
2020-01-31 03:24:23 +07:00
channel := client.Subscribe("qq")
_, err := channel.Receive()
2020-01-31 03:24:23 +07:00
if err != nil {
panic(err)
}
for msg := range channel.Channel() {
if msg.Channel != "qq" {
return
}
bytes := []byte(msg.Payload)
var data Message
json.Unmarshal(bytes, &data)
exec.Command("./makejpg.sh", data.ID, data.Name, data.Email)
println("Printing", data.ID, data.Name, data.Email, "at", time.Now().String())
2020-01-31 03:24:23 +07:00
}
}