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 
    
    
  
  
  
  
  
  
  
  
  
    
The received attributes.
 - 
  
    
      #data  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
The received data.
 - 
  
    
      #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.
 
Constructor Details
#initialize(data = nil, attributes = {}) ⇒ Message
Create an empty Message object. This can be used to publish several messages in bulk.
      54 55 56 57 58 59 60 61  | 
    
      # File 'lib/google/cloud/pubsub/message.rb', line 54 def initialize data = nil, attributes = {} # Convert attributes to strings to match the protobuf definition attributes = Hash[attributes.map { |k, v| [String(k), String(v)] }] @grpc = Google::Pubsub::V1::PubsubMessage.new( data: String(data).encode("ASCII-8BIT"), attributes: attributes) end  | 
  
Instance Method Details
#attributes ⇒ Object
The received attributes.
      71 72 73 74 75  | 
    
      # File 'lib/google/cloud/pubsub/message.rb', line 71 def attributes return @grpc.attributes.to_h if @grpc.attributes.respond_to? :to_h # Enumerable doesn't have to_h on Ruby 2.0, so fallback to this Hash[@grpc.attributes.to_a] end  | 
  
#data ⇒ Object
The received data.
      65 66 67  | 
    
      # File 'lib/google/cloud/pubsub/message.rb', line 65 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.
      80 81 82  | 
    
      # File 'lib/google/cloud/pubsub/message.rb', line 80 def @grpc. end  |