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)
	}
}