From b8d5be205a30700988b149fe0fe6ab92551ac25d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=97=E5=B1=B1=E5=90=B4=E5=BD=A6=E7=A5=96?= Date: Sat, 22 Dec 2018 11:51:35 +0800 Subject: [PATCH] init --- .gitignore | 8 + README.md | 1 + composer.json | 27 + composer.lock | 1680 +++++++++++++++++++++++++++++ example/db.php | 12 + example/rabbitConsumeExample.php | 77 ++ example/rabbitProducerExample.php | 22 + example/server.php | 10 + example/worker.mq.php | 15 + phpunit.xml | 23 + src/Consumer/Rabbit.php | 268 +++++ src/ConsumerInterface.php | 38 + src/Exception.php | 10 + src/Master.php | 66 ++ src/Producer/Rabbit.php | 100 ++ src/ProducerInterface.php | 33 + tests/MasterTest.php | 9 + tests/bootstrap.php | 2 + tests/db.php | 12 + tests/server.php | 10 + tests/worker.mq.php | 15 + 21 files changed, 2438 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 composer.json create mode 100644 composer.lock create mode 100644 example/db.php create mode 100644 example/rabbitConsumeExample.php create mode 100644 example/rabbitProducerExample.php create mode 100644 example/server.php create mode 100644 example/worker.mq.php create mode 100644 phpunit.xml create mode 100644 src/Consumer/Rabbit.php create mode 100644 src/ConsumerInterface.php create mode 100644 src/Exception.php create mode 100644 src/Master.php create mode 100644 src/Producer/Rabbit.php create mode 100644 src/ProducerInterface.php create mode 100644 tests/MasterTest.php create mode 100644 tests/bootstrap.php create mode 100644 tests/db.php create mode 100644 tests/server.php create mode 100644 tests/worker.mq.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7686503 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +.* +!.gitignore +.idea/ +*.log +nbproject/ +.htaccess +vendor/ +Vagrantfile \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ + diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..94c38f5 --- /dev/null +++ b/composer.json @@ -0,0 +1,27 @@ +{ + "name": "bee-framework/mq", + "description": "Bee框架MQ组件", + "require": { + "php": "^7.1", + "ext-swoole": "^4.0", + "ext-amqp": "*", + "bee-framework/util": "^1.0", + "bee-framework/process": "^1.0", + "bee-framework/serialize": "^1.0" + }, + "require-dev": { + "phalcon/ide-stubs": "*", + "eaglewu/swoole-ide-helper": "master-dev", + "phpunit/phpunit": "^7.4" + }, + "autoload": { + "psr-4": { + "Bee\\Mq\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "Bee\\Mq\\Test\\": "tests/" + } + } +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..a982ea3 --- /dev/null +++ b/composer.lock @@ -0,0 +1,1680 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "content-hash": "5fd2ca57ae9c74c91b0e4b89fcf6bc0f", + "packages": [ + { + "name": "adhocore/cli", + "version": "0.3.2", + "source": { + "type": "git", + "url": "https://github.com/adhocore/php-cli.git", + "reference": "9dbab2581b1797b9b37caf83102ec0335e046f7d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/adhocore/php-cli/zipball/9dbab2581b1797b9b37caf83102ec0335e046f7d", + "reference": "9dbab2581b1797b9b37caf83102ec0335e046f7d", + "shasum": "" + }, + "require": { + "php": ">=7.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Ahc\\Cli\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jitendra Adhikari", + "email": "jiten.adhikary@gmail.com" + } + ], + "description": "Command line interface library for PHP", + "keywords": [ + "PHP7", + "argument-parser", + "argv-parser", + "cli", + "cli-action", + "cli-app", + "cli-color", + "cli-option", + "cli-writer", + "command", + "console", + "console-app", + "php-cli", + "stream-input", + "stream-output" + ], + "time": "2018-09-06T15:32:22+00:00" + }, + { + "name": "bee-framework/process", + "version": "v1.0.14", + "source": { + "type": "git", + "url": "https://github.com/Anoxia/bee-process.git", + "reference": "3fb6375e199a263a310a67b110da0a9b5bf6acfe" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Anoxia/bee-process/zipball/3fb6375e199a263a310a67b110da0a9b5bf6acfe", + "reference": "3fb6375e199a263a310a67b110da0a9b5bf6acfe", + "shasum": "" + }, + "require": { + "adhocore/cli": "^0.3.2", + "bee-framework/util": "^1.0", + "ext-igbinary": "*", + "ext-inotify": "^2.0.0", + "ext-pcntl": "*", + "ext-swoole": "^4.1.0", + "php": "^7.1" + }, + "require-dev": { + "eaglewu/swoole-ide-helper": "master-dev" + }, + "type": "library", + "autoload": { + "psr-4": { + "Bee\\Process\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "authors": [ + { + "name": "南山吴彦祖", + "email": "anoxia@engineer.com" + } + ], + "description": "Bee框架进程组件", + "time": "2018-11-07T11:24:17+00:00" + }, + { + "name": "bee-framework/serialize", + "version": "v1.0.1", + "source": { + "type": "git", + "url": "https://github.com/Anoxia/bee-serialize.git", + "reference": "6df85c1f72cf0013bd65774dbda14a01b0874e21" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Anoxia/bee-serialize/zipball/6df85c1f72cf0013bd65774dbda14a01b0874e21", + "reference": "6df85c1f72cf0013bd65774dbda14a01b0874e21", + "shasum": "" + }, + "require": { + "bee-framework/util": "^1.0" + }, + "require-dev": { + "phpunit/phpunit": "^7.4" + }, + "type": "library", + "autoload": { + "psr-4": { + "Bee\\Serialize\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "description": "Bee框架序列化组件", + "time": "2018-11-07T02:52:15+00:00" + }, + { + "name": "bee-framework/util", + "version": "v1.0.0", + "source": { + "type": "git", + "url": "https://github.com/Anoxia/bee-util.git", + "reference": "dceb0117962de995e92a28ddb94a5c38a58a2876" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Anoxia/bee-util/zipball/dceb0117962de995e92a28ddb94a5c38a58a2876", + "reference": "dceb0117962de995e92a28ddb94a5c38a58a2876", + "shasum": "" + }, + "require": { + "ext-inotify": "*", + "ext-phalcon": "^3.2.0" + }, + "require-dev": { + "phalcon/ide-stubs": "*", + "phpunit/phpunit": "^7.2" + }, + "type": "library", + "autoload": { + "psr-4": { + "Bee\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "description": "Bee框架通用类库", + "time": "2018-10-11T15:02:17+00:00" + } + ], + "packages-dev": [ + { + "name": "doctrine/instantiator", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/instantiator.git", + "reference": "185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda", + "reference": "185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda", + "shasum": "" + }, + "require": { + "php": "^7.1" + }, + "require-dev": { + "athletic/athletic": "~0.1.8", + "ext-pdo": "*", + "ext-phar": "*", + "phpunit/phpunit": "^6.2.3", + "squizlabs/php_codesniffer": "^3.0.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com", + "homepage": "http://ocramius.github.com/" + } + ], + "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", + "homepage": "https://github.com/doctrine/instantiator", + "keywords": [ + "constructor", + "instantiate" + ], + "time": "2017-07-22T11:58:36+00:00" + }, + { + "name": "eaglewu/swoole-ide-helper", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/wudi/swoole-ide-helper.git", + "reference": "d5ba04bca84302713dc4ae288dcdf11febb82d35" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/wudi/swoole-ide-helper/zipball/d5ba04bca84302713dc4ae288dcdf11febb82d35", + "reference": "d5ba04bca84302713dc4ae288dcdf11febb82d35", + "shasum": "" + }, + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "eagle", + "email": "eaglewudi@gmail.com", + "role": "lead" + } + ], + "description": "Swoole IDE Helper, to improve auto-completion", + "keywords": [ + "autocomplete", + "codeintel", + "helper", + "ide", + "netbeans", + "phpdoc", + "phpstorm", + "sublime", + "swoole" + ], + "time": "2018-10-25T04:44:48+00:00" + }, + { + "name": "myclabs/deep-copy", + "version": "1.8.1", + "source": { + "type": "git", + "url": "https://github.com/myclabs/DeepCopy.git", + "reference": "3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8", + "reference": "3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8", + "shasum": "" + }, + "require": { + "php": "^7.1" + }, + "replace": { + "myclabs/deep-copy": "self.version" + }, + "require-dev": { + "doctrine/collections": "^1.0", + "doctrine/common": "^2.6", + "phpunit/phpunit": "^7.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "DeepCopy\\": "src/DeepCopy/" + }, + "files": [ + "src/DeepCopy/deep_copy.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Create deep copies (clones) of your objects", + "keywords": [ + "clone", + "copy", + "duplicate", + "object", + "object graph" + ], + "time": "2018-06-11T23:09:50+00:00" + }, + { + "name": "phalcon/ide-stubs", + "version": "v3.4.2", + "source": { + "type": "git", + "url": "https://github.com/phalcon/ide-stubs.git", + "reference": "48e7920621dd2086efe39ab1d52aa9b2e1b8dca0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phalcon/ide-stubs/zipball/48e7920621dd2086efe39ab1d52aa9b2e1b8dca0", + "reference": "48e7920621dd2086efe39ab1d52aa9b2e1b8dca0", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Phalcon Team", + "email": "team@phalconphp.com", + "homepage": "https://phalconphp.com/en/team" + }, + { + "name": "Contributors", + "homepage": "https://github.com/phalcon/ide-stubs/graphs/contributors" + } + ], + "description": "The most complete Phalcon Framework IDE stubs library which enables autocompletion in modern IDEs.", + "homepage": "https://phalconphp.com", + "keywords": [ + "Devtools", + "Eclipse", + "autocomplete", + "ide", + "netbeans", + "phalcon", + "phpstorm", + "stub", + "stubs" + ], + "time": "2018-09-18T18:54:45+00:00" + }, + { + "name": "phar-io/manifest", + "version": "1.0.3", + "source": { + "type": "git", + "url": "https://github.com/phar-io/manifest.git", + "reference": "7761fcacf03b4d4f16e7ccb606d4879ca431fcf4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phar-io/manifest/zipball/7761fcacf03b4d4f16e7ccb606d4879ca431fcf4", + "reference": "7761fcacf03b4d4f16e7ccb606d4879ca431fcf4", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-phar": "*", + "phar-io/version": "^2.0", + "php": "^5.6 || ^7.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + }, + { + "name": "Sebastian Heuer", + "email": "sebastian@phpeople.de", + "role": "Developer" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "Developer" + } + ], + "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", + "time": "2018-07-08T19:23:20+00:00" + }, + { + "name": "phar-io/version", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/phar-io/version.git", + "reference": "45a2ec53a73c70ce41d55cedef9063630abaf1b6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phar-io/version/zipball/45a2ec53a73c70ce41d55cedef9063630abaf1b6", + "reference": "45a2ec53a73c70ce41d55cedef9063630abaf1b6", + "shasum": "" + }, + "require": { + "php": "^5.6 || ^7.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + }, + { + "name": "Sebastian Heuer", + "email": "sebastian@phpeople.de", + "role": "Developer" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "Developer" + } + ], + "description": "Library for handling version information and constraints", + "time": "2018-07-08T19:19:57+00:00" + }, + { + "name": "phpdocumentor/reflection-common", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionCommon.git", + "reference": "21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6", + "reference": "21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6", + "shasum": "" + }, + "require": { + "php": ">=5.5" + }, + "require-dev": { + "phpunit/phpunit": "^4.6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jaap van Otterdijk", + "email": "opensource@ijaap.nl" + } + ], + "description": "Common reflection classes used by phpdocumentor to reflect the code structure", + "homepage": "http://www.phpdoc.org", + "keywords": [ + "FQSEN", + "phpDocumentor", + "phpdoc", + "reflection", + "static analysis" + ], + "time": "2017-09-11T18:02:19+00:00" + }, + { + "name": "phpdocumentor/reflection-docblock", + "version": "4.3.0", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", + "reference": "94fd0001232e47129dd3504189fa1c7225010d08" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/94fd0001232e47129dd3504189fa1c7225010d08", + "reference": "94fd0001232e47129dd3504189fa1c7225010d08", + "shasum": "" + }, + "require": { + "php": "^7.0", + "phpdocumentor/reflection-common": "^1.0.0", + "phpdocumentor/type-resolver": "^0.4.0", + "webmozart/assert": "^1.0" + }, + "require-dev": { + "doctrine/instantiator": "~1.0.5", + "mockery/mockery": "^1.0", + "phpunit/phpunit": "^6.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "me@mikevanriel.com" + } + ], + "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", + "time": "2017-11-30T07:14:17+00:00" + }, + { + "name": "phpdocumentor/type-resolver", + "version": "0.4.0", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/TypeResolver.git", + "reference": "9c977708995954784726e25d0cd1dddf4e65b0f7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/9c977708995954784726e25d0cd1dddf4e65b0f7", + "reference": "9c977708995954784726e25d0cd1dddf4e65b0f7", + "shasum": "" + }, + "require": { + "php": "^5.5 || ^7.0", + "phpdocumentor/reflection-common": "^1.0" + }, + "require-dev": { + "mockery/mockery": "^0.9.4", + "phpunit/phpunit": "^5.2||^4.8.24" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "me@mikevanriel.com" + } + ], + "time": "2017-07-14T14:27:02+00:00" + }, + { + "name": "phpspec/prophecy", + "version": "1.8.0", + "source": { + "type": "git", + "url": "https://github.com/phpspec/prophecy.git", + "reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/4ba436b55987b4bf311cb7c6ba82aa528aac0a06", + "reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "^1.0.2", + "php": "^5.3|^7.0", + "phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0", + "sebastian/comparator": "^1.1|^2.0|^3.0", + "sebastian/recursion-context": "^1.0|^2.0|^3.0" + }, + "require-dev": { + "phpspec/phpspec": "^2.5|^3.2", + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5 || ^7.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.8.x-dev" + } + }, + "autoload": { + "psr-0": { + "Prophecy\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Konstantin Kudryashov", + "email": "ever.zet@gmail.com", + "homepage": "http://everzet.com" + }, + { + "name": "Marcello Duarte", + "email": "marcello.duarte@gmail.com" + } + ], + "description": "Highly opinionated mocking framework for PHP 5.3+", + "homepage": "https://github.com/phpspec/prophecy", + "keywords": [ + "Double", + "Dummy", + "fake", + "mock", + "spy", + "stub" + ], + "time": "2018-08-05T17:53:17+00:00" + }, + { + "name": "phpunit/php-code-coverage", + "version": "6.1.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "807e6013b00af69b6c5d9ceb4282d0393dbb9d8d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/807e6013b00af69b6c5d9ceb4282d0393dbb9d8d", + "reference": "807e6013b00af69b6c5d9ceb4282d0393dbb9d8d", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-xmlwriter": "*", + "php": "^7.1", + "phpunit/php-file-iterator": "^2.0", + "phpunit/php-text-template": "^1.2.1", + "phpunit/php-token-stream": "^3.0", + "sebastian/code-unit-reverse-lookup": "^1.0.1", + "sebastian/environment": "^3.1 || ^4.0", + "sebastian/version": "^2.0.1", + "theseer/tokenizer": "^1.1" + }, + "require-dev": { + "phpunit/phpunit": "^7.0" + }, + "suggest": { + "ext-xdebug": "^2.6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "6.1-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", + "homepage": "https://github.com/sebastianbergmann/php-code-coverage", + "keywords": [ + "coverage", + "testing", + "xunit" + ], + "time": "2018-10-31T16:06:48+00:00" + }, + { + "name": "phpunit/php-file-iterator", + "version": "2.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-file-iterator.git", + "reference": "050bedf145a257b1ff02746c31894800e5122946" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/050bedf145a257b1ff02746c31894800e5122946", + "reference": "050bedf145a257b1ff02746c31894800e5122946", + "shasum": "" + }, + "require": { + "php": "^7.1" + }, + "require-dev": { + "phpunit/phpunit": "^7.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "FilterIterator implementation that filters files based on a list of suffixes.", + "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", + "keywords": [ + "filesystem", + "iterator" + ], + "time": "2018-09-13T20:33:42+00:00" + }, + { + "name": "phpunit/php-text-template", + "version": "1.2.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-text-template.git", + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/31f8b717e51d9a2afca6c9f046f5d69fc27c8686", + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Simple template engine.", + "homepage": "https://github.com/sebastianbergmann/php-text-template/", + "keywords": [ + "template" + ], + "time": "2015-06-21T13:50:34+00:00" + }, + { + "name": "phpunit/php-timer", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-timer.git", + "reference": "8b8454ea6958c3dee38453d3bd571e023108c91f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/8b8454ea6958c3dee38453d3bd571e023108c91f", + "reference": "8b8454ea6958c3dee38453d3bd571e023108c91f", + "shasum": "" + }, + "require": { + "php": "^7.1" + }, + "require-dev": { + "phpunit/phpunit": "^7.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Utility class for timing", + "homepage": "https://github.com/sebastianbergmann/php-timer/", + "keywords": [ + "timer" + ], + "time": "2018-02-01T13:07:23+00:00" + }, + { + "name": "phpunit/php-token-stream", + "version": "3.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-token-stream.git", + "reference": "c99e3be9d3e85f60646f152f9002d46ed7770d18" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/c99e3be9d3e85f60646f152f9002d46ed7770d18", + "reference": "c99e3be9d3e85f60646f152f9002d46ed7770d18", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": "^7.1" + }, + "require-dev": { + "phpunit/phpunit": "^7.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Wrapper around PHP's tokenizer extension.", + "homepage": "https://github.com/sebastianbergmann/php-token-stream/", + "keywords": [ + "tokenizer" + ], + "time": "2018-10-30T05:52:18+00:00" + }, + { + "name": "phpunit/phpunit", + "version": "7.4.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit.git", + "reference": "c151651fb6ed264038d486ea262e243af72e5e64" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/c151651fb6ed264038d486ea262e243af72e5e64", + "reference": "c151651fb6ed264038d486ea262e243af72e5e64", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "^1.1", + "ext-dom": "*", + "ext-json": "*", + "ext-libxml": "*", + "ext-mbstring": "*", + "ext-xml": "*", + "myclabs/deep-copy": "^1.7", + "phar-io/manifest": "^1.0.2", + "phar-io/version": "^2.0", + "php": "^7.1", + "phpspec/prophecy": "^1.7", + "phpunit/php-code-coverage": "^6.0.7", + "phpunit/php-file-iterator": "^2.0.1", + "phpunit/php-text-template": "^1.2.1", + "phpunit/php-timer": "^2.0", + "sebastian/comparator": "^3.0", + "sebastian/diff": "^3.0", + "sebastian/environment": "^3.1 || ^4.0", + "sebastian/exporter": "^3.1", + "sebastian/global-state": "^2.0", + "sebastian/object-enumerator": "^3.0.3", + "sebastian/resource-operations": "^2.0", + "sebastian/version": "^2.0.1" + }, + "conflict": { + "phpunit/phpunit-mock-objects": "*" + }, + "require-dev": { + "ext-pdo": "*" + }, + "suggest": { + "ext-soap": "*", + "ext-xdebug": "*", + "phpunit/php-invoker": "^2.0" + }, + "bin": [ + "phpunit" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "7.4-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "The PHP Unit Testing framework.", + "homepage": "https://phpunit.de/", + "keywords": [ + "phpunit", + "testing", + "xunit" + ], + "time": "2018-10-23T05:57:41+00:00" + }, + { + "name": "sebastian/code-unit-reverse-lookup", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git", + "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", + "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", + "shasum": "" + }, + "require": { + "php": "^5.6 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^5.7 || ^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Looks up which function or method a line of code belongs to", + "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", + "time": "2017-03-04T06:30:41+00:00" + }, + { + "name": "sebastian/comparator", + "version": "3.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/comparator.git", + "reference": "5de4fc177adf9bce8df98d8d141a7559d7ccf6da" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/5de4fc177adf9bce8df98d8d141a7559d7ccf6da", + "reference": "5de4fc177adf9bce8df98d8d141a7559d7ccf6da", + "shasum": "" + }, + "require": { + "php": "^7.1", + "sebastian/diff": "^3.0", + "sebastian/exporter": "^3.1" + }, + "require-dev": { + "phpunit/phpunit": "^7.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides the functionality to compare PHP values for equality", + "homepage": "https://github.com/sebastianbergmann/comparator", + "keywords": [ + "comparator", + "compare", + "equality" + ], + "time": "2018-07-12T15:12:46+00:00" + }, + { + "name": "sebastian/diff", + "version": "3.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/diff.git", + "reference": "366541b989927187c4ca70490a35615d3fef2dce" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/366541b989927187c4ca70490a35615d3fef2dce", + "reference": "366541b989927187c4ca70490a35615d3fef2dce", + "shasum": "" + }, + "require": { + "php": "^7.1" + }, + "require-dev": { + "phpunit/phpunit": "^7.0", + "symfony/process": "^2 || ^3.3 || ^4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Diff implementation", + "homepage": "https://github.com/sebastianbergmann/diff", + "keywords": [ + "diff", + "udiff", + "unidiff", + "unified diff" + ], + "time": "2018-06-10T07:54:39+00:00" + }, + { + "name": "sebastian/environment", + "version": "3.1.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/environment.git", + "reference": "cd0871b3975fb7fc44d11314fd1ee20925fce4f5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/cd0871b3975fb7fc44d11314fd1ee20925fce4f5", + "reference": "cd0871b3975fb7fc44d11314fd1ee20925fce4f5", + "shasum": "" + }, + "require": { + "php": "^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.1.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides functionality to handle HHVM/PHP environments", + "homepage": "http://www.github.com/sebastianbergmann/environment", + "keywords": [ + "Xdebug", + "environment", + "hhvm" + ], + "time": "2017-07-01T08:51:00+00:00" + }, + { + "name": "sebastian/exporter", + "version": "3.1.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/exporter.git", + "reference": "234199f4528de6d12aaa58b612e98f7d36adb937" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/234199f4528de6d12aaa58b612e98f7d36adb937", + "reference": "234199f4528de6d12aaa58b612e98f7d36adb937", + "shasum": "" + }, + "require": { + "php": "^7.0", + "sebastian/recursion-context": "^3.0" + }, + "require-dev": { + "ext-mbstring": "*", + "phpunit/phpunit": "^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.1.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides the functionality to export PHP variables for visualization", + "homepage": "http://www.github.com/sebastianbergmann/exporter", + "keywords": [ + "export", + "exporter" + ], + "time": "2017-04-03T13:19:02+00:00" + }, + { + "name": "sebastian/global-state", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/global-state.git", + "reference": "e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4", + "reference": "e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4", + "shasum": "" + }, + "require": { + "php": "^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.0" + }, + "suggest": { + "ext-uopz": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Snapshotting of global state", + "homepage": "http://www.github.com/sebastianbergmann/global-state", + "keywords": [ + "global state" + ], + "time": "2017-04-27T15:39:26+00:00" + }, + { + "name": "sebastian/object-enumerator", + "version": "3.0.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-enumerator.git", + "reference": "7cfd9e65d11ffb5af41198476395774d4c8a84c5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/7cfd9e65d11ffb5af41198476395774d4c8a84c5", + "reference": "7cfd9e65d11ffb5af41198476395774d4c8a84c5", + "shasum": "" + }, + "require": { + "php": "^7.0", + "sebastian/object-reflector": "^1.1.1", + "sebastian/recursion-context": "^3.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Traverses array structures and object graphs to enumerate all referenced objects", + "homepage": "https://github.com/sebastianbergmann/object-enumerator/", + "time": "2017-08-03T12:35:26+00:00" + }, + { + "name": "sebastian/object-reflector", + "version": "1.1.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-reflector.git", + "reference": "773f97c67f28de00d397be301821b06708fca0be" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/773f97c67f28de00d397be301821b06708fca0be", + "reference": "773f97c67f28de00d397be301821b06708fca0be", + "shasum": "" + }, + "require": { + "php": "^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Allows reflection of object attributes, including inherited and non-public ones", + "homepage": "https://github.com/sebastianbergmann/object-reflector/", + "time": "2017-03-29T09:07:27+00:00" + }, + { + "name": "sebastian/recursion-context", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/recursion-context.git", + "reference": "5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8", + "reference": "5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8", + "shasum": "" + }, + "require": { + "php": "^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides functionality to recursively process PHP variables", + "homepage": "http://www.github.com/sebastianbergmann/recursion-context", + "time": "2017-03-03T06:23:57+00:00" + }, + { + "name": "sebastian/resource-operations", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/resource-operations.git", + "reference": "4d7a795d35b889bf80a0cc04e08d77cedfa917a9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/4d7a795d35b889bf80a0cc04e08d77cedfa917a9", + "reference": "4d7a795d35b889bf80a0cc04e08d77cedfa917a9", + "shasum": "" + }, + "require": { + "php": "^7.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides a list of PHP built-in functions that operate on resources", + "homepage": "https://www.github.com/sebastianbergmann/resource-operations", + "time": "2018-10-04T04:07:39+00:00" + }, + { + "name": "sebastian/version", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/version.git", + "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/99732be0ddb3361e16ad77b68ba41efc8e979019", + "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019", + "shasum": "" + }, + "require": { + "php": ">=5.6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that helps with managing the version number of Git-hosted PHP projects", + "homepage": "https://github.com/sebastianbergmann/version", + "time": "2016-10-03T07:35:21+00:00" + }, + { + "name": "theseer/tokenizer", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/theseer/tokenizer.git", + "reference": "cb2f008f3f05af2893a87208fe6a6c4985483f8b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/cb2f008f3f05af2893a87208fe6a6c4985483f8b", + "reference": "cb2f008f3f05af2893a87208fe6a6c4985483f8b", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": "^7.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + } + ], + "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", + "time": "2017-04-07T12:08:54+00:00" + }, + { + "name": "webmozart/assert", + "version": "1.3.0", + "source": { + "type": "git", + "url": "https://github.com/webmozart/assert.git", + "reference": "0df1908962e7a3071564e857d86874dad1ef204a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/webmozart/assert/zipball/0df1908962e7a3071564e857d86874dad1ef204a", + "reference": "0df1908962e7a3071564e857d86874dad1ef204a", + "shasum": "" + }, + "require": { + "php": "^5.3.3 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.6", + "sebastian/version": "^1.0.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3-dev" + } + }, + "autoload": { + "psr-4": { + "Webmozart\\Assert\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + } + ], + "description": "Assertions to validate method input/output with nice error messages.", + "keywords": [ + "assert", + "check", + "validate" + ], + "time": "2018-01-29T19:49:41+00:00" + } + ], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": { + "eaglewu/swoole-ide-helper": 20 + }, + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "php": "^7.1", + "ext-amqp": "*" + }, + "platform-dev": [] +} diff --git a/example/db.php b/example/db.php new file mode 100644 index 0000000..9e970b4 --- /dev/null +++ b/example/db.php @@ -0,0 +1,12 @@ + [ + 'default' => [ + 'host' => '192.168.0.254', + 'port' => 5672, + 'login' => 'guest', + 'password' => 'guest', + 'vhost' => '/', + ] + ] +]; diff --git a/example/rabbitConsumeExample.php b/example/rabbitConsumeExample.php new file mode 100644 index 0000000..302dc45 --- /dev/null +++ b/example/rabbitConsumeExample.php @@ -0,0 +1,77 @@ +test; + $hello->haha; + + go(function () { + Co::sleep(4); + file_put_contents(__DIR__ . '/go.log', time() . PHP_EOL, 8); + }); + + go(function () { + file_put_contents(__DIR__ . '/go-1.log', time() . PHP_EOL, 8); + }); + + $queue->ack($envelope->getDeliveryTag()); + } + + /** + * 消费者异常处理函数 + * + * @param \Throwable $e + * @return mixed + */ + public function exception(\Throwable $e) + { + } + + /** + * 错误处理 + * + * @return mixed + */ + public function error() + { + file_put_contents(__DIR__ . '/error.log', json_encode(func_get_args()) . PHP_EOL, 8); + } +} + +$server = require 'server.php'; +$db = require 'db.php'; +$worker = require 'worker.mq.php'; + +$di = new \Phalcon\Di; + +try { + $master = new \Bee\Mq\Master($server['mq']); + $master->setConfig($db['mq'], $worker); +// $master->restart(); + $master->status(); + $master->stop(); + +} catch (\Throwable $e) { + print_r($e); +} diff --git a/example/rabbitProducerExample.php b/example/rabbitProducerExample.php new file mode 100644 index 0000000..c8bef20 --- /dev/null +++ b/example/rabbitProducerExample.php @@ -0,0 +1,22 @@ +publish( + 'dev', + 'mq/developTest', + [ + 'user_id' => 0, + ] + ); + +} catch (\Throwable $e) { + print_r($e); +} \ No newline at end of file diff --git a/example/server.php b/example/server.php new file mode 100644 index 0000000..94b01c9 --- /dev/null +++ b/example/server.php @@ -0,0 +1,10 @@ + [ + 'name' => 'bee-mq', + 'pidFile' => __DIR__ . '/bee.pid', + 'logFile' => __DIR__ . '/bee_mq.log', + 'daemon' => true, // 以守护进程模式运行 + 'redirect' => false, // 不启用标准输出 + ] +]; diff --git a/example/worker.mq.php b/example/worker.mq.php new file mode 100644 index 0000000..5ec059a --- /dev/null +++ b/example/worker.mq.php @@ -0,0 +1,15 @@ + 'default', + 'class' => \RabbitExample::class, + 'num' => 1, + 'params' => [ + 'exchange' => 'dev', + 'type' => 'direct', + 'route' => 'mq/developTest', + 'flags' => AMQP_DURABLE, + 'queue' => 'mq/developTest', + ], + ] +]; diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..aefdea1 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,23 @@ + + + + + + ./tests/ + + + + + ./src + + + \ No newline at end of file diff --git a/src/Consumer/Rabbit.php b/src/Consumer/Rabbit.php new file mode 100644 index 0000000..39d5b77 --- /dev/null +++ b/src/Consumer/Rabbit.php @@ -0,0 +1,268 @@ +process = $process; + $this->ppid = $ppid; + + // 错误处理回调 + set_error_handler([$this, 'error']); + + // 序列化对象 + $this->serializer = Factory::instance($this->format); + // 启动消费者 + $this->receive(); + } + + /** + * 设置MQ连接配置 + * + * @param array $server + * @param array $queue + * + * @throws Exception + */ + public function setConfig(array $server, array $queue) + { + // 检查连接参数 + if (empty($server['host'])) { + throw new Exception('host不能为空'); + } + if (empty($server['port'])) { + throw new Exception('port不能为空'); + } + if (empty($server['login'])) { + throw new Exception('username不能为空'); + } + if (empty($server['password'])) { + throw new Exception('password不能为空'); + } + if (!isset($server['vhost'])) { + $server['vhost'] = '/'; + } + if (isset($server['format'])) { + $this->format = $server['format']; + } + + // 检查交换机,路由和队列参数 + if (!isset($queue['exchange'])) { + throw new Exception('exchange不能为空'); + } + if (!isset($queue['type'])) { + throw new Exception('type不能为空'); + } + if (!isset($queue['route'])) { + throw new Exception('route不能为空'); + } + if (!isset($queue['queue'])) { + throw new Exception('queue不能为空'); + } + if (!isset($queue['flags'])) { + throw new Exception('flags不能为空'); + } + + // 连接配置信息 + $this->config = $server; + + // 交换机,路由与队列信息 + $this->exchange = $queue['exchange']; + $this->type = $queue['type']; + $this->route = $queue['route']; + $this->queue = $queue['queue']; + $this->flags = $queue['flags']; + } + + /** + * 链接MQ + * + * @return \AMQPConnection + * @throws \AMQPConnectionException + */ + public function connect() + { + // 执行MQ链接 + $this->connect = new \AMQPConnection($this->config); + $this->connect->connect(); + + return $this->connect; + } + + /** + * 断开MQ连接 + */ + public function disconnect() + { + $this->connect->disconnect(); + } + + /** + * 接收MQ消息 + * + */ + public function receive() + { + try { + // 获取RabbitMQ连接 + $connection = $this->connect(); + + // 初始化频道 + $ch = new \AMQPChannel($connection); + // 轮询分发 + $ch->qos(0, 1); + + // 设置换机 + $ex = new \AMQPExchange($ch); + $ex->setName($this->exchange); + $ex->setType($this->type); + $ex->setFlags($this->flags); + $ex->declareExchange(); + + // 设置队列 + $qu = new \AMQPQueue($ch); + $qu->setName($this->queue); + $qu->setFlags($this->flags); + $qu->declareQueue(); + $qu->bind($this->exchange, $this->route); + // 开始接收消息 + $qu->consume( + function (\AMQPEnvelope $envelope, \AMQPQueue $queue) { + // 已处理任务达到最大数 + // 退出当前进程(主进程会自动拉起新进程) + if ($this->count >= $this->maximum) { + $this->workerExit(); + } + // 已处理数加1 + $this->count++; + + // 标记进程为执行中 + $this->idle = false; + // 消费业务处理 + $this->consume($envelope, $queue); + // 标记进程未空闲 + $this->idle = true; + // 检查主进程 + $this->checkMaster(); + }); + } catch (\Throwable $e) { + $this->exception($e); + } + } + + /** + * 进程退出时回收资源 + */ + public function workerExit() + { + // 断开MQ连接 + $this->disconnect(); + // 退出当前进程 + $this->exit(); + } + + /** + * 任务执行方法体 + * + * @param \AMQPEnvelope $envelope + * @param \AMQPQueue $queue + * + * @return mixed + */ + abstract public function consume(\AMQPEnvelope $envelope, \AMQPQueue $queue); + + /** + * 消费者异常处理函数 + * + * @param \Throwable $e + * @return mixed + */ + abstract public function exception(\Throwable $e); + + /** + * 错误处理 + * + * @return mixed + */ + abstract public function error(); +} diff --git a/src/ConsumerInterface.php b/src/ConsumerInterface.php new file mode 100644 index 0000000..3392c41 --- /dev/null +++ b/src/ConsumerInterface.php @@ -0,0 +1,38 @@ +servers = $serverConfig; + $this->workers = $workerConfig; + } + + /** + * 主进程业务配置 + * + * @throws Exception + */ + public function configure() + { + $instances = []; + // 工作进程 + $workers = $this->workers; + // MQ服务器连接信息 + $servers = $this->servers; + + // 检查MQ配置 + foreach ($workers as $key => $worker) { + // 所使用的服务配置 + $name = $worker['server']; + + if (!isset($servers[$name])) { + throw new Exception("配置'{$name}'在\$servers中未找到"); + } + + $instances[$key] = new $worker['class']; + $instances[$key]->setConfig($servers[$name], $worker['params']); + } + + // 启动MQ消费者实例 + foreach ($workers as $key => $worker) { + for ($i = 0; $i < $worker['num']; $i++) { + $this->fork([$instances[$key], 'handle'], $worker['params']['route']); + } + } + } +} diff --git a/src/Producer/Rabbit.php b/src/Producer/Rabbit.php new file mode 100644 index 0000000..97c5816 --- /dev/null +++ b/src/Producer/Rabbit.php @@ -0,0 +1,100 @@ +connect(); + + $this->connection = $connection; + $this->serializer = $serializer; + } + + /** + * 获取MQ链接对象 + * + * @return \AMQPConnection + */ + public function connect() + { + if (!$this->connection->isConnected()) { + $this->connection->reconnect(); + } + + return $this->connection; + } + + /** + * 发布消息 + * + * @param string $exchange 交换器 + * @param string $route 路由 + * @param mixed $data 数据 + * + * @return Rabbit + * @throws \AMQPChannelException + * @throws \AMQPConnectionException + * @throws \AMQPExchangeException + */ + public function publish($exchange, $route, $data) + { + if (is_array($data)) { + $_data = $this->serializer::pack($data); + } else { + $_data = $data; + } + + // MQ连接 + $connection = $this->connect(); + // 频道 + $channel = new \AMQPChannel($connection); + + // 交换机 + $ex = new \AMQPExchange($channel); + $ex->setName($exchange); + // 发布消息 + $ex->publish($_data, $route); + + return $this; + } + + /** + * 关闭MQ连接 + */ + public function close() + { + $this->connection->disconnect(); + } +} \ No newline at end of file diff --git a/src/ProducerInterface.php b/src/ProducerInterface.php new file mode 100644 index 0000000..909acc1 --- /dev/null +++ b/src/ProducerInterface.php @@ -0,0 +1,33 @@ + [ + 'default' => [ + 'host' => '192.168.0.254', + 'port' => 5672, + 'login' => 'guest', + 'password' => 'guest', + 'vhost' => '/', + ] + ] +]; diff --git a/tests/server.php b/tests/server.php new file mode 100644 index 0000000..94b01c9 --- /dev/null +++ b/tests/server.php @@ -0,0 +1,10 @@ + [ + 'name' => 'bee-mq', + 'pidFile' => __DIR__ . '/bee.pid', + 'logFile' => __DIR__ . '/bee_mq.log', + 'daemon' => true, // 以守护进程模式运行 + 'redirect' => false, // 不启用标准输出 + ] +]; diff --git a/tests/worker.mq.php b/tests/worker.mq.php new file mode 100644 index 0000000..5ec059a --- /dev/null +++ b/tests/worker.mq.php @@ -0,0 +1,15 @@ + 'default', + 'class' => \RabbitExample::class, + 'num' => 1, + 'params' => [ + 'exchange' => 'dev', + 'type' => 'direct', + 'route' => 'mq/developTest', + 'flags' => AMQP_DURABLE, + 'queue' => 'mq/developTest', + ], + ] +];