27 lines
641 B
Go
27 lines
641 B
Go
package message
|
||
|
||
import (
|
||
"context"
|
||
"fmt"
|
||
"gateway/internal/otelTrace"
|
||
|
||
"os"
|
||
|
||
"go.uber.org/zap"
|
||
)
|
||
|
||
func SendMessage(ctx context.Context, topic, message string) {
|
||
conn := GetActiveMQConn()
|
||
if conn == nil {
|
||
otelTrace.Logger.WithContext(ctx).Error("send message get Active mq fail")
|
||
os.Exit(1)
|
||
}
|
||
err := conn.Send(topic, "text/plain", []byte(message))
|
||
|
||
if err != nil {
|
||
otelTrace.Logger.WithContext(ctx).Error("发送消息给activeMQ失败, message=", zap.String("message", message))
|
||
} else {
|
||
otelTrace.Logger.WithContext(ctx).Info(fmt.Sprintf("发送消息给activeMQ成功,message="), zap.String("message", message))
|
||
}
|
||
}
|