I've got some legacy code, where I need to use the Google Pubsub old API Google_Service_Pubsub_Topics_Resource to publish a message. How do I add attributes to the message? I keep getting an error:
(publish) unknown parameter: 'myattr'
Here's the code:
$pubsubService = new Google_Service_Pubsub($client);
$req = new Google_Service_Pubsub_PublishRequest();
$req->setTopic("testtopic");
$msg = new Google_Service_Pubsub_PubsubMessage();
$msg->setData("....");
$req->setMessage($msg);
$opts = array(
"myattr" => "test"
);
$ret = $pubsubService->topics->publish($req, $opts);
Looking at the google cloud documentation :
You need to put your attributes in an array with the key attributes .
So something like this :
$pubsubService->topics->publish($req, ['attributes' => ['myattr'=>'test']] );
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.