Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ChatGpt to message #208

Merged
merged 5 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/constant/config/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ const VideoProcessorRpcServiceName = "GuGoTik-VideoProcessorService"

const VideoPicker = "GuGoTik-VideoPicker"
const Event = "GuGoTik-Recommend"
const MsgConsumer = "GuGoTik-MgsConsumer"
3 changes: 2 additions & 1 deletion src/constant/strings/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ const (
VideoCommentEvent = "video.comment.action"
VideoPublishEvent = "video.publish.action"

MessageActionEvent = "message.send"
MessageActionEvent = "message.send"
MessageGptActionEvent = "message.gpt.send"
)
63 changes: 54 additions & 9 deletions src/services/message/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import (
"GuGoTik/src/rpc/user"
"GuGoTik/src/storage/database"
"GuGoTik/src/storage/redis"
grpc2 "GuGoTik/src/utils/grpc"
"GuGoTik/src/utils/logging"
"GuGoTik/src/utils/ptr"
"GuGoTik/src/utils/rabbitmq"
"context"
"encoding/json"
"fmt"

grpc2 "GuGoTik/src/utils/grpc"
"time"

"github.com/go-redis/redis_rate/v10"
Expand Down Expand Up @@ -79,14 +79,46 @@ func (c MessageServiceImpl) New() {

_, err = channel.QueueDeclare(
strings.MessageActionEvent,
false, false, false, false,
true, false, false, false,
nil,
)

if err != nil {
failOnError(err, "Failed to define queue")
}

_, err = channel.QueueDeclare(
strings.MessageGptActionEvent,
true, false, false, false,
nil,
)

if err != nil {
failOnError(err, "Failed to define queue")
}

err = channel.QueueBind(
strings.MessageActionEvent,
strings.MessageActionEvent,
strings.MessageExchange,
false,
nil,
)
if err != nil {
failOnError(err, "Failed to bind queue to exchange")
}

err = channel.QueueBind(
strings.MessageGptActionEvent,
strings.MessageGptActionEvent,
strings.MessageExchange,
false,
nil,
)
if err != nil {
failOnError(err, "Failed to bind queue to exchange")
}

userRpcConn := grpc2.Connect(config.UserRpcServerName)

userClient = user.NewUserServiceClient(userRpcConn)
Expand Down Expand Up @@ -359,13 +391,26 @@ func addMessage(ctx context.Context, fromUserId uint32, toUserId uint32, Context
return
}
headers := rabbitmq.InjectAMQPHeaders(ctx)
err = channel.Publish("", strings.MessageActionEvent, false, false,
amqp.Publishing{
DeliveryMode: amqp.Persistent,
ContentType: "text/plain",
Body: body,
Headers: headers,
})

if message.ToUserId == config.EnvCfg.MagicUserId {
err = channel.Publish("", strings.MessageGptActionEvent, false, false,
amqp.Publishing{
DeliveryMode: amqp.Persistent,
ContentType: "text/plain",
Body: body,
Headers: headers,
})

} else {

err = channel.Publish("", strings.MessageActionEvent, false, false,
amqp.Publishing{
DeliveryMode: amqp.Persistent,
ContentType: "text/plain",
Body: body,
Headers: headers,
})
}

// result := database.Client.WithContext(ctx).Create(&message)

Expand Down
9 changes: 5 additions & 4 deletions src/services/message/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import (
"GuGoTik/src/utils/logging"
"GuGoTik/src/utils/prom"
"context"
grpcprom "github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus"
"github.com/oklog/run"
"github.com/prometheus/client_golang/prometheus/promhttp"
"net"
"net/http"
"os"
"syscall"

grpcprom "github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus"
"github.com/oklog/run"
"github.com/prometheus/client_golang/prometheus/promhttp"

"github.com/sirupsen/logrus"
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
"google.golang.org/grpc"
Expand Down Expand Up @@ -74,7 +75,7 @@ func main() {
var probe healthImpl.ProbeImpl
chat.RegisterChatServiceServer(s, srv)
health.RegisterHealthServer(s, &probe)

defer CloseMQConn()
srv.New()
srvMetrics.InitializeMetrics(s)

Expand Down
Loading
Loading