69 lines
2.4 KiB
Go
69 lines
2.4 KiB
Go
// Package integration 定义 room-service 到外部服务的接口边界。
|
|
package integration
|
|
|
|
import (
|
|
"context"
|
|
|
|
"google.golang.org/grpc"
|
|
roomeventsv1 "hyapp/api/proto/events/room/v1"
|
|
imv1 "hyapp/api/proto/im/v1"
|
|
walletv1 "hyapp/api/proto/wallet/v1"
|
|
)
|
|
|
|
// grpcWalletClient 是 WalletClient 的 gRPC 实现。
|
|
type grpcWalletClient struct {
|
|
// client 是 protobuf 生成的 wallet-service client。
|
|
client walletv1.WalletServiceClient
|
|
}
|
|
|
|
// NewGRPCWalletClient 用 gRPC 连接创建 wallet-service 客户端。
|
|
func NewGRPCWalletClient(conn *grpc.ClientConn) WalletClient {
|
|
return &grpcWalletClient{
|
|
client: walletv1.NewWalletServiceClient(conn),
|
|
}
|
|
}
|
|
|
|
// DebitGift 直接转调 wallet-service gRPC 接口。
|
|
func (c *grpcWalletClient) DebitGift(ctx context.Context, req *walletv1.DebitGiftRequest) (*walletv1.DebitGiftResponse, error) {
|
|
// 这里不吞错,账务失败必须原样阻断 SendGift 房间状态变更。
|
|
return c.client.DebitGift(ctx, req)
|
|
}
|
|
|
|
// grpcRoomEventPublisher 是 room-service 到 im-service RoomBridgeService 的 gRPC 实现。
|
|
type grpcRoomEventPublisher struct {
|
|
// client 是 protobuf 生成的 im-service room bridge client。
|
|
client imv1.RoomBridgeServiceClient
|
|
}
|
|
|
|
// NewGRPCRoomEventPublisher 用 gRPC 连接创建 im-service 同步广播客户端。
|
|
func NewGRPCRoomEventPublisher(conn *grpc.ClientConn) RoomEventPublisher {
|
|
return &grpcRoomEventPublisher{
|
|
client: imv1.NewRoomBridgeServiceClient(conn),
|
|
}
|
|
}
|
|
|
|
// PublishRoomEvent 把房间系统事件同步推给 im-service。
|
|
func (p *grpcRoomEventPublisher) PublishRoomEvent(ctx context.Context, event *imv1.RoomEvent) error {
|
|
// 同步广播失败由 room-service 上层忽略,后续 outbox worker 负责补偿。
|
|
_, err := p.client.PublishRoomEvent(ctx, &imv1.PublishRoomEventRequest{
|
|
Event: event,
|
|
})
|
|
|
|
return err
|
|
}
|
|
|
|
// noopOutboxPublisher 是首版异步 outbox 消费占位实现。
|
|
type noopOutboxPublisher struct{}
|
|
|
|
// NewNoopOutboxPublisher 返回一个占位 outbox 发布器。
|
|
// 目前 compose 版本只把同步 room->im 打通,异步活动消费仍保留占位。
|
|
func NewNoopOutboxPublisher() OutboxPublisher {
|
|
return noopOutboxPublisher{}
|
|
}
|
|
|
|
// PublishOutboxEvent 直接吞掉 outbox 事件。
|
|
func (noopOutboxPublisher) PublishOutboxEvent(context.Context, *roomeventsv1.EventEnvelope) error {
|
|
// 当前本地版本先保留 outbox 表和 worker 语义,真正 MQ/activity 投递后续替换该实现。
|
|
return nil
|
|
}
|