meioa/php-mq

A library for MQ message listening and sending based on PHP AMQP extension

Maintainers

Details

github.com/cpptpp/php-mq

Source

Issues

Installs: 5

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/meioa/php-mq

v1.0.2 2025-10-14 03:45 UTC

This package is auto-updated.

Last update: 2025-11-14 03:56:17 UTC


README

A simple library for MQ message listening and sending based on PHP AMQP extension

Installation

composer require meioa/php-mq

Example

    use PhpMq\Consumer;
    use PhpMq\Producer;
    //连接配置信息
    $config = [
        'host'      => '127.0.0.1',
        'port'      => 5672,
        'login'     => 'guest',
        'password'  => 'guest',
        'vhost'     => '/',
        ];
    //定义消息处理函数
    $callback = function(AMQPEnvelope $envelope){
        var_export($envelope);
        echo PHP_EOL;
//        echo " [x] Received ", $envelope->getBody(), PHP_EOL;
//        $headers = $envelope->getHeaders();
//        echo "Headers: " . json_encode($headers) . PHP_EOL;
//        echo "Content Type: " . $envelope->getContentType() . "\n";

    };
    //监听 指定队列,处理消息
    (new Consumer($config))->run('q11',$callback);
        
    $data = ['a'=>123,'b'=>'vv'];
    //创建 指定交换机 的连接实例
    $producer = new Producer($config,'et5');
    //发送消息    
    $producer->send($data,'route');    
    //发送持久化消息 ,rabbitMq-server 重启后消息不丢失
    $producer->setDeliveryMode()->send($data,'route');    
    //向指定 header 类型交换机 发送 带有headers 参数的 消息
    $producer->send($data,'',['h'=>2]);