Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop
This commit is contained in:
commit
0900329979
|
@ -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"
|
||||||
|
|
||||||
|
@ -29,8 +32,12 @@ func main() {
|
||||||
defer server.Stop()
|
defer server.Stop()
|
||||||
|
|
||||||
ctx := svc.NewServiceContext(c)
|
ctx := svc.NewServiceContext(c)
|
||||||
|
//消费渲染前组装数据队列
|
||||||
|
ctx1 := context.Background()
|
||||||
|
ctx2, cancel := context.WithCancel(ctx1)
|
||||||
|
defer cancel()
|
||||||
|
go ctx.RabbitMq.Consume(ctx2, constants.RABBIT_MQ_ASSEMBLE_RENDER_DATA, &consumer.MqConsumerRenderAssemble{})
|
||||||
handler.RegisterHandlers(server, ctx)
|
handler.RegisterHandlers(server, ctx)
|
||||||
|
|
||||||
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 {
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,11 +22,6 @@ type renderImageControlChanItem struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 渲染发送到组装数据组装数据
|
// 渲染发送到组装数据组装数据
|
||||||
type assembleRenderData struct {
|
|
||||||
TaskId string `json:"task_id"`
|
|
||||||
RenderData interface{} `json:"render_data"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *wsConnectItem) assembleRenderData(data []byte) {
|
func (w *wsConnectItem) assembleRenderData(data []byte) {
|
||||||
var renderImageData websocket_data.RenderImageReqMsg
|
var renderImageData websocket_data.RenderImageReqMsg
|
||||||
if err := json.Unmarshal(data, &renderImageData); err != nil {
|
if err := json.Unmarshal(data, &renderImageData); err != nil {
|
||||||
|
@ -42,7 +37,7 @@ func (w *wsConnectItem) assembleRenderData(data []byte) {
|
||||||
TaskId: taskId,
|
TaskId: taskId,
|
||||||
RenderId: renderImageData.RenderId,
|
RenderId: renderImageData.RenderId,
|
||||||
}
|
}
|
||||||
tmpData := assembleRenderData{
|
tmpData := websocket_data.AssembleRenderData{
|
||||||
TaskId: taskId,
|
TaskId: taskId,
|
||||||
RenderData: renderImageData.RenderData,
|
RenderData: renderImageData.RenderData,
|
||||||
}
|
}
|
||||||
|
|
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
|
||||||
|
}
|
|
@ -19,3 +19,9 @@ type ThirdPartyLoginRspMsg struct {
|
||||||
//websocket三方登录的通知数据
|
//websocket三方登录的通知数据
|
||||||
Token string `json:"token"`
|
Token string `json:"token"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 发送到渲染组装的mq数据
|
||||||
|
type AssembleRenderData struct {
|
||||||
|
TaskId string `json:"task_id"`
|
||||||
|
RenderData interface{} `json:"render_data"`
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user