Laravel接入Apollo

廢話不說,直接上代碼

namespace App\Console\Commands\Apollo;

use Illuminate\Console\Command;
use Illuminate\Support\Arr;
use Org\Multilinguals\Apollo\Client\ApolloClient;

class SyncCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'ue:apollo:sync';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '阿波羅同步';

    protected $config = [];

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        while (true) {
            $this->doSync();
            sleep(10);
        }

    }


    protected function doSync()
    {

        if (!$this->config) {
            $this->config = config('apollo');
        }

        $server = Arr::get($this->config, 'server');

        $appid = Arr::get($this->config, 'app_id');

        $namespaces = Arr::get($this->config, 'namespace');

        $apollo = new ApolloClient($server, $appid, $namespaces);

        $error = $apollo->start();

        logger()->error(null, ['error' => $error, 'class' => __CLASS__]);

    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章