在Laravel 9中,我如何在生产环境中立即调度WebSocket事件?

klr1opcd  于 2023-10-20  发布在  其他
关注(0)|答案(1)|浏览(131)

我使用Laravel 9。我有一个拍卖系统。当一个用户出价时,我调度一个AuctionBidPlaced事件:

class AuctionBidPlaced implements ShouldBroadcast
{
    use Dispatchable;
    use InteractsWithSockets;
    use SerializesModels;
    use DateTrait;

    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct(
        public CommunityAuctionBid $bid,
        public ?User $user = null,
    ) {
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\Broadcasting\Channel|\Illuminate\Broadcasting\Channel[]|string[]|string
     */
    public function broadcastOn(): Channel
    {
        return new PrivateChannel($this->bid->auction->receivesBroadcastNotificationsOn());
    }

    /**
     * Get the data to broadcast.
     *
     * @return array<string, mixed>
     */
    public function broadcastWith(): array
    {
        return [
            ... some data I return ...
        ];
    }
}

我这样称呼这个事件:

AuctionBidPlaced::dispatch($bid, $previousLeadingBidUser);

dispatchNow()sync()不存在。
在我当地的环境中,它会立即起火。在生产上,有大约10秒的延迟。
我的本地QUEUE_DRIVERsync,,生产是sqs,但我不想让它排队。如何更改代码以保证即时派单?

1cklez4t

1cklez4t1#

要调用事件,请遵循以下格式:

broadcast(new AuctionBidPlaced($bid, $previousLeadingBidUser));

相关问题