PHP Class Google\Cloud\PubSub\Message

Example: use Google\Cloud\ServiceBuilder; $cloud = new ServiceBuilder(); $pubsub = $cloud->pubsub(); $subscription = $pubsub->subscription('my-new-subscription'); $messages = $subscription->pull(); foreach ($messages as $message) { echo $message->data(); }
Datei anzeigen Open project: GoogleCloudPlatform/gcloud-php

Public Methods

Method Description
__construct ( array $message, array $metadata )
ackId ( ) : string Get the message ackId.
attribute ( string $key ) : string | null Retrieve a single message attribute.
attributes ( ) : array Retrieve all message attributes.
data ( ) : string The message payload.
id ( ) : string Get the message ID.
info ( ) : array Get the message data.
publishTime ( ) : DateTimeImmutable Get the message published time.
subscription ( ) : Subscription Get the subcription through which the message was obtained.

Method Details

__construct() public method

public __construct ( array $message, array $metadata )
$message array See [PubsubMessage](https://cloud.google.com/pubsub/docs/reference/rest/v1/PubsubMessage).
$metadata array { Message metadata @type string $ackId The message ackId. This is only set when messages are pulled from the PubSub service. @type Subscription $subscription The subscription the message was obtained from. This is only set when messages are delivered by pushDelivery.

ackId() public method

This is only set when message is obtained via {@see \Google\Cloud\PubSub\Subscription::pull()}. Example: echo $message->ackId();
public ackId ( ) : string
return string

attribute() public method

Example: echo $message->attribute('browser-name');
public attribute ( string $key ) : string | null
$key string The attribute key
return string | null

attributes() public method

Example: $attributes = $message->attributes();
public attributes ( ) : array
return array

data() public method

Example: echo $message->data();
public data ( ) : string
return string

id() public method

The message ID is assigned by the server when the message is published. Guaranteed to be unique within the topic. Example: echo $message->id();
public id ( ) : string
return string

info() public method

Available keys are ackId, subscription and message. Example: $info = $message->info();
public info ( ) : array
return array

publishTime() public method

Example: $time = $message->publishTime();
public publishTime ( ) : DateTimeImmutable
return DateTimeImmutable

subscription() public method

This is only set when the message is obtained via push delivery. Example: echo "Subscription Name: ". $message->subscription()->name();
public subscription ( ) : Subscription
return Subscription