发布后如何在我的 Laravel 中使用我的 RabbitMQ?

问题描述 投票:0回答:0

目前在我的 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

我现在该怎么办?制作 BroadcastEventRabbitMQ 消费者脚本?我的应用程序主要是基于 API 的

laravel rabbitmq laravel-echo pusher-js
© www.soinside.com 2019 - 2024. All rights reserved.