初始化

main
gzydong 2020-11-03 14:07:54 +08:00
parent ec714fd0b2
commit 2735fcfd16
7 changed files with 30 additions and 13 deletions

View File

@ -1,4 +1,4 @@
APP_NAME=skeleton
APP_NAME=hyperf-chat
APP_ENV=dev
DB_DRIVER=mysql
@ -14,4 +14,4 @@ DB_PREFIX=
REDIS_HOST=localhost
REDIS_AUTH=(null)
REDIS_PORT=6379
REDIS_DB=0
REDIS_DB=0

View File

@ -37,7 +37,7 @@ class DemoConsumer extends ConsumerMessage
*
* @var string
*/
public $queue = 'im.message.queue';
public $queue = 'im:message:queue';
/**
* 路由key
@ -70,6 +70,13 @@ class DemoConsumer extends ConsumerMessage
echo $data;
echo PHP_EOL;
$server = server();
foreach (server()->connections as $fd){
if ($server->isEstablished($fd)) {
$server->push($fd, "Recv: 我是后台进程 [{$data}]");
}
}
return Result::ACK;
}

View File

@ -12,6 +12,7 @@ declare(strict_types=1);
namespace App\Controller;
use Hyperf\HttpServer\Contract\ResponseInterface;
use Hyperf\Amqp\Producer;
use App\Amqp\Producer\DemoProducer;
@ -22,13 +23,12 @@ class IndexController extends AbstractController
$user = $this->request->input('user', 'Hyperf');
$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')));
return [
'method' => $method,
'message' => "Hello {$user}.",
'message' => "Hello {$user}."
];
}
}

View File

@ -7,15 +7,23 @@ use Hyperf\Contract\OnCloseInterface;
use Hyperf\Contract\OnMessageInterface;
use Hyperf\Contract\OnOpenInterface;
use Swoole\Http\Request;
use Swoole\Server;
use Swoole\Websocket\Frame;
use Swoole\Server;
use Swoole\WebSocket\Server as WebSocketServer;
use Hyperf\Amqp\Producer;
use App\Amqp\Producer\DemoProducer;
class WebSocketController implements OnMessageInterface, OnOpenInterface, OnCloseInterface
{
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

View File

@ -14,9 +14,9 @@ namespace App\Process;
use Hyperf\AsyncQueue\Process\ConsumerProcess;
use Hyperf\Process\Annotation\Process;
/**
* @Process
*/
///**
// * @Process
// */
class AsyncQueueConsumer extends ConsumerProcess
{

View File

@ -12,6 +12,8 @@ date_default_timezone_set('Asia/Shanghai');
require BASE_PATH . '/vendor/autoload.php';
echo gethostbyname(null);
// Self-called anonymous function that creates its own scope and keep the global namespace clean.
(function () {
Hyperf\Di\ClassLoader::init();

View File

@ -19,7 +19,7 @@ return [
'name' => 'http',
'type' => Server::SERVER_HTTP,
'host' => '0.0.0.0',
'port' => 9501,
'port' => 9503,
'sock_type' => SWOOLE_SOCK_TCP,
'callbacks' => [
SwooleEvent::ON_REQUEST => [Hyperf\HttpServer\Server::class, 'onRequest'],
@ -29,7 +29,7 @@ return [
'name' => 'ws',
'type' => Server::SERVER_WEBSOCKET,
'host' => '0.0.0.0',
'port' => 9502,
'port' => 9504,
'sock_type' => SWOOLE_SOCK_TCP,
'callbacks' => [
SwooleEvent::ON_HAND_SHAKE => [Hyperf\WebSocketServer\Server::class, 'onHandShake'],