目前在我的 Laravel 控制器中我有这个
public function store(MessageRequest $request, int $roomId) {
$user = auth()->user();
Queue::push(new SendMessageJob($chatId, $user->id, $request->message));
return response()->json(null, 200);
}
我的SendMessageJob handle()如下
public function handle(): void {
$message = RoomMessage::create([
'room_id' => $this->roomId,
'sender_id' => $this->userId,
'message' => $this->message,
]);
$connection = new AMQPStreamConnection(env('RaMQ_HOST'), env('RaMQ_PORT'), env('RaMQ_USER'), env('RaMQ_PASS'), env('RaMQ_VHOST'));
$channel = $connection->channel();
$channel->exchange_declare('rooms', 'topic', durable: true, auto_delete: true);
$channel->basic_publish(new AMQPMessage(json_encode($message)), 'rooms', this->roomId);
$channel->close();
$connection->close();
}
并成功添加消息到room.{roomId}
的Topic
从这一点上我完全迷路了。我用 Laravel Echo 和 Pusher 安装了 Soketi 并做了一个 WebSocket Server
我现在该怎么办?制作 Broadcast 或 Event 或 RabbitMQ 消费者脚本?我的应用程序主要是基于 API 的