The integration of RabbitMQ with Magento 2 is more flexible than that.
Magento 2 can launch RabbitMQ consumers in two ways:
Command-line Interface (CLI): You can manually start a RabbitMQ consumer using the command bin/magento queue:consumers:start <consumer_name>. This method allows you to run the consumer as a separate process, continuously processing messages from the queue. You can also configure the consumer to run as a daemon or within a process manager like Supervisor.
Cron: Magento 2 can also launch RabbitMQ consumers through cron, which is useful for scheduling periodic tasks. In this case, the consumer runs as a separate process for a specified time, executing the queued messages and then stopping.
In both cases, RabbitMQ functions as an intermediary message broker between the PHP/Magento code and the Magento API. Magento 2 sends tasks to RabbitMQ, which in turn manages the queue and passes the tasks to the designated consumers for processing. The consumers then make API calls to Magento 2 to execute the tasks.
So, the architecture of Magento 2's RabbitMQ integration is closer to your expectation than you initially thought. The use of cron for running consumers is just one of the available options and is not the only method for managing RabbitMQ consumers in Magento 2.
** EDIT **
The integration between Magento and RabbitMQ is established through the Advanced Message Queuing Protocol (AMQP). RabbitMQ doesn't require its own PHP interpreter; instead, it communicates with Magento through the AMQP interface.
In the context of Magento and RabbitMQ, here's how the process works:
Magento publishes messages to RabbitMQ's exchange. RabbitMQ then routes these messages to the appropriate queue based on the defined binding rules. Magento consumers are responsible for consuming messages from the queues, processing the tasks, and executing the specified PHP classes. As you've mentioned, the initialization and the real launch of consumers happen on the Magento side. Magento's PHP application is responsible for running the consumers that process the messages from RabbitMQ.
To ensure smooth communication between Magento and RabbitMQ, you need to configure the message queue settings in the env.php file and set up the appropriate exchanges, queues, and bindings in RabbitMQ.
To summarize, RabbitMQ doesn't need a PHP interpreter; it works as a message broker that routes messages between Magento and its consumers. The actual processing of tasks using the specified PHP classes happens on the Magento side.