add: anowflake email kafka, refa: redis connectg

This commit is contained in:
wwweww
2026-02-25 01:16:13 +08:00
parent fdbcde13b2
commit 300058ad01
67 changed files with 3596 additions and 139 deletions
+33
View File
@@ -0,0 +1,33 @@
package main
import (
"flag"
"fmt"
"juwan-backend/app/email/mq/internal/config"
"juwan-backend/app/email/mq/internal/consumer"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/core/service"
)
var configFile = flag.String("f", "etc/email.yaml", "the config file")
func main() {
flag.Parse()
var c config.Config
conf.MustLoad(*configFile, &c)
if err := c.SetUp(); err != nil {
panic(err)
}
serviceGroup := service.NewServiceGroup()
defer serviceGroup.Stop()
for _, mq := range consumer.Mqs(c) {
serviceGroup.Add(mq)
}
fmt.Print("Starting email service\n")
serviceGroup.Start()
}
+18
View File
@@ -0,0 +1,18 @@
Name: email-mq
Prometheus:
Host: 0.0.0.0
Port: 4003
Path: /metrics
Kmq:
Name: email-mq
Brokers:
- my-cluster-kafka-bootstrap.kafka.svc.cluster.local:9092
Topic: email-task
Group: email-consumer-group
ForceCommit: true
CommitInOrder: false
Offset: last
Consumers: 8
Processors: 8
+11
View File
@@ -0,0 +1,11 @@
package config
import (
"github.com/zeromicro/go-queue/kq"
"github.com/zeromicro/go-zero/core/service"
)
type Config struct {
service.ServiceConf
Kmq kq.KqConf
}
@@ -0,0 +1,21 @@
package consumer
import (
"context"
"juwan-backend/app/email/mq/internal/config"
"juwan-backend/app/email/mq/internal/svc"
"github.com/zeromicro/go-zero/core/service"
)
func Mqs(c config.Config) []service.Service {
//svcContext := NewServiceContext
ctx := context.Background()
svcCtx := svc.NewServiceContext(c)
var services []service.Service
services = append(services, Kqs(ctx, c, svcCtx)...)
return services
}
+15
View File
@@ -0,0 +1,15 @@
package consumer
import (
"context"
"juwan-backend/app/email/mq/internal/config"
"juwan-backend/app/email/mq/internal/logic"
"juwan-backend/app/email/mq/internal/svc"
"github.com/zeromicro/go-queue/kq"
"github.com/zeromicro/go-zero/core/service"
)
func Kqs(ctx context.Context, c config.Config, svcCtx *svc.ServiceContext) []service.Service {
return []service.Service{kq.MustNewQueue(c.Kmq, logic.NewSendVerificationCodeMq(ctx, c, svcCtx))}
}
@@ -0,0 +1,32 @@
package logic
import (
"context"
"juwan-backend/app/email/mq/internal/config"
"juwan-backend/app/email/mq/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type SendVerificationCodeMq struct {
c config.Config
ctx context.Context
svcCxt *svc.ServiceContext
}
func NewSendVerificationCodeMq(ctx context.Context, c config.Config, svcCtx *svc.ServiceContext) *SendVerificationCodeMq {
return &SendVerificationCodeMq{
c: c,
ctx: ctx,
svcCxt: svcCtx,
}
}
func (l *SendVerificationCodeMq) Consume(ctx context.Context, key, value string) error {
_ = ctx
_ = key
_ = value
logx.Infof("Consume get message key: %s, value: %s", key, value)
return nil
}
@@ -0,0 +1,13 @@
package svc
import "juwan-backend/app/email/mq/internal/config"
type ServiceContext struct {
c config.Config
}
func NewServiceContext(c config.Config) *ServiceContext {
return &ServiceContext{
c: c,
}
}