Reference documentation and code samples for the Cloud PubSub Client class Message.
Represents a PubSub Message.
Example:
use Google\Cloud\PubSub\PubSubClient;
$pubsub = new PubSubClient();
$subscription = $pubsub->subscription('my-new-subscription');
$messages = $subscription->pull();
foreach ($messages as $message) {
echo $message->data();
}
Methods
__construct
message
array
Message Options
See [PubsubMessage](https://cloud.google.com/pubsub/docs/reference/rest/v1/PubsubMessage).
↳ data
string
The message data field. If this is empty, the message must contain at least one attribute.
↳ attributes
array
Optional attributes for this message.
↳ messageId
string
ID of this message, assigned by the server when the message is published.
↳ publishTime
string
The time at which the message was published, populated by the server when it receives the publish call.
↳ orderingKey
string
The message ordering key.
metadata
array
Message metadata
↳ ackId
string
The message ackId. This is only set when messages are pulled from the PubSub service.
↳ deliveryAttempt
int
Delivery attempt counter is 1 + (the sum of number of NACKs and number of ack_deadline exceeds) for this message. If a DeadLetterPolicy is not set on the subscription, this will be null
.
↳ subscription
Subscription
The subscription the message was obtained from. This is only set when messages are delivered by pushDelivery
data
The message payload.
Example:
echo $message->data();
string
attribute
Retrieve a single message attribute.
Example:
echo $message->attribute('browser-name');
key
string
The attribute key
string|null
attributes
Retrieve all message attributes.
Example:
$attributes = $message->attributes();
array
id
Get the message ID.
The message ID is assigned by the server when the message is published. Guaranteed to be unique within the topic.
Example:
echo $message->id();
string
orderingKey
Get the message ordering key.
Example:
$orderingKey = $message->orderingKey();
string|null
publishTime
Get the message published time.
Example:
$time = $message->publishTime();
DateTimeInterface
|null
ackId
Get the message ackId.
This is only set when message is obtained via Google\Cloud\PubSub\Google\Cloud\PubSub\Subscription::pull() .
Example:
echo $message->ackId();
string
deliveryAttempt
Get the delivery attempt count.
If a DeadLetterPolicy is not set on the subscription, this will be null
.
Example:
echo $message->deliveryAttempt();
int|null
subscription
Get the subcription through which the message was obtained.
This is only set when the message is obtained via push delivery.
Example:
echo "Subscription Name: ". $message->subscription()->name();
info
Get the message data.
Available keys are ackId
, subscription
and message
.
Example:
$info = $message->info();
array