优化结构

This commit is contained in:
Yvan
2026-08-22 11:26:58 +08:00
parent 54f76bd913
commit d987244d0e
8 changed files with 53 additions and 43 deletions
+9
View File
@@ -191,6 +191,9 @@ func (c *RabbitMQ) Publish(ctx context.Context, topic string, payload []byte, qo
if c == nil {
return ErrUnavailable
}
if ctx == nil {
ctx = context.Background()
}
if c != nil && strings.TrimSpace(topic) == "" {
topic = c.config.RoutingKey
}
@@ -231,6 +234,9 @@ func (c *RabbitMQ) Subscribe(ctx context.Context, topic string, qos byte, handle
if c == nil {
return ErrUnavailable
}
if ctx == nil {
ctx = context.Background()
}
if c != nil && strings.TrimSpace(topic) == "" {
topic = c.config.RoutingKey
}
@@ -331,6 +337,9 @@ func (c *RabbitMQ) Unsubscribe(ctx context.Context, topics ...string) error {
if c == nil {
return ErrUnavailable
}
if ctx == nil {
ctx = context.Background()
}
if len(topics) == 0 {
return errors.New("rabbitmq routing keys are empty")
}