Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions app/Controller/MsgController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@

namespace App\Controller;

use DtmClient\Barrier;
use DtmClient\Msg;
use DtmClient\TransContext;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\HttpServer\Contract\RequestInterface;
use Psr\Http\Message\ServerRequestInterface;

#[Controller(prefix: '/msg')]
class MsgController extends AbstractSagaController
{
private Msg $msg;

public function __construct(Msg $msg)
public function __construct(Msg $msg, private Barrier $barrier)
{
$this->msg = $msg;
}
Expand All @@ -22,10 +25,20 @@ public function msg()
{
$gid = $this->msg->generateGid();
TransContext::setGid($gid);
$this->msg->doAndSubmit('http_msg_doAndCommit', function () {
$this->msg->doAndSubmit($this->serviceUri . '/msg/queryPrepared', function () {
$this->msg->add('test', ['name' => 'dtmMsg']);
});
}

#[RequestMapping(path: 'queryPrepared')]
public function queryPrepared(RequestInterface $request): string
{
$queryParams = $request->query();
$gid = $queryParams['gid'];
$transType = $queryParams['trans_type'];

return $this->barrier->queryPrepared($transType, $gid);
}


}
15 changes: 15 additions & 0 deletions app/Controller/TccGrpcController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@
use App\Grpc\GrpcClient;
use App\Grpc\Message\BusiReply;
use App\Grpc\Message\BusiReq;
use DtmClient\Annotation\Barrier;
use DtmClient\Middleware\DtmMiddleware;
use DtmClient\TCC;
use Hyperf\Contract\ConfigInterface;
use Hyperf\Contract\StdoutLoggerInterface;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\Middleware;

#[Controller(prefix: '/tcc-grpc')]
class TccGrpcController
Expand Down Expand Up @@ -65,31 +68,43 @@ public function successCase()
return 'success';
}

#[Middleware(middleware: DtmMiddleware::class)]
#[Barrier]
public function transOutTcc(BusiReq $request)
{
return new BusiReply();
}

#[Middleware(middleware: DtmMiddleware::class)]
#[Barrier]
public function transOutConfirm(BusiReq $request)
{
return new BusiReply();
}

#[Middleware(middleware: DtmMiddleware::class)]
#[Barrier]
public function transOutCancel(BusiReq $request)
{
return new BusiReply();
}

#[Middleware(middleware: DtmMiddleware::class)]
#[Barrier]
public function transInTcc(BusiReq $request)
{
return new BusiReply();
}

#[Middleware(middleware: DtmMiddleware::class)]
#[Barrier]
public function transInConfirm(BusiReq $request)
{
return new BusiReply();
}

#[Middleware(middleware: DtmMiddleware::class)]
#[Barrier]
public function transInCancel(BusiReq $request)
{
return new BusiReply();
Expand Down
4 changes: 3 additions & 1 deletion app/Listener/DbQueryExecutedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
namespace App\Listener;

use Hyperf\Contract\StdoutLoggerInterface;
use Hyperf\Database\Events\QueryExecuted;
use Hyperf\Event\Annotation\Listener;
use Hyperf\Event\Contract\ListenerInterface;
Expand All @@ -29,7 +30,8 @@ class DbQueryExecutedListener implements ListenerInterface

public function __construct(ContainerInterface $container)
{
$this->logger = $container->get(LoggerFactory::class)->get('sql');
// $this->logger = $container->get(LoggerFactory::class)->get('sql');
$this->logger = $container->get(StdoutLoggerInterface::class);
}

public function listen(): array
Expand Down
1 change: 1 addition & 0 deletions config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
Router::post('/TransInConfirm', 'App\Controller\TccGrpcController@transInConfirm');
Router::post('/TransInRevert', 'App\Controller\TccGrpcController@transInRevert');
});
// , ['middleware' => [\DtmClient\Middleware\DtmMiddleware::class]]
});

Router::addGroup('/tcc', function () {
Expand Down