Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added nsq. #1321

Merged
merged 32 commits into from
Jan 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
44d58d7
Init nsq component.
limingxinleo Jan 20, 2020
d8233fc
Added Socket.
limingxinleo Jan 20, 2020
339d00d
Optimized code of Socket.
limingxinleo Jan 20, 2020
31ff1e0
Renamed Socket to HeartbeatConnection.
limingxinleo Jan 20, 2020
9e10089
Optimized code for heartbeat connection.
limingxinleo Jan 21, 2020
5e630af
Init nsq client
huangzhhui Jan 21, 2020
9156972
Merge remote-tracking branch 'origin/master'
huangzhhui Jan 21, 2020
80ade91
Added NsqPool.
limingxinleo Jan 22, 2020
cbbe1c7
Added default pool config.
limingxinleo Jan 22, 2020
83591e4
Renamed HeartbeatConnection to KeepaliveConnection.
limingxinleo Jan 22, 2020
df31692
Added comsumer manager for nsq.
limingxinleo Jan 22, 2020
d872a91
Added consumer manager listener.
limingxinleo Jan 22, 2020
05cccdf
Deleted useless code.
limingxinleo Jan 22, 2020
ab44b19
Use static methods instead of normal methods of Packer
huangzhhui Jan 22, 2020
fbd1526
Optimized code for consumer.
limingxinleo Jan 22, 2020
63ed438
rename property
huangzhhui Jan 22, 2020
a42807d
Merge branch 'master' of github.com:huangzhhui/hyperf-nsq
limingxinleo Jan 22, 2020
271423f
Add MPUB DPUB and CLS
huangzhhui Jan 22, 2020
3052c31
Merge branch 'master' of github.com:huangzhhui/hyperf-nsq
limingxinleo Jan 22, 2020
71eb492
Support dpub and mpub.
limingxinleo Jan 22, 2020
9cb7816
Fixed defer time of dpub does not works.
limingxinleo Jan 22, 2020
1ab9e95
Add IDENTIFY
huangzhhui Jan 22, 2020
d3ef0d5
Fixed message unpack
huangzhhui Jan 22, 2020
fbde9e8
Merge remote-tracking branch 'origin/master'
huangzhhui Jan 22, 2020
e1f378e
Optimized
huangzhhui Jan 22, 2020
4489815
Added argument result for AfterConsume.
limingxinleo Jan 22, 2020
e62bf1e
Support Auth protocol.
limingxinleo Jan 22, 2020
60fdae5
Remove useless packer namespace
huangzhhui Jan 23, 2020
7a232b6
Extract MAGIC
huangzhhui Jan 23, 2020
21ccfc0
Fix nsq protocol
huangzhhui Jan 23, 2020
368d6c1
Optimized and format
huangzhhui Jan 23, 2020
c1b2276
Added ext-bcmatch required.
limingxinleo Jan 24, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ before_script:
- composer config -g process-timeout 900 && composer update

script:
- composer analyse src/di src/json-rpc src/tracer src/metric src/redis src/nats src/db src/retry src/grpc-client
- composer analyse src/di src/json-rpc src/tracer src/metric src/redis src/nats src/db src/retry src/grpc-client src/nsq
- composer test -- --exclude-group NonCoroutine
- vendor/bin/phpunit --group NonCoroutine
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"php": ">=7.2",
"ext-json": "*",
"ext-swoole": ">=4.4",
"ext-bcmath": "*",
"bandwidth-throttle/token-bucket": "^2.0",
"doctrine/annotations": "^1.6",
"doctrine/inflector": "^1.3",
Expand Down Expand Up @@ -167,6 +168,7 @@
"Hyperf\\ModelCache\\": "src/model-cache/src/",
"Hyperf\\ModelListener\\": "src/model-listener/src/",
"Hyperf\\Nats\\": "src/nats/src/",
"Hyperf\\Nsq\\": "src/nsq/src/",
"Hyperf\\Paginator\\": "src/paginator/src/",
"Hyperf\\Pool\\": "src/pool/src/",
"Hyperf\\Process\\": "src/process/src/",
Expand Down Expand Up @@ -235,6 +237,7 @@
"HyperfTest\\ModelCache\\": "src/model-cache/tests/",
"HyperfTest\\ModelListener\\": "src/model-listener/tests/",
"HyperfTest\\Nats\\": "src/nats/tests/",
"HyperfTest\\Nsq\\": "src/nsq/tests/",
"HyperfTest\\Paginator\\": "src/paginator/tests/",
"HyperfTest\\Pool\\": "src/pool/tests/",
"HyperfTest\\Process\\": "src/process/tests/",
Expand Down Expand Up @@ -298,6 +301,7 @@
"Hyperf\\ModelCache\\ConfigProvider",
"Hyperf\\ModelListener\\ConfigProvider",
"Hyperf\\Nats\\ConfigProvider",
"Hyperf\\Nsq\\ConfigProvider",
"Hyperf\\Paginator\\ConfigProvider",
"Hyperf\\Pool\\ConfigProvider",
"Hyperf\\Process\\ConfigProvider",
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
<directory suffix=".php">./src/json-rpc/src</directory>
<directory suffix=".php">./src/logger/src</directory>
<directory suffix=".php">./src/model-cache/src</directory>
<directory suffix=".php">./src/nsq/src</directory>
<directory suffix=".php">./src/paginator/src</directory>
<directory suffix=".php">./src/redis/src</directory>
<directory suffix=".php">./src/rpc/src</directory>
Expand Down
37 changes: 37 additions & 0 deletions src/devtool/src/Generator/NsqConsumerCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://doc.hyperf.io
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/

namespace Hyperf\Devtool\Generator;

use Hyperf\Command\Annotation\Command;

/**
* @Command
*/
class NsqConsumerCommand extends GeneratorCommand
{
public function __construct()
{
parent::__construct('gen:nsq-consumer');
$this->setDescription('Create a new nsq consumer class');
}

protected function getStub(): string
{
return $this->getConfig()['stub'] ?? __DIR__ . '/stubs/nsq-consumer.stub';
}

protected function getDefaultNamespace(): string
{
return $this->getConfig()['namespace'] ?? 'App\\Nsq\\Consumer';
}
}
23 changes: 23 additions & 0 deletions src/devtool/src/Generator/stubs/nsq-consumer.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace %NAMESPACE%;

use Hyperf\Nsq\AbstractConsumer;
use Hyperf\Nsq\Annotation\Consumer;
use Hyperf\Nsq\Message;
use Hyperf\Nsq\Result;

/**
* @Consumer(topic="hyperf", channel="hyperf", name ="%CLASS%", nums=1)
*/
class %CLASS% extends AbstractConsumer
{
public function consume(Message $payload)
{
var_dump($payload->getBody());

return Result::ACK;
}
}
2 changes: 1 addition & 1 deletion src/nats/src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __invoke(): array
'publish' => [
[
'id' => 'config',
'description' => 'The config for amqp.',
'description' => 'The config for nats.',
'source' => __DIR__ . '/../publish/nats.php',
'destination' => BASE_PATH . '/config/autoload/nats.php',
],
Expand Down
1 change: 1 addition & 0 deletions src/nsq/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/tests export-ignore
21 changes: 21 additions & 0 deletions src/nsq/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) Hyperf

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
55 changes: 55 additions & 0 deletions src/nsq/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"name": "hyperf/nsq",
"description": "A nsq library for Hyperf.",
"license": "MIT",
"keywords": [
"php",
"swoole",
"hyperf",
"nsq"
],
"support": {
},
"require": {
"php": ">=7.2",
"ext-bcmath": "*",
"hyperf/contract": "~1.1.0",
"hyperf/utils": "~1.1.0",
"jean85/pretty-package-versions": "^1.2"
},
"require-dev": {
"malukenho/docheader": "^0.1.6",
"mockery/mockery": "^1.0",
"phpunit/phpunit": "^7.0.0",
"friendsofphp/php-cs-fixer": "^2.9"
},
"suggest": {
},
"autoload": {
"psr-4": {
"Hyperf\\Nsq\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"HyperfTest\\Nsq\\": "tests/"
}
},
"config": {
"sort-packages": true
},
"extra": {
"branch-alias": {
"dev-master": "1.1-dev"
},
"hyperf": {
"config": "Hyperf\\Nsq\\ConfigProvider"
}
},
"bin": [
],
"scripts": {
"cs-fix": "php-cs-fixer fix $1",
"test": "phpunit --colors=always"
}
}
26 changes: 26 additions & 0 deletions src/nsq/publish/nsq.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://doc.hyperf.io
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/

return [
'default' => [
'host' => '127.0.0.1',
'port' => 4150,
'pool' => [
'min_connections' => 1,
'max_connections' => 10,
'connect_timeout' => 10.0,
'wait_timeout' => 3.0,
'heartbeat' => -1,
'max_idle_time' => 60.0,
],
],
];
110 changes: 110 additions & 0 deletions src/nsq/src/AbstractConsumer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php

declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://doc.hyperf.io
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/

namespace Hyperf\Nsq;

use Psr\Container\ContainerInterface;

abstract class AbstractConsumer
{
/**
* @var string
*/
protected $pool = 'default';

/**
* @var string
*/
protected $topic = '';

/**
* @var string
*/
protected $channel = '';

/**
* @var string
*/
protected $name = 'NsqConsumer';

/**
* @var int
*/
protected $nums = 1;

/**
* @var ContainerInterface
*/
protected $container;

public function __construct(ContainerInterface $container)
{
$this->container = $container;
}

abstract public function consume(Message $message): ?string;

public function getTopic(): string
{
return $this->topic;
}

public function setTopic(string $topic): self
{
$this->topic = $topic;
return $this;
}

public function getChannel(): string
{
return $this->channel;
}

public function setChannel(string $channel): self
{
$this->channel = $channel;
return $this;
}

public function getName(): string
{
return $this->name;
}

public function setName(string $name): self
{
$this->name = $name;
return $this;
}

public function getNums(): int
{
return $this->nums;
}

public function setNums(int $nums): self
{
$this->nums = $nums;
return $this;
}

public function getPool(): string
{
return $this->pool;
}

public function setPool(string $pool): self
{
$this->pool = $pool;
return $this;
}
}
47 changes: 47 additions & 0 deletions src/nsq/src/Annotation/Consumer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://doc.hyperf.io
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/

namespace Hyperf\Nsq\Annotation;

use Hyperf\Di\Annotation\AbstractAnnotation;

/**
* @Annotation
* @Target({"CLASS"})
*/
class Consumer extends AbstractAnnotation
{
/**
* @var string
*/
public $topic = '';

/**
* @var string
*/
public $channel = '';

/**
* @var string
*/
public $name = '';

/**
* @var int
*/
public $nums = 1;

/**
* @var string
*/
public $pool = '';
}