fix
This commit is contained in:
parent
36efad44df
commit
315ad19dd4
|
@ -5,7 +5,7 @@ import (
|
|||
"crypto/tls"
|
||||
"errors"
|
||||
"fusenapi/constants"
|
||||
"fusenapi/server/websocket/consumer"
|
||||
"fusenapi/utils/mq_consumer_factory"
|
||||
"github.com/streadway/amqp"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"log"
|
||||
|
@ -84,10 +84,10 @@ func (h *RabbitMqHandle) SendMsg(queueName constants.RABBIT_MQ, message []byte)
|
|||
}
|
||||
|
||||
// 消费消息
|
||||
func (h *RabbitMqHandle) Consume(ctx context.Context, queueName constants.RABBIT_MQ, handle consumer.MqHandle) error {
|
||||
func (h *RabbitMqHandle) Consume(ctx context.Context, queueName constants.RABBIT_MQ, handle mq_consumer_factory.MqHandle) {
|
||||
object, ok := mapMq[queueName]
|
||||
if !ok {
|
||||
return errors.New("unknown queue")
|
||||
panic("unknown queue")
|
||||
}
|
||||
go func() {
|
||||
select {
|
||||
|
@ -135,5 +135,4 @@ func (h *RabbitMqHandle) Consume(ctx context.Context, queueName constants.RABBIT
|
|||
}(msg)
|
||||
}
|
||||
wait.Wait()
|
||||
return nil
|
||||
}
|
||||
|
|
12
server/render/consumer/assemble_render_data.go
Normal file
12
server/render/consumer/assemble_render_data.go
Normal file
|
@ -0,0 +1,12 @@
|
|||
package consumer
|
||||
|
||||
import "fmt"
|
||||
|
||||
// 消费渲染需要组装的数据
|
||||
type MqConsumerRenderAssemble struct {
|
||||
}
|
||||
|
||||
func (m *MqConsumerRenderAssemble) Run(data []byte) error {
|
||||
fmt.Println("收到消息:" + string(data))
|
||||
return nil
|
||||
}
|
|
@ -5,4 +5,5 @@ SourceMysql: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest
|
|||
Auth:
|
||||
AccessSecret: fusen2023
|
||||
AccessExpire: 2592000
|
||||
RefreshAfter: 1592000
|
||||
RefreshAfter: 1592000
|
||||
SourceRabbitMq: amqp://rabbit001:rabbit001129@110.41.19.98:5672
|
|
@ -2,12 +2,12 @@ package config
|
|||
|
||||
import (
|
||||
"fusenapi/server/render/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
rest.RestConf
|
||||
SourceMysql string
|
||||
Auth types.Auth
|
||||
SourceMysql string
|
||||
Auth types.Auth
|
||||
SourceRabbitMq string
|
||||
}
|
||||
|
|
|
@ -18,14 +18,16 @@ type ServiceContext struct {
|
|||
|
||||
MysqlConn *gorm.DB
|
||||
AllModels *gmodel.AllModelsGen
|
||||
RabbitMq *initalize.RabbitMqHandle
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
|
||||
initalize.InitRabbitMq(c.SourceRabbitMq, nil)
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
MysqlConn: initalize.InitMysql(c.SourceMysql),
|
||||
AllModels: gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)),
|
||||
RabbitMq: initalize.InitRabbitMq(c.SourceRabbitMq, nil),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"fusenapi/constants"
|
||||
"fusenapi/server/render/consumer"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
|
@ -30,7 +33,11 @@ func main() {
|
|||
|
||||
ctx := svc.NewServiceContext(c)
|
||||
handler.RegisterHandlers(server, ctx)
|
||||
|
||||
//消费渲染前组装数据队列
|
||||
ctx1 := context.Background()
|
||||
ctx2, cancel := context.WithCancel(ctx1)
|
||||
defer cancel()
|
||||
go ctx.RabbitMq.Consume(ctx2, constants.RABBIT_MQ_ASSEMBLE_RENDER_DATA, &consumer.MqConsumerRenderAssemble{})
|
||||
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
|
||||
server.Start()
|
||||
}
|
||||
|
|
|
@ -2,10 +2,6 @@ package consumer
|
|||
|
||||
import "fmt"
|
||||
|
||||
type MqHandle interface {
|
||||
Run(data []byte) error
|
||||
}
|
||||
|
||||
// 消费渲染结果数据
|
||||
type MqConsumerRenderResult struct {
|
||||
}
|
||||
|
|
6
utils/mq_consumer_factory/mq.go
Normal file
6
utils/mq_consumer_factory/mq.go
Normal file
|
@ -0,0 +1,6 @@
|
|||
package mq_consumer_factory
|
||||
|
||||
// 消费mq消息要实现对应Run方法
|
||||
type MqHandle interface {
|
||||
Run(data []byte) error
|
||||
}
|
Loading…
Reference in New Issue
Block a user