fix: events

This commit is contained in:
Rogee
2025-01-10 11:41:49 +08:00
parent fa480d33c3
commit 312b30ce42
10 changed files with 63 additions and 56 deletions

View File

@@ -1,10 +1,11 @@
package events
package event
import (
"context"
"git.ipao.vip/rogeecn/atom/container"
"git.ipao.vip/rogeecn/atom/utils/opt"
"github.com/ThreeDotsLabs/watermill"
"github.com/ThreeDotsLabs/watermill/message"
)
@@ -46,3 +47,18 @@ func (ps *PubSub) Handle(
) {
ps.Router.AddHandler(handlerName, consumerTopic, ps.Subscriber, publisherTopic, ps.Publisher, handler)
}
// publish
func (ps *PubSub) Publish(e contracts.EventPublisher) error {
if e == nil {
return nil
}
payload, err := e.Marshal()
if err != nil {
return err
}
msg := message.NewMessage(watermill.NewUUID(), payload)
return ps.Publisher.Publish(e.Topic(), msg)
}

View File

@@ -1,4 +1,4 @@
package events
package event
import (
"github.com/ThreeDotsLabs/watermill"

View File

@@ -1,4 +1,4 @@
package events
package event
import (
"git.ipao.vip/rogeecn/atom/container"

View File

@@ -1,4 +1,4 @@
package events
package event
import (
"git.ipao.vip/rogeecn/atom/container"

View File

@@ -1,4 +1,4 @@
package events
package event
import (
"git.ipao.vip/rogeecn/atom/container"

View File

@@ -1,4 +1,4 @@
package events
package event
import (
sqlDB "database/sql"