Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
longpi1 committed May 10, 2024
1 parent 197b1a6 commit cbf9127
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 72 deletions.
15 changes: 13 additions & 2 deletions comment/comment-job/conf/dev/web.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,19 @@ redis:
addr: 127.0.0.1:6379
db: 0
password: ""
local_cache:
eviction_time: 10
#消息队列
queue:
topicName: "comment-job"
config:
switch: true # 队列开关,可选:true|false,默认为true
retry: 2 # 重试次数,仅rocketmq支持
groupName: "comment-job" # mq群组名称
#磁盘队列
kafka:
address: "127.0.0.1:9092" # kafka地址+端口
version: "2.0.0.0" # kafka专属配置,默认2.0.0.0
randClient: true # 开启随机生成clientID,可以实现启动多实例同时一起消费相同topic,加速消费能力的特性,默认为true
multiConsumer: true # 是否支持创建多个消费者
app:
port: 8888
debug: true
Expand Down
26 changes: 24 additions & 2 deletions comment/comment-job/job/comment/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package comment
import (
"comment-job/libary/conf"
"context"
"encoding/json"

service_queue "comment-job/model/service/queue"

"github.com/longpi1/gopkg/libary/queue"
)
Expand All @@ -12,12 +15,31 @@ var commentQueue = CommentQueue{}
type CommentQueue struct {
}

type CommentInfo struct {
CommentId int64 // 评论id
ResourceId int64 // 评论所关联的资源id
ResourceTitle string // 资源的title
Content string // 文本信息
ContentMeta string // 存储一些关键的附属信息
ContentRich string
Pid int64 // 父评论 ID
Ext string // 额外信息存储
IP string
IPArea string
UserID int64 // 发表者id
UserName string // 发表者名称
}

func (queue CommentQueue) GetTopic() string {
topicName := conf.GetConfig().QueueConfig.TopicName
return topicName
}

func (queue CommentQueue) Handle(ctx context.Context, msg queue.Msg) (err error) {
// todo
return err
var commentInfo CommentInfo
if err = json.Unmarshal(msg.Body, &commentInfo); err != nil {
return err
}

return service_queue.UpdateComment(commentInfo)
}
26 changes: 2 additions & 24 deletions comment/comment-job/libary/conf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,38 +41,16 @@ type WebConfig struct {
Password string `json:"password"`
} `json:"redis" mapstructure:"redis"`
QueueConfig struct {
TopicName string `json:"topic_name"`
TopicName string `json:"topicName"`
Config queue.Config `json:"config"`
} `json:"comment" mapstructure:"comment"`
} `json:"queue" mapstructure:"queue"`
AppConfig struct {
Port string `json:"port"`
Debug bool `json:"debug"`
LogFilePath string `json:"log_path" mapstructure:"log_path"`
} `json:"app" mapstructure:"app"`
}

type RocketConf struct {
Address []string `json:"address"`
LogLevel string `json:"logLevel"`
}

type PulsarConf struct {
Address []string `json:"address"`
LogLevel string `json:"logLevel"`
}

type KafkaConf struct {
Address []string `json:"address"`
Version string `json:"version"`
RandClient bool `json:"randClient"`
MultiConsumer bool `json:"multiConsumer"`
}

type MapConfig struct {
TypeMap map[string]int `json:"type_map" mapstructure:"type_map"`
PlatformMap map[string]int `json:"platform_map" mapstructure:"platform_map"`
}

func GetConfig() *WebConfig {
if conf == nil {
filePath := getFilePath()
Expand Down
38 changes: 0 additions & 38 deletions comment/comment-job/main.go

This file was deleted.

2 changes: 1 addition & 1 deletion comment/comment-job/model/dao/db/model/comment_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func DeleteChildCommentsWithTx(tx *gorm.DB, commentID uint) error {
// 遍历子评论
for _, childComment := range childComments {
// 删除子评论的内容
if err := DeleteCommentContentWithTx(tx, childComment.ID); err != nil {
if err := DeleteCommentContentWithTx(tx, int64(childComment.ID)); err != nil {
return err
}

Expand Down
31 changes: 31 additions & 0 deletions comment/comment-job/model/dao/db/model/comment_response.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package model

type CommentResponse struct {
CommentId uint // 评论id
ResourceId uint // 评论所关联的资源id
ResourceTitle string // 资源的title
Content string // 文本信息
ContentMeta string // 存储一些关键的附属信息
ContentRich string
Pid uint // 父评论 ID
Ext string // 额外信息存储
IP string
IPArea string
UserID uint // 发表者id
UserName string // 发表者名称
Type uint // 评论类型,文字评论、图评等
IsCollapsed bool // 折叠
IsPending bool // 待审
IsPinned bool // 置顶
State uint // 状态
LikeCount uint // 点赞数
HateCount uint // 点踩数
ReplyCount uint // 回复数

FloorCount uint // 评论层数
}

type CommentListResponse struct {
CommentResponses []CommentResponse
RootReplyCount uint // 根评论回复数
}
17 changes: 12 additions & 5 deletions comment/comment-job/model/service/queue/update_comment.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
package queue

import "comment-job/libary/event"
import (
"comment-job/job/comment"
"comment-job/libary/event"
)

func UpdateComment() {
// 发送事件
func UpdateComment(commentInfo comment.CommentInfo) error {
// todo redis相关更新操作

// 发送事件,进行后置更新,消息通知等行为
event.Send(event.CommentUpdateEvent{
UserId: userId,
CommentId: comment.Id,
UserId: commentInfo.UserID,
ResourceId: commentInfo.ResourceId,
CommentId: commentInfo.CommentId,
})
return nil
}

0 comments on commit cbf9127

Please sign in to comment.