How to add attributes to Google Pubsub message using Google_Service_Pubsub_Topics_Resource (PHP)?

Viewed 1095

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);
1 Answers

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']] );
Related