publish() public method

$message must provide at least one of data and attributes members. Example: $topic->publish([ 'data' => 'New User Registered', 'attributes' => [ 'id' => 1, 'userName' => 'John', 'location' => 'Detroit' ] ]);
See also: https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.topics/publish Publish Message
public publish ( array $message, array $options = [] ) : array
$message array [Message Format](https://cloud.google.com/pubsub/docs/reference/rest/v1/PubsubMessage)
$options array [optional] Configuration Options
return array A list of message IDs
Beispiel #1
0
 public function testPublish()
 {
     $message = ['data' => 'hello world', 'attributes' => ['key' => 'value']];
     $ids = ['message1id'];
     $this->connection->publishMessage(Argument::that(function ($options) use($message) {
         if ($options['foo'] !== 'bar') {
             return false;
         }
         $message['data'] = base64_encode($message['data']);
         if ($options['messages'] !== [$message]) {
             return false;
         }
         return true;
     }))->willReturn($ids);
     $topic = new Topic($this->connection->reveal(), 'topic-name', 'project-name');
     $res = $topic->publish($message, ['foo' => 'bar']);
     $this->assertEquals($res, $ids);
 }