fix
This commit is contained in:
parent
36efad44df
commit
315ad19dd4
@ -5,7 +5,7 @@ import (
|
|||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"errors"
|
"errors"
|
||||||
"fusenapi/constants"
|
"fusenapi/constants"
|
||||||
"fusenapi/server/websocket/consumer"
|
"fusenapi/utils/mq_consumer_factory"
|
||||||
"github.com/streadway/amqp"
|
"github.com/streadway/amqp"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"log"
|
"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]
|
object, ok := mapMq[queueName]
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("unknown queue")
|
panic("unknown queue")
|
||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
select {
|
select {
|
||||||
@ -135,5 +135,4 @@ func (h *RabbitMqHandle) Consume(ctx context.Context, queueName constants.RABBIT
|
|||||||
}(msg)
|
}(msg)
|
||||||
}
|
}
|
||||||
wait.Wait()
|
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:
|
Auth:
|
||||||
AccessSecret: fusen2023
|
AccessSecret: fusen2023
|
||||||
AccessExpire: 2592000
|
AccessExpire: 2592000
|
||||||
RefreshAfter: 1592000
|
RefreshAfter: 1592000
|
||||||
|
SourceRabbitMq: amqp://rabbit001:rabbit001129@110.41.19.98:5672
|
@ -2,12 +2,12 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fusenapi/server/render/internal/types"
|
"fusenapi/server/render/internal/types"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest"
|
"github.com/zeromicro/go-zero/rest"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
rest.RestConf
|
rest.RestConf
|
||||||
SourceMysql string
|
SourceMysql string
|
||||||
Auth types.Auth
|
Auth types.Auth
|
||||||
|
SourceRabbitMq string
|
||||||
}
|
}
|
||||||
|
@ -18,14 +18,16 @@ type ServiceContext struct {
|
|||||||
|
|
||||||
MysqlConn *gorm.DB
|
MysqlConn *gorm.DB
|
||||||
AllModels *gmodel.AllModelsGen
|
AllModels *gmodel.AllModelsGen
|
||||||
|
RabbitMq *initalize.RabbitMqHandle
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServiceContext(c config.Config) *ServiceContext {
|
func NewServiceContext(c config.Config) *ServiceContext {
|
||||||
|
initalize.InitRabbitMq(c.SourceRabbitMq, nil)
|
||||||
return &ServiceContext{
|
return &ServiceContext{
|
||||||
Config: c,
|
Config: c,
|
||||||
MysqlConn: initalize.InitMysql(c.SourceMysql),
|
MysqlConn: initalize.InitMysql(c.SourceMysql),
|
||||||
AllModels: gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)),
|
AllModels: gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)),
|
||||||
|
RabbitMq: initalize.InitRabbitMq(c.SourceRabbitMq, nil),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"fusenapi/constants"
|
||||||
|
"fusenapi/server/render/consumer"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -30,7 +33,11 @@ func main() {
|
|||||||
|
|
||||||
ctx := svc.NewServiceContext(c)
|
ctx := svc.NewServiceContext(c)
|
||||||
handler.RegisterHandlers(server, ctx)
|
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)
|
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
|
||||||
server.Start()
|
server.Start()
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,6 @@ package consumer
|
|||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
type MqHandle interface {
|
|
||||||
Run(data []byte) error
|
|
||||||
}
|
|
||||||
|
|
||||||
// 消费渲染结果数据
|
// 消费渲染结果数据
|
||||||
type MqConsumerRenderResult struct {
|
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…
x
Reference in New Issue
Block a user