├── .gitignore ├── compo ├── composer.json ├── src ├── MqJob.php ├── Producer.php ├── Consumer.php ├── MqQueue.php └── RabbitMqQueueDriver.php ├── tests ├── ProductTest.php └── ConsumerTest.php ├── README.md └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | # Editor directories and files 2 | .idea 3 | .vscode 4 | *.suo 5 | *.ntvs* 6 | *.njsproj 7 | *.sln 8 | vendor 9 | composer.lock -------------------------------------------------------------------------------- /compo: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # author:lys 3 | 4 | pwd_dir=`pwd` 5 | #cd $pwd_dir 6 | su - www <=2.0", 15 | "easyswoole/component": ">=2.0" 16 | }, 17 | "require-dev": { 18 | "phpunit/phpunit": "^8.5", 19 | "easyswoole/swoole-ide-helper": "^1.3" 20 | }, 21 | "autoload": { 22 | "psr-4": { 23 | "EasySwoole\\RabbitMq\\": "src/" 24 | } 25 | }, 26 | "autoload-dev": { 27 | "psr-4": { 28 | "EasySwoole\\RabbitMq\\Test\\": "tests/" 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/MqJob.php: -------------------------------------------------------------------------------- 1 | exchange = $exchange; 17 | $this->routingKey = $routingKey; 18 | $this->mqType = $mqType; 19 | $this->queueName = $queueName; 20 | } 21 | 22 | 23 | public function setExchange($exchange) 24 | { 25 | return $this->exchange = $exchange; 26 | } 27 | 28 | public function setRoutingKey($routingKey) 29 | { 30 | return $this->routingKey = $routingKey; 31 | } 32 | 33 | public function setMqType($mqType) 34 | { 35 | return $this->mqType = $mqType; 36 | } 37 | 38 | public function setQueueName($queueName) 39 | { 40 | return $this->queueName = $queueName; 41 | } 42 | 43 | 44 | public function getExchange() 45 | { 46 | return $this->exchange; 47 | } 48 | 49 | public function getRoutingKey() 50 | { 51 | return $this->routingKey; 52 | } 53 | 54 | public function getMqType() 55 | { 56 | return $this->mqType; 57 | } 58 | 59 | public function getQueueName() 60 | { 61 | return $this->queueName; 62 | } 63 | } -------------------------------------------------------------------------------- /tests/ProductTest.php: -------------------------------------------------------------------------------- 1 | driver = new \EasySwoole\RabbitMq\RabbitMqQueueDriver('127.0.0.1', 5672, 'test', 'test', "/"); 26 | } 27 | 28 | /** 29 | * php vendor/bin/phpunit tests/ProductTest.php --filter testDirectPush 30 | */ 31 | public function testDirectPush() 32 | { 33 | 34 | MqQueue::getInstance($this->driver); 35 | $job = new MqJob(); 36 | $job->setJobData('hello word'); 37 | $res = MqQueue::getInstance()->producer()->setConfig('kd_sms_send_ex', 'hello', 'direct')->push($job); 38 | $this->assertEquals(true, !empty($res)); 39 | 40 | } 41 | 42 | /** 43 | * php vendor/bin/phpunit tests/ProductTest.php --filter testTopicPush 44 | */ 45 | public function testTopicPush() 46 | { 47 | 48 | MqQueue::getInstance($this->driver); 49 | $job = new MqJob(); 50 | $job->setJobData('hello word'); 51 | $res = MqQueue::getInstance()->producer()->setConfig('test_topic_ex', 'com.topic_hello', 'topic', 'topic_hello')->push($job); 52 | $this->assertEquals(true, !empty($res)); 53 | 54 | } 55 | 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/Producer.php: -------------------------------------------------------------------------------- 1 | atomic = $atomic; 23 | $this->driver = $driver; 24 | $this->nodeId = $nodeId; 25 | } 26 | 27 | /** 28 | * 初始化监听队列名 29 | * @param $exchange //交换器名称 30 | * @param $routingKey //绑定路由和队列名称 31 | * @param $mqType //交换器类型 32 | * @param $queueName //队列名称 33 | * @return $this 34 | */ 35 | public function setConfig($exchange, $routingKey, $mqType = 'direct', $queueName = '') 36 | { 37 | $this->exchange = $exchange; 38 | $this->routingKey = $routingKey; 39 | $this->mqType = $mqType; 40 | $this->queueName = $queueName; 41 | $this->writeExchange = true; 42 | return $this; 43 | } 44 | 45 | function push(MqJob $job, bool $init = true) 46 | { 47 | if ($this->writeExchange) { 48 | $job->setExchange($this->exchange); 49 | $job->setRoutingKey($this->routingKey); 50 | $job->setMqType($this->mqType); 51 | $job->setQueueName($this->queueName); 52 | $this->writeExchange = false; 53 | } 54 | $id = $this->atomic->add(1); 55 | if ($id > 0) { 56 | if ($init) { 57 | $job->setJobId($id); 58 | $job->setNodeId($this->nodeId); 59 | } 60 | $ret = $this->driver->push($job); 61 | if ($ret) { 62 | return $id; 63 | } 64 | } 65 | return 0; 66 | } 67 | } -------------------------------------------------------------------------------- /src/Consumer.php: -------------------------------------------------------------------------------- 1 | wait(null, false, $waitTime); 22 | 23 | function __construct(RabbitMqQueueDriver $driver) 24 | { 25 | $this->driver = $driver; 26 | } 27 | 28 | /** 29 | * 初始化监听队列名 30 | * @param $exchange //交换器名称 31 | * @param $routingKey //路由和绑定队列名称 32 | * @param $mqType //交换器类型 33 | * @return $this 34 | */ 35 | public function setConfig($exchange, $routingKey, $mqType = 'direct', $queueName = '') 36 | { 37 | $this->job = new MqJob($exchange, $routingKey, $mqType, $queueName); 38 | return $this; 39 | } 40 | 41 | /** 42 | * 设置错误监控函数针对 $channel->wait(null, false, $waitTime); 43 | * @param callable $moniterWaitErrorCallable 44 | * @return $this 45 | */ 46 | function setMoniterWaitError(callable $moniterWaitErrorCallable){ 47 | $this->moniterWaitErrorCallable = $moniterWaitErrorCallable; 48 | return $this; 49 | } 50 | 51 | /** 52 | * 监听 53 | * @param callable $call 54 | * @param $breakTime 55 | * @param $waitTime 56 | * @param $maxCurrency 57 | * @throws 58 | */ 59 | function listen(callable $call, $breakTime = 0.001, $waitTime = 5, int $maxCurrency = 128) 60 | { 61 | if (empty($this->job->getExchange()) && empty($this->job->getRoutingKey())) { 62 | throw new Exception('exchange and routingKey parameters cannot be null or empty'); 63 | } 64 | $job = $this->driver->consumerPop($call, $this->job, $breakTime, $waitTime, $this->moniterWaitErrorCallable); //这边本身自己会挂起 65 | } 66 | 67 | function stopListen(): Consumer 68 | { 69 | return $this; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/MqQueue.php: -------------------------------------------------------------------------------- 1 | driver = $driver; 22 | $this->atomic = new Long(0); 23 | $this->nodeId = Random::character(6); 24 | } 25 | 26 | /** 27 | * 刷新重建一个链接 28 | * @return MqQueue 29 | */ 30 | function refreshConnect() 31 | { 32 | return new static($this->driver->refreshConnect()); 33 | } 34 | 35 | /** 36 | * 主动关闭链接 37 | * @param callable|null $callback //关闭链接异常捕获回调函数 38 | * @return bool 39 | */ 40 | function closeConnection(callable $callback = null) 41 | { 42 | return $this->driver->closeConnection($callback); 43 | } 44 | 45 | function queueDriver() 46 | { 47 | return $this->driver; 48 | } 49 | 50 | function producer(): Producer 51 | { 52 | return new Producer($this->driver, $this->atomic, $this->nodeId); 53 | } 54 | 55 | function consumer(): Consumer 56 | { 57 | return new Consumer($this->driver); 58 | } 59 | 60 | 61 | function size(): ?int 62 | { 63 | return $this->driver->size(); 64 | } 65 | 66 | function currentJobId(): int 67 | { 68 | return $this->atomic->get(); 69 | } 70 | 71 | function setJobStartId(int $id): MqQueue 72 | { 73 | $this->atomic->set($id); 74 | return $this; 75 | } 76 | 77 | /** 78 | * @return bool|string 79 | */ 80 | public function getNodeId() 81 | { 82 | return $this->nodeId; 83 | } 84 | 85 | /** 86 | * @param bool|string $nodeId 87 | */ 88 | public function setNodeId($nodeId): void 89 | { 90 | $this->nodeId = $nodeId; 91 | } 92 | } -------------------------------------------------------------------------------- /tests/ConsumerTest.php: -------------------------------------------------------------------------------- 1 | driver = new \EasySwoole\RabbitMq\RabbitMqQueueDriver('127.0.0.1', 5672, 'test', 'test', "/"); 26 | } 27 | 28 | /** 29 | * php vendor/bin/phpunit tests/ConsumerTest.php --filter testDirectListen 30 | * @throws 31 | */ 32 | public function testDirectListen() 33 | { 34 | go(function () { 35 | MqQueue::getInstance($this->driver); 36 | MqQueue::getInstance()->consumer()->setConfig('kd_sms_send_ex', 'hello', 'direct')->listen(function (MqJob $job) { 37 | var_dump($job->getJobData()); 38 | }); 39 | }); 40 | } 41 | 42 | /** 43 | * php vendor/bin/phpunit tests/ConsumerTest.php --filter testTopicListen 44 | * @throws 45 | */ 46 | public function testTopicListen() 47 | { 48 | go(function () { 49 | MqQueue::getInstance($this->driver); 50 | MqQueue::getInstance()->consumer()->setConfig('test_topic_ex', 'com.#', 'topic', 'topic_hello')->listen(function (MqJob $job) { 51 | var_dump($job->getJobData()); 52 | }); 53 | }); 54 | } 55 | 56 | 57 | /** 58 | * php vendor/bin/phpunit tests/ConsumerTest.php --filter testFanoutListen 59 | * @throws 60 | */ 61 | public function testFanoutListen() 62 | { 63 | go(function () { 64 | MqQueue::getInstance($this->driver); 65 | MqQueue::getInstance()->consumer()->setConfig('test_fanout_ex', 'fanout_hello', 'fanout', 'fanout_hello')->listen(function (MqJob $job) { 66 | var_dump($job->getJobData()); 67 | }); 68 | }); 69 | } 70 | 71 | /** 72 | * php vendor/bin/phpunit tests/ConsumerTest.php --filter testFanout1Listen 73 | * @throws 74 | */ 75 | public function testFanout1Listen() 76 | { 77 | go(function () { 78 | MqQueue::getInstance($this->driver); 79 | MqQueue::getInstance()->consumer()->setConfig('test_fanout_ex', 'fanout_hello', 'fanout', 'fanout_hello1')->listen(function (MqJob $job) { 80 | var_dump($job->getJobData()); 81 | }); 82 | }); 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # easy-swoole-rabbitmq 2 | EasySwoole 框架的 RabbitMQ 队列插件,基于 php-amqplib/php-amqplib 3 | 4 | ### 支持的交换器类型 5 | 已支持 direct topic fanout 6 | 7 | ### 安装 8 | composer require lys/easy-swoole-rabbitmq 9 | 10 | 11 | ### 示例: 12 | 我们创建一个MqQueueProcess.php, 消费者进程 13 | ```php 14 | refreshConnect(); 29 | $MqQueue->consumer()->setConfig($exchange = 'kd_sms_send_ex', $routingKey = 'hello', $mqType = 'direct', $queueName = 'hello')->listen(function(MqJob $obj) { 30 | echo " [x] Received ", $obj->getJobData(), "\n"; 31 | Logger::getInstance()->log('log level info' . var_export($obj->getJobData(), true), Logger::LOG_LEVEL_INFO, 'DEBUG');//记录info级别日志//例子后面2个参数默认值 32 | var_dump($obj->getJobData(),'MqQueueProcess'); 33 | //return; //使用return 终止执行下面的代码 34 | //return true; //使用return true终止执行下面的代码 35 | echo 11111; 36 | //return false; //return false消息回滚,所以请注意,不要随意使用return false 37 | }); 38 | }); 39 | } 40 | } 41 | ``` 42 | 修改EasySwooleEvent.php,在mainServerCreate中添加如下代码 43 | ```php 44 | setProcessGroup('Test');//设置进程组 74 | $processConfig->setArg(['a'=>123]);//传参 75 | $processConfig->setRedirectStdinStdout(false);//是否重定向标准io 76 | $processConfig->setPipeType($processConfig::PIPE_TYPE_SOCK_DGRAM);//设置管道类型 77 | $processConfig->setEnableCoroutine(true);//是否自动开启协程 78 | $processConfig->setMaxExitWaitTime(3);//最大退出等待时间 79 | $processConfig->setProcessName('MqQueueProcessComposer'); 80 | \EasySwoole\EasySwoole\ServerManager::getInstance()->addProcess(new MqQueueProcess($processConfig)); 81 | } 82 | 83 | public static function onRequest(Request $request, Response $response): bool 84 | { 85 | // TODO: Implement onRequest() method. 86 | return true; 87 | } 88 | 89 | public static function afterRequest(Request $request, Response $response): void 90 | { 91 | // TODO: Implement afterAction() method. 92 | } 93 | } 94 | ``` 95 | 生产者投递消息 96 | ```php 97 | setJobData('composer hello word'.date('Y-m-d H:i:s', time())); 108 | $res = MqQueue::getInstance()->producer()->setConfig($exchange = 'kd_sms_send_ex',$routingKey = 'hello',$mqType = 'direct', $queueName = 'hello')->push($job); 109 | if($res){ 110 | var_dump('发布成功'); 111 | }else{ 112 | var_dump('发布失败'); 113 | } 114 | //主动关闭链接 115 | /* MqQueue::getInstance()->closeConnection(function (\Exception $e){ 116 | //这边是主动关闭异常处理 117 | }); */ 118 | } 119 | } 120 | 121 | ``` 122 | 123 | ### 更多请关注本人的博客 124 | https://www.developzhe.com/single200.html 125 | 126 | ### Page visitor counter 127 | ![visitor counter](https://profile-counter.glitch.me/1107012776_easy-swoole-rabbitmq/count.svg) 128 | -------------------------------------------------------------------------------- /src/RabbitMqQueueDriver.php: -------------------------------------------------------------------------------- 1 | config = [ 31 | $host, $port, $user, $password, $vhost, 32 | $insist, $login_method, $login_response, $locale, $connection_timeout, $read_write_timeout, 33 | $context, $keepalive, $heartbeat 34 | ]; 35 | $this->connection(); 36 | } 37 | 38 | /** 39 | * 链接 40 | */ 41 | protected function connection() 42 | { 43 | list($host, $port, $user, $password, $vhost, 44 | $insist, $login_method, $login_response, $locale, $connection_timeout, $read_write_timeout, 45 | $context, $keepalive, $heartbeat) = $this->config; 46 | $this->connection = new AMQPStreamConnection($host, $port, $user, $password, $vhost, 47 | $insist, $login_method, $login_response, $locale, $connection_timeout, $read_write_timeout, 48 | $context, $keepalive, $heartbeat 49 | ); 50 | } 51 | 52 | /** 53 | * 刷新链接 54 | */ 55 | public function refreshConnect() 56 | { 57 | list($host, $port, $user, $password, $vhost, 58 | $insist, $login_method, $login_response, $locale, $connection_timeout, $read_write_timeout, 59 | $context, $keepalive, $heartbeat) = $this->config; 60 | return new self($host, $port, $user, $password, $vhost, 61 | $insist, $login_method, $login_response, $locale, $connection_timeout, $read_write_timeout, 62 | $context, $keepalive, $heartbeat); 63 | } 64 | 65 | /** 66 | * 关闭链接 67 | * @param callable|null $callback 68 | * @return bool 69 | */ 70 | public function closeConnection(callable $callback = null) 71 | { 72 | try { 73 | $this->connection->close(); 74 | } catch (\Exception $e) { 75 | !empty($callback) && $callback($e); 76 | return false; 77 | } 78 | return true; 79 | } 80 | 81 | /** 82 | * 生产发布信息 83 | * @param MqJob $job 84 | * @return bool 85 | */ 86 | public function push($job): bool 87 | { 88 | try { 89 | $channel = $this->connection->channel(); 90 | } catch (\Exception $e) { 91 | try { 92 | $this->connection->close(); 93 | } catch (\Exception $e) { 94 | 95 | } 96 | $this->connection(); 97 | $channel = $this->connection->channel(); 98 | } 99 | $exchange = $job->getExchange(); //交换器名 100 | $queueName = $routingKey = $job->getRoutingKey(); //路由关键字(也可以省略) 101 | if (!empty($job->getQueueName())) { 102 | $queueName = $job->getQueueName(); 103 | } 104 | $channel->exchange_declare($exchange, $job->getMqType(), false, true, false); //声明初始化交换器 105 | $channel->queue_declare($queueName, false, true, false, false); 106 | $channel->queue_bind($queueName, $exchange, $routingKey); 107 | $body = $job->getJobData(); 108 | is_array($body) && $body = json_encode($body, JSON_UNESCAPED_UNICODE); 109 | $msg = new AMQPMessage($body, [ 110 | 'delivery_mode' => 2 // make message persistent 持久化消息 111 | ]); 112 | $channel->tx_select(); //事务声明 113 | try { 114 | $channel->basic_publish($msg, $exchange, $routingKey); 115 | $channel->tx_commit(); 116 | $isOk = true; 117 | } catch (\Exception $e) { 118 | $channel->tx_rollback(); 119 | $isOk = false; 120 | } finally { 121 | $channel->close(); 122 | } 123 | return $isOk; 124 | } 125 | 126 | 127 | /** 128 | * @param $callback 129 | * @param MqJob $job 130 | * @param $breakTime 131 | * @param $waitTime 132 | * @param $moniterWaitErrorCallable 133 | * @return mixed 134 | * @throws 135 | */ 136 | public function consumerPop($callback, MqJob $job, $breakTime, $waitTime, callable $moniterWaitErrorCallable = null) 137 | { 138 | $channel = $this->connection->channel(); 139 | $exchange = $job->getExchange(); //交换器名 140 | $queueName = $routingKey = $job->getRoutingKey(); //路由关键字(也可以省略) 141 | if (!empty($job->getQueueName())) { 142 | $queueName = $job->getQueueName(); 143 | } 144 | $channel->exchange_declare($exchange, $job->getMqType(), false, true, false); //声明初始化交换器 145 | $channel->queue_declare($queueName, false, true, false, false); 146 | $channel->queue_bind($queueName, $exchange, $routingKey); 147 | $channel->basic_consume($queueName, '', false, false, false, false, function ($msg) use ($job, $callback) { 148 | $job->setJobData($msg->body); 149 | $res = $callback($job); 150 | if ($res === false) { //明确消息是失败直接reject 151 | Coroutine::sleep(2); //协程睡眠,以免频繁回滚出现消耗大量性能 152 | $msg->delivery_info['channel']->basic_reject($msg->delivery_info['delivery_tag'], true); //回滚 153 | return; 154 | } 155 | $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']); //ack回应消息收到了 156 | }); 157 | while (count($channel->callbacks)) { 158 | try { 159 | $channel->wait(null, false, $waitTime); 160 | } catch (\Exception $e) { 161 | !empty($moniterWaitErrorCallable) && $moniterWaitErrorCallable($e); 162 | } 163 | Coroutine::sleep($breakTime); 164 | } 165 | return $job; 166 | } 167 | 168 | public function size(): ?int 169 | { 170 | return 0; 171 | } 172 | 173 | } 174 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------