Skip to content

Commit

Permalink
fix: simulator
Browse files Browse the repository at this point in the history
  • Loading branch information
saitofun committed Jul 19, 2024
1 parent 9fef77a commit bb4595c
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions cmd/simulator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func Main() error {
return nil
}

clients := make([]string, 0, len(config.Devices)*2)
clients := make([]*confmqtt.Client, 0, len(config.Devices)*2)

for _, imei := range config.Devices {
go func(imei string) {
Expand All @@ -69,8 +69,8 @@ func Main() error {
signal.Notify(sig, os.Interrupt)
_ = <-sig

for _, clientID := range clients {
config.MqttBroker.CloseByClientID(clientID)
for _, c := range clients {
config.MqttBroker.Close(c)
}

return nil
Expand All @@ -83,16 +83,16 @@ func main() {
os.Exit(-1)
}

func PubSubQuery(imei string) []string {
func PubSubQuery(imei string) []*confmqtt.Client {
broker := config.MqttBroker
logger := config.Logger
clients := make([]string, 2)
clients := make([]*confmqtt.Client, 2)

{
topic := "backend/+/status"
client, err := broker.NewClient("sub_backend_status_simulator", topic)
must.NoErrorWrap(err, "failed to new sub mqtt client: [topic %s]", topic)
clients[1] = client.ID()
clients[1] = client
sequence := 0
err = client.Subscribe(func(_ mqtt.Client, message mqtt.Message) {
if parts := strings.Split(message.Topic(), "/"); len(parts) != 3 || parts[1] != imei {
Expand Down Expand Up @@ -127,7 +127,7 @@ func PubSubQuery(imei string) []string {
client, err := broker.NewClient(imei+"_"+uuid.NewString(), topic)
must.NoErrorWrap(err, "failed to new pub mqtt client: [topic %s]", topic)

clients[0] = client.ID()
clients[0] = client
logger.Info("publishing started", "topic", topic)
sequence := 0
for {
Expand Down

0 comments on commit bb4595c

Please sign in to comment.