1

enter image description hereHi I have installed google pubsub library via composer in Laravel Framework

$ composer require google/cloud

Is this the right library for laravel framework. Has anyone used this library and successfully implemented pubsub.

Then I have created the topics and subscription. The Subscription is set as push. Then When I tried to publish the message, I am getting error. In google, I can't find such error been repeated. Here is my code.

use Google\Cloud\PubSub\PubSubClient;
$pubsub = new PubSubClient([
            "projectId" => $projectId
        ]);

// Get an instance of a previously created topic.
$topic = $pubSub->topic('my_topic');

// Publish a message to the topic.
$topic->publish(['data' => 'My new message.']);

enter image description here

Binod
  • 21
  • 4

1 Answers1

0

Publish function must provide at least one of data and attributes members.

enter image description here

Karunais13
  • 11
  • 1
  • I have added the attributes , but still I have having same issue public function publishMessage() { $projectId = 'projectIdname'; $pubsub = new PubSubClient([ "projectId" => $projectId ]); $topicName = 'projects/projectIdname/topics/topicName'; $topic = $pubsub->topic($topicName); $topic->publish([ 'data' => 'New User Registered', 'attributes' => [ 'id' => '1', 'userName' => 'John', 'location' => 'Detroit' ] ]); print("Message published" . PHP_EOL); } – Binod Jul 22 '20 at 00:43