Skip to content

Release Pub/Sub 0.27.0

Choose a tag to compare

@blowmage blowmage released this 10 Aug 18:16
· 24484 commits to main since this release

This is a major release that offers new functionality. It adds the ability to asynchronously publish batches of messages when a threshold is met (batch message count, total batch size, batch age). It also adds the ability to receive and acknowledge messages via multiple streams.

A topic can now asynchronously publish messages in batches when a threshold is met (batch count, batch size, batch age), and yields a PublishResult object:

require "google/cloud/pubsub"

pubsub = Google::Cloud::Pubsub.new

topic = pubsub.topic "my-topic"
topic.publish_async "task completed" do |result|
  if result.succeeded?
    log_publish_success result.data
  else
    log_publish_failure result.data, result.error
  end
end

# time passes...

topic.async_publisher.stop.wait!

A Subscriber object streams messages using gRPC's streaming capability, placing received messages in inventory until they are handled by the user:

require "google/cloud/pubsub"

pubsub = Google::Cloud::Pubsub.new

sub = pubsub.subscription "my-topic-sub"

subscriber = sub.listen do |msg|
  log_received_message msg
  msg.ack!
end

subscriber.start

# time passes...

subscriber.stop.wait!
  • Publishing Messages Asynchronously
    • Topic#publish_async and AsyncPublisher added
    • AsyncPublisher can be stopped
    • PublishResult object is yielded from Topic#publish_async
  • Subscriber Streaming Messages
    • Subscription#listen changed to return a Subscriber object
    • Subscriber can open multiple streams to pull messages
    • Subscriber must be started to begin streaming messages
    • Subscriber can be stopped
    • Subscriber's received messages are leased until acknowledged or rejected
  • Other Additions
    • ReceivedMessage#reject! method added (aliased as nack! and ignore!)
    • Message#published_at attribute was added
  • Removals
    • Project#publish method has been removed
    • Project#subscribe method has been removed
    • Project#topic method argument autocreate was removed
    • Subscription#pull method argument autoack was removed
    • Subscription#wait_for_messages method argument autoack was removed