Skip to content

Commit 2b21192

Browse files
authored
Add files via upload
1 parent 6ec2d1c commit 2b21192

7 files changed

Lines changed: 104 additions & 2 deletions

File tree

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"name": "webman/stomp",
3-
"description": "Stomp client written in PHP for webman.",
3+
"description": "Stomp queue plugin for webman.",
44
"require": {
5+
"workerman/webman-framework": "^1.2.1",
56
"workerman/stomp": "^1.0"
67
},
78
"autoload": {

src/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function __call($name, $arguments)
8787
*/
8888
public static function connection($name = 'default') {
8989
if (!isset(static::$_connections[$name])) {
90-
$config = config('stomp', []);
90+
$config = config('stomp', config('plugin.webman.stomp.stomp', []));
9191
if (!isset($config[$name])) {
9292
throw new \RuntimeException("RedisQueue connection $name not found");
9393
}

src/Install.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
namespace Webman\Stomp;
3+
4+
class Install
5+
{
6+
const WEBMAN_PLUGIN = true;
7+
8+
/**
9+
* @var array
10+
*/
11+
protected static $pathRelation = array (
12+
'config/plugin/webman/stomp' => 'config/plugin/webman/stomp',
13+
);
14+
15+
/**
16+
* Install
17+
* @return void
18+
*/
19+
public static function install()
20+
{
21+
static::installByRelation();
22+
mkdir(app_path() . '/queue/stomp', 0777, true);
23+
}
24+
25+
/**
26+
* Uninstall
27+
* @return void
28+
*/
29+
public static function uninstall()
30+
{
31+
self::uninstallByRelation();
32+
}
33+
34+
/**
35+
* installByRelation
36+
* @return void
37+
*/
38+
public static function installByRelation()
39+
{
40+
foreach (static::$pathRelation as $source => $dest) {
41+
if ($pos = strrpos($dest, '/')) {
42+
$parent_dir = base_path().'/'.substr($dest, 0, $pos);
43+
if (!is_dir($parent_dir)) {
44+
mkdir($parent_dir, 0777, true);
45+
}
46+
}
47+
//symlink(__DIR__ . "/$source", base_path()."/$dest");
48+
copy_dir(__DIR__ . "/$source", base_path()."/$dest");
49+
}
50+
}
51+
52+
/**
53+
* uninstallByRelation
54+
* @return void
55+
*/
56+
public static function uninstallByRelation()
57+
{
58+
foreach (static::$pathRelation as $source => $dest) {
59+
$path = base_path()."/$dest";
60+
if (!is_dir($path) && !is_file($path)) {
61+
continue;
62+
}
63+
/*if (is_link($path) {
64+
unlink($path);
65+
}*/
66+
remove_dir($path);
67+
}
68+
}
69+
70+
}

src/Process/Consumer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ public function __construct($consumer_dir = '')
4343
*/
4444
public function onWorkerStart()
4545
{
46+
if (!is_dir($this->_consumerDir)) {
47+
echo "Consumer directory {$this->_consumerDir} not exists\r\n";
48+
return;
49+
}
4650
$dir_iterator = new \RecursiveDirectoryIterator($this->_consumerDir);
4751
$iterator = new \RecursiveIteratorIterator($dir_iterator);
4852
foreach ($iterator as $file) {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
return [
3+
'enable' => true,
4+
];
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
return [
3+
'consumer' => [
4+
'handler' => Webman\Stomp\Process\Consumer::class,
5+
'count' => 8, // 可多进程消费
6+
'constructor' => [
7+
// 消费者类目录
8+
'consumer_dir' => app_path() . '/queue/stomp'
9+
]
10+
]
11+
];
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
return [
3+
'default' => [
4+
'host' => 'stomp://127.0.0.1:61613',
5+
'options' => [
6+
'vhost' => '/',
7+
'login' => 'guest',
8+
'passcode' => 'guest',
9+
'debug' => true,
10+
]
11+
]
12+
];

0 commit comments

Comments
 (0)