<?php


namespace App\Services\common;

use Api\PhpUtils\Kafka\KafkaUtil;
use Api\PhpUtils\Log\FileLog;

class KafkaService
{

    /**
     * marketing 广播
     */
    public static function productMarketingUpdate(array $marketingInfo) : void
    {
        if ($marketingInfo['userId'] == '17963416161910792')
        {
            return;
        }

        $msg = json_encode([
            'marketingInfo' => $marketingInfo,
            'time' => time(),
        ], JSON_FORCE_OBJECT);
        $serverName = 'goods.publish';

        $kafka = KafkaUtil::getInstance($serverName);

        if ($kafka->produce($msg, $marketingInfo['activityId'])) {
            FileLog::info(sprintf('kafka produce success serverName %s msg = %s', $serverName, $msg));
        }
        else {
            FileLog::error(sprintf('kafka produce failure serverName %s msg = %s', $serverName, $msg));
        }


    }

}