[英]How to add attributes to Google Pubsub message using Google_Service_Pubsub_Topics_Resource (PHP)?
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. 我有一些旧代码,我需要在其中使用Google Pubsub旧API Google_Service_Pubsub_Topics_Resource来发布消息。 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 : 查看Google Cloud文档 :
You need to put your attributes in an array with the key attributes . 您需要将属性与键属性放到一个数组中。
So something like this : 所以像这样:
$pubsubService->topics->publish($req, ['attributes' => ['myattr'=>'test']] );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.