PHP Microservices — Video Processing With RabbitMQ

A queueing service is important for video processing because:A server has limited capacity on how many videos it can process at a timeLarge videos can take hours to process, and other videos must wait their turn until enough resources are available on the serverOther tools include ProdigyView, a toolkit for building micro applications, will be used for video conversions and downloading the file, and FFMPEG will handle the processing.Run The CodeThe code for this example is available at: With A ClientA client in this scenario is the server, ie your web server, that is going to send a message to another server to perform a task..In our example, let us imagine that when a user uploads a video to our web server, we will tell our video servers to process them.With RabbitMQ, we are going to start by setting up the client..Before you begin, you must have RabbitMQ installed and running on your system..If you have not already done this, you may do so here..After that, in our client.php we start with the following:$connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest');$channel = $connection->channel();The above small snippet sets the messaging server and the port..The code also handles authentication — the guest, guest part..Next, we setup declare a queue.$channel->queue_declare('video_processing', false, false, false, false);We have now declared a queue named ‘video_processing’ that we will send our messages too..With RabbitMQ, we can declare multiple queues (image processing, sending emails, etc) for sending messages to different locations..Now let’s create the data we want to send over..Imagine it as a user uploading a video and now we have to convert the video so it works on all devices..We can create a simple definition like below:Take note above, we are sending the URL of the video we want to process..We DO NOT want to send an actual video file because of the amount of time, server resources and blocked I/O that would take, making it very inefficient and impractical.. More details

Leave a Reply