添加消费队列
This commit is contained in:
parent
c771e3b559
commit
a7bd832a00
6
Makefile
6
Makefile
|
@ -38,6 +38,12 @@ rpcrun:
|
|||
cd cmd/rpc && go run transfer.go
|
||||
|
||||
|
||||
.PHONY: qrun
|
||||
# 运行rpc
|
||||
qrun:
|
||||
cd cmd/rpc/queue && go run queue.go
|
||||
|
||||
|
||||
.PHONY: apirun
|
||||
# 运行rpc
|
||||
apirun:
|
||||
|
|
|
@ -2,6 +2,7 @@ package etc
|
|||
|
||||
type ExtraConfig struct {
|
||||
Nacos NacosConf
|
||||
Mq RockerMqConfig
|
||||
}
|
||||
|
||||
type NacosConf struct {
|
||||
|
@ -10,3 +11,9 @@ type NacosConf struct {
|
|||
TimeOut uint64
|
||||
ServiceName string
|
||||
}
|
||||
|
||||
type RockerMqConfig struct {
|
||||
Host []string
|
||||
GroupName string
|
||||
Topic []string
|
||||
}
|
||||
|
|
|
@ -13,4 +13,12 @@ type Config struct {
|
|||
Cache cache.CacheConf
|
||||
ZLTX types.ZLTXConf
|
||||
Market types.MarketConf
|
||||
DB struct {
|
||||
Master struct {
|
||||
DataSource string
|
||||
}
|
||||
Slave struct {
|
||||
DataSource string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,13 +2,8 @@ package logic
|
|||
|
||||
import (
|
||||
"context"
|
||||
"github.com/pkg/errors"
|
||||
"trasfer_middleware/pkg/xerr"
|
||||
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"trasfer_middleware/cmd/rpc/internal/svc"
|
||||
"trasfer_middleware/cmd/rpc/pb/transfer"
|
||||
)
|
||||
|
||||
type GetResellerByAppIdLogic struct {
|
||||
|
@ -24,13 +19,3 @@ func NewGetResellerByAppIdLogic(ctx context.Context, svcCtx *svc.ServiceContext)
|
|||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetResellerByAppIdLogic) GetResellerByAppId(in *transfer.GetResellerByAppIdReq) (*transfer.GetResellerByAppIdRes, error) {
|
||||
var res transfer.GetResellerByAppIdRes
|
||||
reseller, err := l.svcCtx.DbReseller.ResellerMerchant.FindOneByAppId(l.ctx, in.AppId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg(l.ctx, "未找到分销商信息"), "temp in : %+v", err, in.AppId)
|
||||
}
|
||||
_ = copier.Copy(&res, &reseller)
|
||||
return &res, nil
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package logic
|
|||
|
||||
import (
|
||||
"context"
|
||||
"trasfer_middleware/pkg/common"
|
||||
"trasfer_middleware/until/common"
|
||||
|
||||
"trasfer_middleware/cmd/rpc/internal/svc"
|
||||
"trasfer_middleware/cmd/rpc/pb/transfer"
|
||||
|
@ -25,7 +25,7 @@ func NewMarketKeyDiscardLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
|
|||
}
|
||||
|
||||
func (l *MarketKeyDiscardLogic) MarketKeyDiscard(in *transfer.MarketKeyDiscardReq) (*transfer.MarketKeyDiscardRes, error) {
|
||||
res, err := l.svcCtx.Market.SetData(common.StructToMap(in)).KeyDiscard()
|
||||
res, err := l.svcCtx.Market.SetData(common.StructToMap(in), &l.svcCtx.Config.Mq).KeyDiscard()
|
||||
|
||||
return res, err
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package logic
|
|||
|
||||
import (
|
||||
"context"
|
||||
"trasfer_middleware/pkg/common"
|
||||
"trasfer_middleware/until/common"
|
||||
|
||||
"trasfer_middleware/cmd/rpc/internal/svc"
|
||||
"trasfer_middleware/cmd/rpc/pb/transfer"
|
||||
|
@ -25,7 +25,6 @@ func NewMarketKeySendLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Mar
|
|||
}
|
||||
|
||||
func (l *MarketKeySendLogic) MarketKeySend(in *transfer.MarketKeySendReq) (*transfer.MarketKeySendRes, error) {
|
||||
res, err := l.svcCtx.Market.SetData(common.StructToMap(in)).KeySend()
|
||||
|
||||
res, err := l.svcCtx.Market.SetData(common.StructToMap(in), &l.svcCtx.Config.Mq).KeySend()
|
||||
return res, err
|
||||
}
|
||||
|
|
|
@ -2,10 +2,9 @@ package logic
|
|||
|
||||
import (
|
||||
"context"
|
||||
"trasfer_middleware/pkg/common"
|
||||
|
||||
"trasfer_middleware/cmd/rpc/internal/svc"
|
||||
"trasfer_middleware/cmd/rpc/pb/transfer"
|
||||
"trasfer_middleware/until/common"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
@ -25,6 +24,6 @@ func NewMarketQueryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Marke
|
|||
}
|
||||
|
||||
func (l *MarketQueryLogic) MarketQuery(in *transfer.MarketQueryReq) (*transfer.MarketQueryRes, error) {
|
||||
res, err := l.svcCtx.Market.SetData(common.StructToMap(in)).Query()
|
||||
res, err := l.svcCtx.Market.SetData(common.StructToMap(in), &l.svcCtx.Config.Mq).Query()
|
||||
return res, err
|
||||
}
|
||||
|
|
|
@ -1,12 +1,18 @@
|
|||
package market
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
"trasfer_middleware/cmd/rpc/etc"
|
||||
"trasfer_middleware/cmd/rpc/internal/logic/po/zltx/types"
|
||||
"trasfer_middleware/cmd/rpc/internal/logic/vo"
|
||||
"trasfer_middleware/cmd/rpc/pb/transfer"
|
||||
"trasfer_middleware/pkg/request"
|
||||
"trasfer_middleware/cmd/rpc/pkg/mq"
|
||||
"trasfer_middleware/until/common"
|
||||
"trasfer_middleware/until/request"
|
||||
"trasfer_middleware/until/sysLog"
|
||||
)
|
||||
|
||||
type Market struct {
|
||||
|
@ -17,6 +23,7 @@ type Market struct {
|
|||
type MarketRequest struct {
|
||||
*Market
|
||||
RequestBody map[string]string
|
||||
Config etc.RockerMqConfig
|
||||
}
|
||||
|
||||
func NewMarket(conf types.MarketConf) *Market {
|
||||
|
@ -26,9 +33,9 @@ func NewMarket(conf types.MarketConf) *Market {
|
|||
}
|
||||
}
|
||||
|
||||
func (r *Market) SetData(data map[string]interface{}) *MarketRequest {
|
||||
func (r *Market) SetData(data map[string]interface{}, config *etc.RockerMqConfig) *MarketRequest {
|
||||
|
||||
/*data["timestamp"] = time.Now().Format("20060102150405")
|
||||
data["timestamp"] = time.Now().Format("20060102150405")
|
||||
private1 := "MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQC5FGH7Tq5u7pA/eh6AjAS0InykvWDJt095go8yK3w7+TRIhSYDdbRHlTgOQm4nWuMPfz3U2Rs1vJQwyyEYdylcYJ2zFLr7Vb1BdvkJ3Kz/2yJ6sz3BNq6xAHaeCKzA/WZxnc/ypfkGlrmfr2tNqCM9CUHUWryihBjLxwRiWLmo0aKgYpKLKYNixLgyqUYAifD3APncAduv6sSjUPMTyXMOlP1DXgVwX6IaUG/yV8/56Ew72Vdi/y4qZmCKMmXq4PovWrs8ISOEuhxbfLrGWbGCAVYPq7d7XaH+AOY4dhJZm7OZ43UGWw80QKGEPkvU4Oquzu8BqBh12md7Zsd6r0XzAgMBAAECggEAcLgTPKUc437z51UOwqeELdlbJFIaYn/8LTrwz1NgpH4P86L0FeNX2sjsjPK0d8+IvmV2WO2o/r9NWbI9A9N/Iz3MjcawYmZDj11QK0t1KZZil2wWzlfpaO+pTnJmFFvASq4ceeHPms2tW63QokkmvQOoTha9EBV3rJQW/XagDEolty57kkfmB31cQHJuAt+BF5EzBqv3q3jnqhsj8J/ddT0hadyKq65u85VomLH92asu/KKMKYYXC8aHjgX48chAmQUAHGM/HCD2owLHwtei2kPWNDx85ecBsglIX3wy0yhH1dnL+o3eeskVLl89ye3QCJPHJBaNUUfbgucgWT0bsQKBgQD1pPMAe31ZXajl9WlHMtn8qhpAGzi/GiiH6YrrHMQECC2GGuAakBko1Vhc+2HU35gwlPOhwMIOCapB0cCqcZVo3+71AKo78YvZLQ7yMuSsp0/Wn2N79NZ6+++wtHGPP9eHrLuWm23l15W7W0RcQptTaQupbculMQZ8b6cAjh6d1QKBgQDA4c4Xl2ePbQdgMMOuKTPPKF3QI1VhCVtxSV+Gj9MZBZedstz9+ZO3oxHhy8D5S9it1hE6dn6/a+7OWibZ/gBr1S0+11LcwKDb7q30dimr9bQs/srIywpoIIN8wVEkX4P9JLOWgQeAtq53IMba+cElef916aqyJpXuIek9lvUQpwKBgQCD7alNMwWpf3H8v4dhY+BLoRgkIfqiOGxYQogHqhVkjPfWNIzz9zxr/9lLZv+uEsBsJzOKRjpyy6ITY5H0eLhj8REnqMnFE/+mDlsenVLPn7Rzcns90ct3leOvpdnvs7wP9CdzxdqKPPUAAQ5/9o3xiFNpFbzv5Zq0LkslMy8iWQKBgQCiRJWctUxzllcRLpVBTPqAOkaKV195zmR2rzLFQvRmZZUDH7nZlQEYCgF+Q2tqj8uPm7tMwumo4wW55pAu7witr19sMbxNaWUrAeao9kvilkfpXsV9HYv4w/m6l+xKvGyPKDRJ1u1X9Nhb8mA5UsqSW8t2CIoJbHrQJwlRPlGXmwKBgQDg4rcsM2PmShOg8lSrHXPATXiZyyqpPJLpXbV6DRKyt7U6KWjyrplQN7yOoIUgsuD2OC/q67y7w1P3OY7X0RDnMr6MtIV0JyBJHg24eyBTqeLai2DqoHlsBOSvpJDZf+g/DXCjvHMWp1h0wqdj3aLthmU0dHM/CEqr/o7d8GwrGQ=="
|
||||
p := "-----BEGIN RSA PRIVATE KEY-----\n" + private1 + "\n-----END RSA PRIVATE KEY-----"
|
||||
data["app_id"] = "2783278"
|
||||
|
@ -39,7 +46,7 @@ func (r *Market) SetData(data map[string]interface{}) *MarketRequest {
|
|||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
data["sign"] = sign*/
|
||||
data["sign"] = sign
|
||||
//data := common.MergeMaps(common.ToMap(p), common.ToMap(r), common.ToMap(e))*/
|
||||
requestBody := make(map[string]string, len(data))
|
||||
for key, value := range data {
|
||||
|
@ -48,16 +55,38 @@ func (r *Market) SetData(data map[string]interface{}) *MarketRequest {
|
|||
return &MarketRequest{
|
||||
Market: r,
|
||||
RequestBody: requestBody,
|
||||
Config: *config,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *MarketRequest) request(url string) (*request.Response, error) {
|
||||
reqInfo := make(map[string]interface{}, 4)
|
||||
reqInfo["url"] = fmt.Sprintf("%s%s", r.Conf.Host, url)
|
||||
req := request.Request{
|
||||
Method: "POST",
|
||||
Url: fmt.Sprintf("%s%s", r.Conf.Host, url),
|
||||
Url: reqInfo["url"].(string),
|
||||
Data: r.RequestBody,
|
||||
}
|
||||
resp, _ := req.Send()
|
||||
//异步存入请求记录
|
||||
reqStr, _ := json.Marshal(r.RequestBody)
|
||||
reqInfo["data"] = string(reqStr)
|
||||
reqInfo["resp"] = resp.Text
|
||||
reqInfo["code"] = resp.StatusCode
|
||||
sendMq := mq.RocketMq{}
|
||||
send, err := sendMq.Produce(r.Config.Host, r.Config.GroupName, "MARKET", reqInfo, 0)
|
||||
if err != nil {
|
||||
sysLog.ErrLog(context.Background(), err)
|
||||
} else {
|
||||
sysLog.LogMq(context.Background(), send)
|
||||
}
|
||||
/*r.Model.Insert(context.Background(), &genModel.ServerMiddleMarketLogs{
|
||||
Url : url,
|
||||
Code :int64()
|
||||
Data :string(reqStr)
|
||||
Resp :resp.Text,
|
||||
CreateTime :time.Now(),
|
||||
})*/
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"trasfer_middleware/cmd/rpc/internal/logic/po/zltx/types"
|
||||
"trasfer_middleware/cmd/rpc/internal/logic/vo"
|
||||
"trasfer_middleware/cmd/rpc/pb/transfer"
|
||||
"trasfer_middleware/pkg/request"
|
||||
"trasfer_middleware/until/request"
|
||||
)
|
||||
|
||||
type ZltxOrder struct {
|
||||
|
|
|
@ -2,7 +2,7 @@ package logic
|
|||
|
||||
import (
|
||||
"context"
|
||||
"trasfer_middleware/pkg/common"
|
||||
"trasfer_middleware/until/common"
|
||||
|
||||
"trasfer_middleware/cmd/rpc/internal/svc"
|
||||
"trasfer_middleware/cmd/rpc/pb/transfer"
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"context"
|
||||
"trasfer_middleware/cmd/rpc/internal/svc"
|
||||
"trasfer_middleware/cmd/rpc/pb/transfer"
|
||||
"trasfer_middleware/pkg/common"
|
||||
"trasfer_middleware/until/common"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
|
|
@ -2,7 +2,7 @@ package logic
|
|||
|
||||
import (
|
||||
"context"
|
||||
"trasfer_middleware/pkg/common"
|
||||
"trasfer_middleware/until/common"
|
||||
|
||||
"trasfer_middleware/cmd/rpc/internal/svc"
|
||||
"trasfer_middleware/cmd/rpc/pb/transfer"
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"context"
|
||||
"trasfer_middleware/cmd/rpc/internal/svc"
|
||||
"trasfer_middleware/cmd/rpc/pb/transfer"
|
||||
"trasfer_middleware/pkg/common"
|
||||
"trasfer_middleware/until/common"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
|
|
@ -3,7 +3,7 @@ package logic
|
|||
import (
|
||||
"context"
|
||||
"github.com/jinzhu/copier"
|
||||
"trasfer_middleware/pkg/common"
|
||||
"trasfer_middleware/until/common"
|
||||
|
||||
"trasfer_middleware/cmd/rpc/internal/svc"
|
||||
"trasfer_middleware/cmd/rpc/pb/transfer"
|
||||
|
|
|
@ -2,7 +2,7 @@ package logic
|
|||
|
||||
import (
|
||||
"context"
|
||||
"trasfer_middleware/pkg/common"
|
||||
"trasfer_middleware/until/common"
|
||||
|
||||
"trasfer_middleware/cmd/rpc/internal/svc"
|
||||
"trasfer_middleware/cmd/rpc/pb/transfer"
|
||||
|
|
|
@ -3,7 +3,7 @@ package logic
|
|||
import (
|
||||
"context"
|
||||
"github.com/jinzhu/copier"
|
||||
"trasfer_middleware/pkg/common"
|
||||
"trasfer_middleware/until/common"
|
||||
|
||||
"trasfer_middleware/cmd/rpc/internal/svc"
|
||||
"trasfer_middleware/cmd/rpc/pb/transfer"
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
package mq
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/streadway/amqp"
|
||||
"time"
|
||||
"trasfer_middleware/cmd/rpc/etc"
|
||||
"trasfer_middleware/cmd/rpc/internal/queue/mq/mqSvc"
|
||||
"trasfer_middleware/genModel"
|
||||
)
|
||||
|
||||
type Message interface {
|
||||
MessageHandler(tag uint64, ch *amqp.Channel, msg []byte) error
|
||||
}
|
||||
type Market struct {
|
||||
svc *mqSvc.ServiceContext
|
||||
ctx context.Context
|
||||
}
|
||||
type ZLTX struct {
|
||||
svc *mqSvc.ServiceContext
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
func NewMarket(svc *mqSvc.ServiceContext, ctx context.Context) *Market {
|
||||
return &Market{
|
||||
svc: svc,
|
||||
ctx: ctx,
|
||||
}
|
||||
}
|
||||
|
||||
func NewZLTX(svc *mqSvc.ServiceContext, ctx context.Context) *ZLTX {
|
||||
return &ZLTX{
|
||||
svc: svc,
|
||||
ctx: ctx,
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Market) MessageHandler(tag uint64, ch *amqp.Channel, msg []byte) error {
|
||||
var market = &genModel.ServerMiddleMarketLogs{}
|
||||
json.Unmarshal(msg, market)
|
||||
market.CreateTime = time.Now()
|
||||
_, err := m.svc.DbWrite.MarketLogs.Insert(m.ctx, market)
|
||||
if err != nil {
|
||||
return fmt.Errorf("market数据保存失败:%s,原因:%s", msg, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *ZLTX) MessageHandler(tag uint64, ch *amqp.Channel, msg []byte) error {
|
||||
var zltx = &genModel.ServerMiddleZltxLogs{}
|
||||
json.Unmarshal(msg, zltx)
|
||||
zltx.CreateTime = time.Now()
|
||||
_, err := m.svc.DbWrite.ZLTXLogs.Insert(m.ctx, zltx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("zltx数据保存失败:%s", msg)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func AllHandle(c *etc.RockerMqConfig, svc *mqSvc.ServiceContext, ctx context.Context) map[string]Message {
|
||||
result := make(map[string]Message, len(c.Topic))
|
||||
result["MARKET"] = NewMarket(svc, ctx)
|
||||
result["ZLTX"] = NewZLTX(svc, ctx)
|
||||
return result
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
package mqServer
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/apache/rocketmq-client-go/v2/consumer"
|
||||
"github.com/apache/rocketmq-client-go/v2/primitive"
|
||||
"sync"
|
||||
"trasfer_middleware/cmd/rpc/etc"
|
||||
"trasfer_middleware/cmd/rpc/internal/queue/mq"
|
||||
"trasfer_middleware/until/sysLog"
|
||||
)
|
||||
|
||||
type RocketMq struct {
|
||||
mqConfig *etc.RockerMqConfig
|
||||
}
|
||||
|
||||
func NewRocketmq(config *etc.RockerMqConfig) *RocketMq {
|
||||
return &RocketMq{
|
||||
mqConfig: config,
|
||||
}
|
||||
}
|
||||
|
||||
func (n RocketMq) Consume(handler map[string]mq.Message) error {
|
||||
c, err := consumer.NewPushConsumer(
|
||||
consumer.WithGroupName(n.mqConfig.GroupName),
|
||||
consumer.WithNsResolver(primitive.NewPassthroughResolver(n.mqConfig.Host)),
|
||||
)
|
||||
|
||||
defer c.Shutdown()
|
||||
// 设置回调函数
|
||||
if err != nil {
|
||||
return fmt.Errorf("rockmq error:%v", err)
|
||||
}
|
||||
var wg sync.WaitGroup
|
||||
|
||||
for _, topic := range n.mqConfig.Topic {
|
||||
wg.Add(1)
|
||||
go func(topic string) {
|
||||
defer wg.Done()
|
||||
err := c.Subscribe(topic,
|
||||
consumer.MessageSelector{},
|
||||
func(ctx context.Context, msgs ...*primitive.MessageExt) (consumer.ConsumeResult, error) {
|
||||
for i := range msgs {
|
||||
err = handler[topic].MessageHandler(0, nil, msgs[i].Body)
|
||||
if err != nil {
|
||||
return consumer.ConsumeRetryLater, err
|
||||
}
|
||||
}
|
||||
return consumer.ConsumeSuccess, nil
|
||||
})
|
||||
if err != nil {
|
||||
sysLog.ErrLog(context.Background(), err)
|
||||
}
|
||||
}(topic)
|
||||
}
|
||||
err = c.Start()
|
||||
if err != nil {
|
||||
sysLog.ErrLog(context.Background(), err)
|
||||
}
|
||||
select {}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package mqSvc
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"trasfer_middleware/cmd/rpc/internal/config"
|
||||
"trasfer_middleware/genModel"
|
||||
)
|
||||
|
||||
type ServiceContext struct {
|
||||
Config config.Config
|
||||
DbWrite *Model
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
DbWrite: DbModel(c.DB.Master.DataSource, c),
|
||||
}
|
||||
}
|
||||
|
||||
func DbModel(datasource string, c config.Config) *Model {
|
||||
sqlConn := sqlx.NewMysql(datasource)
|
||||
return &Model{
|
||||
MarketLogs: genModel.NewServerMiddleMarketLogsModel(sqlConn),
|
||||
ZLTXLogs: genModel.NewServerMiddleZltxLogsModel(sqlConn),
|
||||
}
|
||||
}
|
||||
|
||||
type Model struct {
|
||||
MarketLogs genModel.ServerMiddleMarketLogsModel
|
||||
ZLTXLogs genModel.ServerMiddleZltxLogsModel
|
||||
}
|
|
@ -15,6 +15,7 @@ type ServiceContext struct {
|
|||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
RedisClient: redis.MustNewRedis(redis.RedisConf{
|
||||
|
@ -27,13 +28,15 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
|||
}
|
||||
}
|
||||
|
||||
func DbModel(datasource string, c config.Config) *Model {
|
||||
//sqlConn := sqlx.NewMysql(datasource)
|
||||
/*func DbModel(datasource string, c config.Config) *Model {
|
||||
sqlConn := sqlx.NewMysql(datasource)
|
||||
return &Model{
|
||||
//ClientModel: genModel.NewServerClientModel(sqlConn, c.Cache),
|
||||
MarketLogs: genModel.NewServerMiddleMarketLogsModel(sqlConn, c.Cache),
|
||||
ZLTXLogs: genModel.NewServerMiddleZltxLogsModel(sqlConn, c.Cache),
|
||||
}
|
||||
}
|
||||
|
||||
type Model struct {
|
||||
//ClientModel genModel.ServerClientModel
|
||||
}
|
||||
MarketLogs genModel.ServerMiddleMarketLogsModel
|
||||
ZLTXLogs genModel.ServerMiddleZltxLogsModel
|
||||
}*/
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package mq
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/apache/rocketmq-client-go/v2"
|
||||
"github.com/apache/rocketmq-client-go/v2/primitive"
|
||||
"github.com/apache/rocketmq-client-go/v2/producer"
|
||||
)
|
||||
|
||||
type RocketMq struct {
|
||||
}
|
||||
|
||||
func (n RocketMq) Produce(host []string, groupName string, topic string, log interface{}, delayTime int) (string, error) {
|
||||
p, err := rocketmq.NewProducer(
|
||||
producer.WithNsResolver(primitive.NewPassthroughResolver(host)),
|
||||
producer.WithRetry(2), //指定重试次数
|
||||
producer.WithGroupName(groupName),
|
||||
)
|
||||
defer p.Shutdown()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("rockmq error:%v", err)
|
||||
}
|
||||
if err = p.Start(); err != nil {
|
||||
return "", fmt.Errorf("rockmq error:%v", err)
|
||||
}
|
||||
var body, _ = json.Marshal(log)
|
||||
// 构建一个消息
|
||||
message := primitive.NewMessage(topic, body)
|
||||
// 给message设置延迟级别
|
||||
message.WithDelayTimeLevel(delayTime)
|
||||
res, err := p.SendSync(context.Background(), message)
|
||||
if err != nil {
|
||||
fmt.Errorf("rockmq send message fail:%v", err)
|
||||
}
|
||||
|
||||
return res.String(), nil
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"github.com/zeromicro/go-zero/core/conf"
|
||||
"github.com/zeromicro/go-zero/core/service"
|
||||
"trasfer_middleware/cmd/rpc/internal/config"
|
||||
mq2 "trasfer_middleware/cmd/rpc/internal/queue/mq"
|
||||
"trasfer_middleware/cmd/rpc/internal/queue/mq/mqServer"
|
||||
"trasfer_middleware/cmd/rpc/internal/queue/mq/mqSvc"
|
||||
"trasfer_middleware/until/sysLog"
|
||||
)
|
||||
|
||||
var configFile = flag.String("f", "../../../config/transfer.yaml", "the config file")
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
var c config.Config
|
||||
conf.MustLoad(*configFile, &c)
|
||||
|
||||
svcCtx := mqSvc.NewServiceContext(c)
|
||||
ctx := context.Background()
|
||||
serviceGroup := service.NewServiceGroup()
|
||||
defer serviceGroup.Stop()
|
||||
res := mq2.AllHandle(&c.Mq, svcCtx, ctx)
|
||||
|
||||
mqSv := mqServer.NewRocketmq(&c.Mq)
|
||||
|
||||
err := mqSv.Consume(res)
|
||||
if err != nil {
|
||||
sysLog.ErrLog(ctx, err)
|
||||
panic(err)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
{"@timestamp":"2024-06-12T10:43:56.711+08:00","caller":"queue/queue.go:31","content":"errlog:%!(EXTRA []interface {}=[the topic=ZLTX route info not found, it may not exist])","level":"error"}
|
||||
{"@timestamp":"2024-06-12T10:44:29.461+08:00","caller":"queue/queue.go:31","content":"errlog:%!(EXTRA []interface {}=[the topic=ZLTX route info not found, it may not exist])","level":"error"}
|
|
@ -0,0 +1,29 @@
|
|||
package genModel
|
||||
|
||||
import "github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
|
||||
var _ ServerMiddleMarketLogsModel = (*customServerMiddleMarketLogsModel)(nil)
|
||||
|
||||
type (
|
||||
// ServerMiddleMarketLogsModel is an interface to be customized, add more methods here,
|
||||
// and implement the added methods in customServerMiddleMarketLogsModel.
|
||||
ServerMiddleMarketLogsModel interface {
|
||||
serverMiddleMarketLogsModel
|
||||
withSession(session sqlx.Session) ServerMiddleMarketLogsModel
|
||||
}
|
||||
|
||||
customServerMiddleMarketLogsModel struct {
|
||||
*defaultServerMiddleMarketLogsModel
|
||||
}
|
||||
)
|
||||
|
||||
// NewServerMiddleMarketLogsModel returns a model for the database table.
|
||||
func NewServerMiddleMarketLogsModel(conn sqlx.SqlConn) ServerMiddleMarketLogsModel {
|
||||
return &customServerMiddleMarketLogsModel{
|
||||
defaultServerMiddleMarketLogsModel: newServerMiddleMarketLogsModel(conn),
|
||||
}
|
||||
}
|
||||
|
||||
func (m *customServerMiddleMarketLogsModel) withSession(session sqlx.Session) ServerMiddleMarketLogsModel {
|
||||
return NewServerMiddleMarketLogsModel(sqlx.NewSqlConnFromSession(session))
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
// Code generated by goctl. DO NOT EDIT.
|
||||
|
||||
package genModel
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
)
|
||||
|
||||
var (
|
||||
serverMiddleMarketLogsFieldNames = builder.RawFieldNames(&ServerMiddleMarketLogs{})
|
||||
serverMiddleMarketLogsRows = strings.Join(serverMiddleMarketLogsFieldNames, ",")
|
||||
serverMiddleMarketLogsRowsExpectAutoSet = strings.Join(stringx.Remove(serverMiddleMarketLogsFieldNames, "`log_id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
||||
serverMiddleMarketLogsRowsWithPlaceHolder = strings.Join(stringx.Remove(serverMiddleMarketLogsFieldNames, "`log_id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
||||
)
|
||||
|
||||
type (
|
||||
serverMiddleMarketLogsModel interface {
|
||||
Insert(ctx context.Context, data *ServerMiddleMarketLogs) (sql.Result, error)
|
||||
FindOne(ctx context.Context, logId uint64) (*ServerMiddleMarketLogs, error)
|
||||
Update(ctx context.Context, data *ServerMiddleMarketLogs) error
|
||||
Delete(ctx context.Context, logId uint64) error
|
||||
}
|
||||
|
||||
defaultServerMiddleMarketLogsModel struct {
|
||||
conn sqlx.SqlConn
|
||||
table string
|
||||
}
|
||||
|
||||
ServerMiddleMarketLogs struct {
|
||||
LogId uint64 `db:"log_id"`
|
||||
Url string `db:"url"`
|
||||
Type string `db:"type"`
|
||||
Code int64 `db:"code"`
|
||||
Data string `db:"data"`
|
||||
Resp string `db:"resp"`
|
||||
CreateTime time.Time `db:"create_time"`
|
||||
UpdateTime time.Time `db:"update_time"`
|
||||
Status int64 `db:"status"`
|
||||
}
|
||||
)
|
||||
|
||||
func newServerMiddleMarketLogsModel(conn sqlx.SqlConn) *defaultServerMiddleMarketLogsModel {
|
||||
return &defaultServerMiddleMarketLogsModel{
|
||||
conn: conn,
|
||||
table: "`server_middle_market_logs`",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultServerMiddleMarketLogsModel) Delete(ctx context.Context, logId uint64) error {
|
||||
query := fmt.Sprintf("delete from %s where `log_id` = ?", m.table)
|
||||
_, err := m.conn.ExecCtx(ctx, query, logId)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultServerMiddleMarketLogsModel) FindOne(ctx context.Context, logId uint64) (*ServerMiddleMarketLogs, error) {
|
||||
query := fmt.Sprintf("select %s from %s where `log_id` = ? limit 1", serverMiddleMarketLogsRows, m.table)
|
||||
var resp ServerMiddleMarketLogs
|
||||
err := m.conn.QueryRowCtx(ctx, &resp, query, logId)
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlx.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultServerMiddleMarketLogsModel) Insert(ctx context.Context, data *ServerMiddleMarketLogs) (sql.Result, error) {
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?)", m.table, serverMiddleMarketLogsRowsExpectAutoSet)
|
||||
ret, err := m.conn.ExecCtx(ctx, query, data.Url, data.Type, data.Code, data.Data, data.Resp, data.Status)
|
||||
return ret, err
|
||||
}
|
||||
|
||||
func (m *defaultServerMiddleMarketLogsModel) Update(ctx context.Context, data *ServerMiddleMarketLogs) error {
|
||||
query := fmt.Sprintf("update %s set %s where `log_id` = ?", m.table, serverMiddleMarketLogsRowsWithPlaceHolder)
|
||||
_, err := m.conn.ExecCtx(ctx, query, data.Url, data.Type, data.Code, data.Data, data.Resp, data.Status, data.LogId)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultServerMiddleMarketLogsModel) tableName() string {
|
||||
return m.table
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package genModel
|
||||
|
||||
import "github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
|
||||
var _ ServerMiddleZltxLogsModel = (*customServerMiddleZltxLogsModel)(nil)
|
||||
|
||||
type (
|
||||
// ServerMiddleZltxLogsModel is an interface to be customized, add more methods here,
|
||||
// and implement the added methods in customServerMiddleZltxLogsModel.
|
||||
ServerMiddleZltxLogsModel interface {
|
||||
serverMiddleZltxLogsModel
|
||||
withSession(session sqlx.Session) ServerMiddleZltxLogsModel
|
||||
}
|
||||
|
||||
customServerMiddleZltxLogsModel struct {
|
||||
*defaultServerMiddleZltxLogsModel
|
||||
}
|
||||
)
|
||||
|
||||
// NewServerMiddleZltxLogsModel returns a model for the database table.
|
||||
func NewServerMiddleZltxLogsModel(conn sqlx.SqlConn) ServerMiddleZltxLogsModel {
|
||||
return &customServerMiddleZltxLogsModel{
|
||||
defaultServerMiddleZltxLogsModel: newServerMiddleZltxLogsModel(conn),
|
||||
}
|
||||
}
|
||||
|
||||
func (m *customServerMiddleZltxLogsModel) withSession(session sqlx.Session) ServerMiddleZltxLogsModel {
|
||||
return NewServerMiddleZltxLogsModel(sqlx.NewSqlConnFromSession(session))
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
// Code generated by goctl. DO NOT EDIT.
|
||||
|
||||
package genModel
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
)
|
||||
|
||||
var (
|
||||
serverMiddleZltxLogsFieldNames = builder.RawFieldNames(&ServerMiddleZltxLogs{})
|
||||
serverMiddleZltxLogsRows = strings.Join(serverMiddleZltxLogsFieldNames, ",")
|
||||
serverMiddleZltxLogsRowsExpectAutoSet = strings.Join(stringx.Remove(serverMiddleZltxLogsFieldNames, "`log_id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
||||
serverMiddleZltxLogsRowsWithPlaceHolder = strings.Join(stringx.Remove(serverMiddleZltxLogsFieldNames, "`log_id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
||||
)
|
||||
|
||||
type (
|
||||
serverMiddleZltxLogsModel interface {
|
||||
Insert(ctx context.Context, data *ServerMiddleZltxLogs) (sql.Result, error)
|
||||
FindOne(ctx context.Context, logId uint64) (*ServerMiddleZltxLogs, error)
|
||||
Update(ctx context.Context, data *ServerMiddleZltxLogs) error
|
||||
Delete(ctx context.Context, logId uint64) error
|
||||
}
|
||||
|
||||
defaultServerMiddleZltxLogsModel struct {
|
||||
conn sqlx.SqlConn
|
||||
table string
|
||||
}
|
||||
|
||||
ServerMiddleZltxLogs struct {
|
||||
LogId uint64 `db:"log_id"`
|
||||
Url string `db:"url"`
|
||||
Code int64 `db:"code"`
|
||||
Data string `db:"data"`
|
||||
Resp string `db:"resp"`
|
||||
CreateTime time.Time `db:"create_time"`
|
||||
UpdateTime time.Time `db:"update_time"`
|
||||
Status int64 `db:"status"`
|
||||
}
|
||||
)
|
||||
|
||||
func newServerMiddleZltxLogsModel(conn sqlx.SqlConn) *defaultServerMiddleZltxLogsModel {
|
||||
return &defaultServerMiddleZltxLogsModel{
|
||||
conn: conn,
|
||||
table: "`server_middle_zltx_logs`",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultServerMiddleZltxLogsModel) Delete(ctx context.Context, logId uint64) error {
|
||||
query := fmt.Sprintf("delete from %s where `log_id` = ?", m.table)
|
||||
_, err := m.conn.ExecCtx(ctx, query, logId)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultServerMiddleZltxLogsModel) FindOne(ctx context.Context, logId uint64) (*ServerMiddleZltxLogs, error) {
|
||||
query := fmt.Sprintf("select %s from %s where `log_id` = ? limit 1", serverMiddleZltxLogsRows, m.table)
|
||||
var resp ServerMiddleZltxLogs
|
||||
err := m.conn.QueryRowCtx(ctx, &resp, query, logId)
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlx.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultServerMiddleZltxLogsModel) Insert(ctx context.Context, data *ServerMiddleZltxLogs) (sql.Result, error) {
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?)", m.table, serverMiddleZltxLogsRowsExpectAutoSet)
|
||||
ret, err := m.conn.ExecCtx(ctx, query, data.Url, data.Code, data.Data, data.Resp, data.Status)
|
||||
return ret, err
|
||||
}
|
||||
|
||||
func (m *defaultServerMiddleZltxLogsModel) Update(ctx context.Context, data *ServerMiddleZltxLogs) error {
|
||||
query := fmt.Sprintf("update %s set %s where `log_id` = ?", m.table, serverMiddleZltxLogsRowsWithPlaceHolder)
|
||||
_, err := m.conn.ExecCtx(ctx, query, data.Url, data.Code, data.Data, data.Resp, data.Status, data.LogId)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultServerMiddleZltxLogsModel) tableName() string {
|
||||
return m.table
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package genModel
|
||||
|
||||
import "github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
|
||||
var ErrNotFound = sqlx.ErrNotFound
|
40
go.mod
40
go.mod
|
@ -3,6 +3,13 @@ module trasfer_middleware
|
|||
go 1.21
|
||||
|
||||
require (
|
||||
gitee.com/chengdu_blue_brothers/openapi-go-sdk v0.0.2
|
||||
github.com/apache/rocketmq-client-go/v2 v2.1.2
|
||||
github.com/jinzhu/copier v0.4.0
|
||||
github.com/nacos-group/nacos-sdk-go/v2 v2.2.3
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/qit-team/snow-core v0.1.29
|
||||
github.com/streadway/amqp v1.1.0
|
||||
github.com/zeromicro/go-zero v1.6.5
|
||||
github.com/zeromicro/zero-contrib/zrpc/registry/nacos v0.0.0-20231030135404-af9ae855016f
|
||||
google.golang.org/grpc v1.63.2
|
||||
|
@ -14,20 +21,32 @@ require (
|
|||
github.com/aliyun/alibaba-cloud-sdk-go v1.61.1704 // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/buger/jsonparser v1.1.1 // indirect
|
||||
github.com/bytedance/sonic v1.10.2 // indirect
|
||||
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.2.0 // indirect
|
||||
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
|
||||
github.com/chenzhuoyu/iasm v0.9.1 // indirect
|
||||
github.com/coreos/go-semver v0.3.1 // indirect
|
||||
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
|
||||
github.com/emirpasic/gods v1.18.1 // indirect
|
||||
github.com/fatih/color v1.16.0 // indirect
|
||||
github.com/fvbock/endless v0.0.0-20170109170031-447134032cb6 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
|
||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||
github.com/gin-gonic/gin v1.9.1 // indirect
|
||||
github.com/go-logr/logr v1.3.0 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/go-openapi/jsonpointer v0.19.6 // indirect
|
||||
github.com/go-openapi/jsonreference v0.20.2 // indirect
|
||||
github.com/go-openapi/swag v0.22.4 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/go-playground/validator/v10 v10.14.1 // indirect
|
||||
github.com/go-sql-driver/mysql v1.8.1 // indirect
|
||||
github.com/goccy/go-json v0.10.2 // indirect
|
||||
github.com/gogo/protobuf v1.3.2 // indirect
|
||||
github.com/golang/mock v1.6.0 // indirect
|
||||
github.com/golang/protobuf v1.5.4 // indirect
|
||||
|
@ -36,10 +55,11 @@ require (
|
|||
github.com/google/gofuzz v1.2.0 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0 // indirect
|
||||
github.com/jinzhu/copier v0.4.0 // indirect
|
||||
github.com/jmespath/go-jmespath v0.4.0 // indirect
|
||||
github.com/josharian/intern v1.0.0 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.2.6 // indirect
|
||||
github.com/leodido/go-urn v1.2.4 // indirect
|
||||
github.com/mailru/easyjson v0.7.7 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
|
@ -47,16 +67,23 @@ require (
|
|||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
||||
github.com/nacos-group/nacos-sdk-go/v2 v2.2.3 // indirect
|
||||
github.com/openzipkin/zipkin-go v0.4.2 // indirect
|
||||
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/prometheus/client_golang v1.18.0 // indirect
|
||||
github.com/prometheus/client_model v0.5.0 // indirect
|
||||
github.com/prometheus/common v0.45.0 // indirect
|
||||
github.com/prometheus/procfs v0.12.0 // indirect
|
||||
github.com/qit-team/work v0.3.11 // indirect
|
||||
github.com/redis/go-redis/v9 v9.4.0 // indirect
|
||||
github.com/robfig/cron v1.2.0 // indirect
|
||||
github.com/sirupsen/logrus v1.9.3 // indirect
|
||||
github.com/spaolacci/murmur3 v1.1.0 // indirect
|
||||
github.com/tidwall/gjson v1.15.0 // indirect
|
||||
github.com/tidwall/match v1.1.1 // indirect
|
||||
github.com/tidwall/pretty v1.2.1 // indirect
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||
github.com/ugorji/go/codec v1.2.11 // indirect
|
||||
go.etcd.io/etcd/api/v3 v3.5.13 // indirect
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.13 // indirect
|
||||
go.etcd.io/etcd/client/v3 v3.5.13 // indirect
|
||||
|
@ -71,10 +98,12 @@ require (
|
|||
go.opentelemetry.io/otel/sdk v1.19.0 // indirect
|
||||
go.opentelemetry.io/otel/trace v1.19.0 // indirect
|
||||
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
|
||||
go.uber.org/atomic v1.10.0 // indirect
|
||||
go.uber.org/atomic v1.11.0 // indirect
|
||||
go.uber.org/automaxprocs v1.5.3 // indirect
|
||||
go.uber.org/multierr v1.9.0 // indirect
|
||||
go.uber.org/zap v1.24.0 // indirect
|
||||
golang.org/x/arch v0.6.0 // indirect
|
||||
golang.org/x/crypto v0.23.0 // indirect
|
||||
golang.org/x/net v0.25.0 // indirect
|
||||
golang.org/x/oauth2 v0.17.0 // indirect
|
||||
golang.org/x/sync v0.6.0 // indirect
|
||||
|
@ -88,7 +117,7 @@ require (
|
|||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect
|
||||
gopkg.in/inf.v0 v0.9.1 // indirect
|
||||
gopkg.in/ini.v1 v1.66.2 // indirect
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
k8s.io/api v0.29.3 // indirect
|
||||
|
@ -100,4 +129,5 @@ require (
|
|||
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
|
||||
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
|
||||
sigs.k8s.io/yaml v1.3.0 // indirect
|
||||
stathat.com/c/consistent v1.0.0 // indirect
|
||||
)
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
{"@timestamp":"2024-06-12T10:39:16.749+08:00","caller":"market/market.go:95","content":"mq:[SendResult [sendStatus=0, msgIds=AC1A15CC3879000000003aef38200001, offsetMsgId=C0A86E5D00002A9F000000000000EB1E, queueOffset=8, messageQueue=MessageQueue [topic=MARKET, brokerName=broker-a, queueId=1]]]","level":"info"}
|
||||
{"@timestamp":"2024-06-12T10:41:25.182+08:00","caller":"market/market.go:95","content":"mq:[SendResult [sendStatus=0, msgIds=AC1A15CC3879000000003af130080002, offsetMsgId=C0A86E5D00002A9F000000000000F380, queueOffset=9, messageQueue=MessageQueue [topic=MARKET, brokerName=broker-a, queueId=1]]]","level":"info"}
|
||||
{"@timestamp":"2024-06-12T10:41:34.998+08:00","caller":"market/market.go:95","content":"mq:[SendResult [sendStatus=0, msgIds=AC1A15CC3879000000003af153300003, offsetMsgId=C0A86E5D00002A9F000000000000F766, queueOffset=10, messageQueue=MessageQueue [topic=MARKET, brokerName=broker-a, queueId=1]]]","level":"info"}
|
||||
{"@timestamp":"2024-06-12T10:41:35.768+08:00","caller":"market/market.go:95","content":"mq:[SendResult [sendStatus=0, msgIds=AC1A15CC3879000000003af157180004, offsetMsgId=C0A86E5D00002A9F000000000000FB4C, queueOffset=11, messageQueue=MessageQueue [topic=MARKET, brokerName=broker-a, queueId=1]]]","level":"info"}
|
||||
{"@timestamp":"2024-06-12T10:41:36.456+08:00","caller":"market/market.go:95","content":"mq:[SendResult [sendStatus=0, msgIds=AC1A15CC3879000000003af15b000005, offsetMsgId=C0A86E5D00002A9F000000000000FF32, queueOffset=12, messageQueue=MessageQueue [topic=MARKET, brokerName=broker-a, queueId=1]]]","level":"info"}
|
||||
{"@timestamp":"2024-06-12T10:41:37.195+08:00","caller":"market/market.go:95","content":"mq:[SendResult [sendStatus=0, msgIds=AC1A15CC3879000000003af15ee80006, offsetMsgId=C0A86E5D00002A9F0000000000010318, queueOffset=13, messageQueue=MessageQueue [topic=MARKET, brokerName=broker-a, queueId=1]]]","level":"info"}
|
||||
{"@timestamp":"2024-06-12T10:41:37.735+08:00","caller":"market/market.go:95","content":"mq:[SendResult [sendStatus=0, msgIds=AC1A15CC3879000000003af15ee80007, offsetMsgId=C0A86E5D00002A9F00000000000106FE, queueOffset=14, messageQueue=MessageQueue [topic=MARKET, brokerName=broker-a, queueId=1]]]","level":"info"}
|
||||
{"@timestamp":"2024-06-12T10:41:38.383+08:00","caller":"market/market.go:95","content":"mq:[SendResult [sendStatus=0, msgIds=AC1A15CC3879000000003af162d00008, offsetMsgId=C0A86E5D00002A9F0000000000010AE4, queueOffset=15, messageQueue=MessageQueue [topic=MARKET, brokerName=broker-a, queueId=1]]]","level":"info"}
|
||||
{"@timestamp":"2024-06-12T10:41:38.992+08:00","caller":"market/market.go:95","content":"mq:[SendResult [sendStatus=0, msgIds=AC1A15CC3879000000003af162d00009, offsetMsgId=C0A86E5D00002A9F0000000000010ECA, queueOffset=16, messageQueue=MessageQueue [topic=MARKET, brokerName=broker-a, queueId=1]]]","level":"info"}
|
||||
{"@timestamp":"2024-06-12T10:41:39.515+08:00","caller":"market/market.go:95","content":"mq:[SendResult [sendStatus=0, msgIds=AC1A15CC3879000000003af166b8000a, offsetMsgId=C0A86E5D00002A9F00000000000112B0, queueOffset=17, messageQueue=MessageQueue [topic=MARKET, brokerName=broker-a, queueId=1]]]","level":"info"}
|
||||
{"@timestamp":"2024-06-12T10:41:40.147+08:00","caller":"market/market.go:95","content":"mq:[SendResult [sendStatus=0, msgIds=AC1A15CC3879000000003af16aa0000b, offsetMsgId=C0A86E5D00002A9F0000000000011B13, queueOffset=18, messageQueue=MessageQueue [topic=MARKET, brokerName=broker-a, queueId=1]]]","level":"info"}
|
||||
{"@timestamp":"2024-06-12T10:41:40.687+08:00","caller":"market/market.go:95","content":"mq:[SendResult [sendStatus=0, msgIds=AC1A15CC3879000000003af16aa0000c, offsetMsgId=C0A86E5D00002A9F0000000000011EF9, queueOffset=19, messageQueue=MessageQueue [topic=MARKET, brokerName=broker-a, queueId=1]]]","level":"info"}
|
||||
{"@timestamp":"2024-06-12T10:41:41.310+08:00","caller":"market/market.go:95","content":"mq:[SendResult [sendStatus=0, msgIds=AC1A15CC3879000000003af16e88000d, offsetMsgId=C0A86E5D00002A9F00000000000122DF, queueOffset=20, messageQueue=MessageQueue [topic=MARKET, brokerName=broker-a, queueId=1]]]","level":"info"}
|
||||
{"@timestamp":"2024-06-12T10:41:41.851+08:00","caller":"market/market.go:95","content":"mq:[SendResult [sendStatus=0, msgIds=AC1A15CC3879000000003af16e88000e, offsetMsgId=C0A86E5D00002A9F00000000000126C5, queueOffset=21, messageQueue=MessageQueue [topic=MARKET, brokerName=broker-a, queueId=1]]]","level":"info"}
|
||||
{"@timestamp":"2024-06-12T10:44:00.912+08:00","caller":"market/market.go:95","content":"mq:[SendResult [sendStatus=0, msgIds=AC1A15CC3879000000003af38d80000f, offsetMsgId=C0A86E5D00002A9F0000000000012AAB, queueOffset=22, messageQueue=MessageQueue [topic=MARKET, brokerName=broker-a, queueId=1]]]","level":"info"}
|
||||
{"@timestamp":"2024-06-12T10:49:45.709+08:00","caller":"market/market.go:95","content":"mq:[SendResult [sendStatus=0, msgIds=AC1A15CC3879000000003af8d1280010, offsetMsgId=C0A86E5D00002A9F0000000000012E91, queueOffset=23, messageQueue=MessageQueue [topic=MARKET, brokerName=broker-a, queueId=1]]]","level":"info"}
|
||||
{"@timestamp":"2024-06-12T13:33:05.542+08:00","caller":"market/market.go:95","content":"mq:[SendResult [sendStatus=0, msgIds=AC1A15CC3879000000003b8e5a680011, offsetMsgId=C0A86E5D00002A9F0000000000013277, queueOffset=24, messageQueue=MessageQueue [topic=MARKET, brokerName=broker-a, queueId=1]]]","level":"info"}
|
|
@ -3,7 +3,7 @@ package test
|
|||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"trasfer_middleware/pkg/request"
|
||||
"trasfer_middleware/until/request"
|
||||
)
|
||||
|
||||
// 发送GET 请求
|
|
@ -1,10 +1,11 @@
|
|||
package pkg
|
||||
package sysLog
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -24,6 +25,35 @@ func ErrLog(ctx context.Context, errContent ...any) {
|
|||
logx.WithContext(ctx).WithCallerSkip(2).Errorf("errlog:", errContent)
|
||||
}
|
||||
|
||||
func LogMq(ctx context.Context, content ...any) {
|
||||
path, _ := logMqPath()
|
||||
// 创建一个文件对象
|
||||
file, err := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
// 创建一个日志写入器,将日志写入文件
|
||||
writer := logx.NewWriter(file)
|
||||
// 使用该写入器记录日志
|
||||
logx.SetWriter(writer)
|
||||
logx.WithContext(ctx).WithCallerSkip(2).Info("mq:", content)
|
||||
}
|
||||
|
||||
func logMqPath() (string, error) {
|
||||
logPath, err := runtimePath()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
path := fmt.Sprintf("%s/%s", logPath, "mq")
|
||||
err = CheckDir(path)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return fmt.Sprintf("%s/%s", path, time.Now().Format(time.DateOnly)), nil
|
||||
}
|
||||
|
||||
func errLogFile() (string, error) {
|
||||
logPath, err := runtimePath()
|
||||
if err != nil {
|
||||
|
@ -39,7 +69,7 @@ func errLogFile() (string, error) {
|
|||
|
||||
func runtimePath() (string, error) {
|
||||
path, err := os.Getwd()
|
||||
return fmt.Sprintf("../%s/%s", path, "runtime"), err
|
||||
return fmt.Sprintf("%s/%s/", filepath.Dir(filepath.Dir(path)), "runtime"), err
|
||||
}
|
||||
|
||||
func CheckDir(path string) error {
|
|
@ -3,7 +3,7 @@ package xerr
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
pkg "trasfer_middleware/pkg/log"
|
||||
"trasfer_middleware/until/sysLog"
|
||||
)
|
||||
|
||||
/**
|
||||
|
@ -37,6 +37,6 @@ func NewErrCode(errCode uint32) *CodeError {
|
|||
}
|
||||
|
||||
func NewErrMsg(ctx context.Context, errMsg string) *CodeError {
|
||||
pkg.ErrLog(ctx, errMsg)
|
||||
sysLog.ErrLog(ctx, errMsg)
|
||||
return &CodeError{errCode: SERVER_COMMON_ERROR, errMsg: errMsg}
|
||||
}
|
Loading…
Reference in New Issue