Class: Google::Cloud::PubSub::Message
- Inherits:
-
Object
- Object
- Google::Cloud::PubSub::Message
- Defined in:
- lib/google/cloud/pubsub/message.rb
Overview
Message
Represents a Pub/Sub Message.
Message objects are created by Topic#publish. Subscription#pull returns an array of ReceivedMessage objects, each of which contains a Message object. Each ReceivedMessage object can be acknowledged and/or delayed.
Instance Method Summary collapse
-
#attributes ⇒ Object
Optional attributes for the message.
-
#data ⇒ Object
The message payload.
-
#initialize(data = nil, attributes = {}) ⇒ Message
constructor
Create an empty Message object.
-
#message_id ⇒ Object
(also: #msg_id)
The ID of this message, assigned by the server at publication time.
-
#ordering_key ⇒ String
Identifies related messages for which publish order should be respected.
-
#published_at ⇒ Object
(also: #publish_time)
The time at which the message was published.
Constructor Details
#initialize(data = nil, attributes = {}) ⇒ Message
Create an empty Message object. This can be used to publish several messages in bulk.
63 64 65 66 67 68 69 70 71 |
# File 'lib/google/cloud/pubsub/message.rb', line 63 def initialize data = nil, attributes = {} # Convert attributes to strings to match the protobuf definition attributes = attributes.to_h { |k, v| [String(k), String(v)] } @grpc = Google::Cloud::PubSub::V1::PubsubMessage.new( data: String(data).dup.force_encoding(Encoding::ASCII_8BIT), attributes: attributes ) end |
Instance Method Details
#attributes ⇒ Object
Optional attributes for the message.
82 83 84 85 |
# File 'lib/google/cloud/pubsub/message.rb', line 82 def attributes return @grpc.attributes.to_h if @grpc.attributes.respond_to? :to_h @grpc.attributes.to_a.to_h end |
#data ⇒ Object
The message payload. This data is a list of bytes encoded as ASCII-8BIT.
76 77 78 |
# File 'lib/google/cloud/pubsub/message.rb', line 76 def data @grpc.data end |
#message_id ⇒ Object Also known as: msg_id
The ID of this message, assigned by the server at publication time. Guaranteed to be unique within the topic.
90 91 92 |
# File 'lib/google/cloud/pubsub/message.rb', line 90 def @grpc. end |
#ordering_key ⇒ String
Identifies related messages for which publish order should be respected.
Google Cloud Pub/Sub ordering keys provide the ability to ensure related messages are sent to subscribers in the order in which they were published. Messages can be tagged with an ordering key, a string that identifies related messages for which publish order should be respected. The service guarantees that, for a given ordering key and publisher, messages are sent to subscribers in the order in which they were published. Ordering does not require sacrificing high throughput or scalability, as the service automatically distributes messages for different ordering keys across subscribers.
See Topic#publish_async and Subscription#listen.
120 121 122 |
# File 'lib/google/cloud/pubsub/message.rb', line 120 def ordering_key @grpc.ordering_key end |
#published_at ⇒ Object Also known as: publish_time
The time at which the message was published.
97 98 99 |
# File 'lib/google/cloud/pubsub/message.rb', line 97 def published_at Convert. @grpc.publish_time end |