初始化
parent
ec714fd0b2
commit
2735fcfd16
|
@ -1,4 +1,4 @@
|
||||||
APP_NAME=skeleton
|
APP_NAME=hyperf-chat
|
||||||
APP_ENV=dev
|
APP_ENV=dev
|
||||||
|
|
||||||
DB_DRIVER=mysql
|
DB_DRIVER=mysql
|
||||||
|
@ -14,4 +14,4 @@ DB_PREFIX=
|
||||||
REDIS_HOST=localhost
|
REDIS_HOST=localhost
|
||||||
REDIS_AUTH=(null)
|
REDIS_AUTH=(null)
|
||||||
REDIS_PORT=6379
|
REDIS_PORT=6379
|
||||||
REDIS_DB=0
|
REDIS_DB=0
|
||||||
|
|
|
@ -37,7 +37,7 @@ class DemoConsumer extends ConsumerMessage
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public $queue = 'im.message.queue';
|
public $queue = 'im:message:queue';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 路由key
|
* 路由key
|
||||||
|
@ -70,6 +70,13 @@ class DemoConsumer extends ConsumerMessage
|
||||||
echo $data;
|
echo $data;
|
||||||
echo PHP_EOL;
|
echo PHP_EOL;
|
||||||
|
|
||||||
|
$server = server();
|
||||||
|
foreach (server()->connections as $fd){
|
||||||
|
if ($server->isEstablished($fd)) {
|
||||||
|
$server->push($fd, "Recv: 我是后台进程 [{$data}]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return Result::ACK;
|
return Result::ACK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ declare(strict_types=1);
|
||||||
namespace App\Controller;
|
namespace App\Controller;
|
||||||
|
|
||||||
use Hyperf\HttpServer\Contract\ResponseInterface;
|
use Hyperf\HttpServer\Contract\ResponseInterface;
|
||||||
|
|
||||||
use Hyperf\Amqp\Producer;
|
use Hyperf\Amqp\Producer;
|
||||||
use App\Amqp\Producer\DemoProducer;
|
use App\Amqp\Producer\DemoProducer;
|
||||||
|
|
||||||
|
@ -22,13 +23,12 @@ class IndexController extends AbstractController
|
||||||
$user = $this->request->input('user', 'Hyperf');
|
$user = $this->request->input('user', 'Hyperf');
|
||||||
$method = $this->request->getMethod();
|
$method = $this->request->getMethod();
|
||||||
|
|
||||||
$producer = $this->container->get(Producer::class);
|
$producer = container()->get(Producer::class);
|
||||||
|
|
||||||
$producer->produce(new DemoProducer('test'. date('Y-m-d H:i:s')));
|
$producer->produce(new DemoProducer('test'. date('Y-m-d H:i:s')));
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'method' => $method,
|
'method' => $method,
|
||||||
'message' => "Hello {$user}.",
|
'message' => "Hello {$user}."
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,15 +7,23 @@ use Hyperf\Contract\OnCloseInterface;
|
||||||
use Hyperf\Contract\OnMessageInterface;
|
use Hyperf\Contract\OnMessageInterface;
|
||||||
use Hyperf\Contract\OnOpenInterface;
|
use Hyperf\Contract\OnOpenInterface;
|
||||||
use Swoole\Http\Request;
|
use Swoole\Http\Request;
|
||||||
use Swoole\Server;
|
|
||||||
use Swoole\Websocket\Frame;
|
use Swoole\Websocket\Frame;
|
||||||
|
|
||||||
|
use Swoole\Server;
|
||||||
use Swoole\WebSocket\Server as WebSocketServer;
|
use Swoole\WebSocket\Server as WebSocketServer;
|
||||||
|
|
||||||
|
use Hyperf\Amqp\Producer;
|
||||||
|
use App\Amqp\Producer\DemoProducer;
|
||||||
|
|
||||||
|
|
||||||
class WebSocketController implements OnMessageInterface, OnOpenInterface, OnCloseInterface
|
class WebSocketController implements OnMessageInterface, OnOpenInterface, OnCloseInterface
|
||||||
{
|
{
|
||||||
public function onMessage($server, Frame $frame): void
|
public function onMessage($server, Frame $frame): void
|
||||||
{
|
{
|
||||||
$server->push($frame->fd, 'Recv: ' . $frame->data);
|
$producer = container()->get(Producer::class);
|
||||||
|
$producer->produce(new DemoProducer('test'. date('Y-m-d H:i:s')));
|
||||||
|
|
||||||
|
//$server->push($frame->fd, 'Recv: ' . $frame->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onClose($server, int $fd, int $reactorId): void
|
public function onClose($server, int $fd, int $reactorId): void
|
||||||
|
|
|
@ -14,9 +14,9 @@ namespace App\Process;
|
||||||
use Hyperf\AsyncQueue\Process\ConsumerProcess;
|
use Hyperf\AsyncQueue\Process\ConsumerProcess;
|
||||||
use Hyperf\Process\Annotation\Process;
|
use Hyperf\Process\Annotation\Process;
|
||||||
|
|
||||||
/**
|
///**
|
||||||
* @Process
|
// * @Process
|
||||||
*/
|
// */
|
||||||
class AsyncQueueConsumer extends ConsumerProcess
|
class AsyncQueueConsumer extends ConsumerProcess
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,8 @@ date_default_timezone_set('Asia/Shanghai');
|
||||||
|
|
||||||
require BASE_PATH . '/vendor/autoload.php';
|
require BASE_PATH . '/vendor/autoload.php';
|
||||||
|
|
||||||
|
echo gethostbyname(null);
|
||||||
|
|
||||||
// Self-called anonymous function that creates its own scope and keep the global namespace clean.
|
// Self-called anonymous function that creates its own scope and keep the global namespace clean.
|
||||||
(function () {
|
(function () {
|
||||||
Hyperf\Di\ClassLoader::init();
|
Hyperf\Di\ClassLoader::init();
|
||||||
|
|
|
@ -19,7 +19,7 @@ return [
|
||||||
'name' => 'http',
|
'name' => 'http',
|
||||||
'type' => Server::SERVER_HTTP,
|
'type' => Server::SERVER_HTTP,
|
||||||
'host' => '0.0.0.0',
|
'host' => '0.0.0.0',
|
||||||
'port' => 9501,
|
'port' => 9503,
|
||||||
'sock_type' => SWOOLE_SOCK_TCP,
|
'sock_type' => SWOOLE_SOCK_TCP,
|
||||||
'callbacks' => [
|
'callbacks' => [
|
||||||
SwooleEvent::ON_REQUEST => [Hyperf\HttpServer\Server::class, 'onRequest'],
|
SwooleEvent::ON_REQUEST => [Hyperf\HttpServer\Server::class, 'onRequest'],
|
||||||
|
@ -29,7 +29,7 @@ return [
|
||||||
'name' => 'ws',
|
'name' => 'ws',
|
||||||
'type' => Server::SERVER_WEBSOCKET,
|
'type' => Server::SERVER_WEBSOCKET,
|
||||||
'host' => '0.0.0.0',
|
'host' => '0.0.0.0',
|
||||||
'port' => 9502,
|
'port' => 9504,
|
||||||
'sock_type' => SWOOLE_SOCK_TCP,
|
'sock_type' => SWOOLE_SOCK_TCP,
|
||||||
'callbacks' => [
|
'callbacks' => [
|
||||||
SwooleEvent::ON_HAND_SHAKE => [Hyperf\WebSocketServer\Server::class, 'onHandShake'],
|
SwooleEvent::ON_HAND_SHAKE => [Hyperf\WebSocketServer\Server::class, 'onHandShake'],
|
||||||
|
|
Loading…
Reference in New Issue