first commit
This commit is contained in:
12
apps/mqs/internal/config/config.go
Normal file
12
apps/mqs/internal/config/config.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-queue/kq"
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
rest.RestConf
|
||||
KqConsumerLog kq.KqConf
|
||||
KqConsumerCharge kq.KqConf
|
||||
}
|
||||
24
apps/mqs/internal/mqs/apirequest/charge.go
Normal file
24
apps/mqs/internal/mqs/apirequest/charge.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package apirequest
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"tianyuan-api/apps/mqs/internal/svc"
|
||||
)
|
||||
|
||||
type Charge struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewCharge(ctx context.Context, svcCtx *svc.ServiceContext) *Charge {
|
||||
return &Charge{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *Charge) Consume(ctx context.Context, key, val string) error {
|
||||
logx.Infof("Charge key :%s , val :%s", key, val)
|
||||
return nil
|
||||
}
|
||||
24
apps/mqs/internal/mqs/apirequest/log.go
Normal file
24
apps/mqs/internal/mqs/apirequest/log.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package apirequest
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"tianyuan-api/apps/mqs/internal/svc"
|
||||
)
|
||||
|
||||
type Log struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewLog(ctx context.Context, svcCtx *svc.ServiceContext) *Log {
|
||||
return &Log{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *Log) Consume(ctx context.Context, key, val string) error {
|
||||
logx.Infof("log key :%s , val :%s", key, val)
|
||||
return nil
|
||||
}
|
||||
18
apps/mqs/internal/mqs/mqs.go
Normal file
18
apps/mqs/internal/mqs/mqs.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package mqs
|
||||
|
||||
import (
|
||||
"context"
|
||||
"tianyuan-api/apps/mqs/internal/config"
|
||||
"tianyuan-api/apps/mqs/internal/mqs/apirequest"
|
||||
"tianyuan-api/apps/mqs/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-queue/kq"
|
||||
"github.com/zeromicro/go-zero/core/service"
|
||||
)
|
||||
|
||||
func Consumers(c config.Config, ctx context.Context, svcContext *svc.ServiceContext) []service.Service {
|
||||
return []service.Service{
|
||||
kq.MustNewQueue(c.KqConsumerLog, apirequest.NewLog(ctx, svcContext)),
|
||||
kq.MustNewQueue(c.KqConsumerCharge, apirequest.NewCharge(ctx, svcContext)),
|
||||
}
|
||||
}
|
||||
13
apps/mqs/internal/svc/servicecontext.go
Normal file
13
apps/mqs/internal/svc/servicecontext.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package svc
|
||||
|
||||
import "tianyuan-api/apps/mqs/internal/config"
|
||||
|
||||
type ServiceContext struct {
|
||||
Config config.Config
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user