pub.go
1.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package message
import (
"github.com/tiptok/gocomm/pkg/broker"
"github.com/tiptok/gocomm/pkg/broker/local"
"github.com/tiptok/gocomm/pkg/broker/models"
"github.com/tiptok/gocomm/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/pg"
"time"
)
func RunPublish() {
var (
err error
)
producer := broker.NewMessageProducer(
models.WithKafkaHost(KAFKA_HOSTS),
models.WithMessageProduceRepository(local.NewPgMessageProduceRepository(pg.DB, nil)),
)
for {
messages := []interface{}{
domain.Users{
Id: 20200129,
Name: "user_2020",
Phone: "18860183058",
Status: 1,
Roles: []int64{7, 8},
CreateTime: time.Now(),
UpdateTime: time.Now(),
},
}
err = producer.Publish(TOPIC_BUSSINESS_ADMIN, messages, models.WithMessageProduceRepository(local.NewPgMessageProduceRepository(pg.DB, nil)))
if err != nil {
log.Error(err)
}
log.Debug("publish :", messages)
time.Sleep(time.Hour * 24)
}
}