Skip to content

feat(spanner): add send_message and ack_message for queues - #260

Closed
torreypayne wants to merge 20 commits into
googleapis:mainfrom
torreypayne:feature/spanner-queues-draft
Closed

torreypayne wants to merge 20 commits into
googleapis:mainfrom
torreypayne:feature/spanner-queues-draft

Conversation

@torreypayne

Copy link
Copy Markdown
Member

Adds support for the Cloud Spanner queue mutations, Send and Ack, which shipped in google-cloud-spanner-v1 1.12.

  • Commit#send_message(queue, key, payload, send_options: nil) and Commit#ack_message(queue, key, ack_options: nil) add the mutations and return the key. Transaction has the same methods, so queue writes commit atomically with table writes.
  • Optional fields go in SendOptions (deliver_time) or AckOptions (ignore_not_found), or in a hash with the same keys, like commit_options:.
  • Keys work like Commit#delete. Payloads are converted like column values, so binary payloads are passed as StringIO.
  • The methods aren't named send because that would override Object#send.
  • Raises the google-cloud-spanner-v1 requirement to ~> 1.12.

The acceptance tests need an Enterprise edition instance and skip on the emulator. They pass against production.

Please squash-merge: earlier commits on the branch use names that were later replaced.

…nitest skip when backend feature is unprovisioned
Ruby has no bytes type, and a String's ASCII-8BIT tag doesn't reliably
mean binary data. Drop the inference and reuse the existing column-value
conversion in Convert.object_to_grpc_value: a String is sent as text,
and binary payloads are passed as a StringIO, same as BYTES columns.
…sage

Every Ruby object already has Object#send, so a Commit#send(queue, key, payload) would shadow it. Name the Send mutation method send_message, and the Ack method ack_message to match.
send_message takes send_options: and ack_message takes ack_options:. Each accepts the options object or a Hash with the same keys, like commit_options:. New Send or Ack fields can then be added to the options types without changing the method signatures. Both methods now return the message key, like delete.
Create TestQueue once per run in the per-run test database, then send and ack messages through Client#commit and Client#transaction. The tests check library behaviour only: an ack without ignore_not_found fails unless the message exists, so a successful ack shows the send landed. Queues need an Enterprise edition instance, so the queue DDL stays out of the shared schema, and the tests skip on the emulator.
The queue acceptance tests create this queue. It stays out of schema_ddl_statements because queues need an Enterprise edition instance and the emulator doesn't support them yet.
Mutation::Send and Mutation::Ack first shipped in google-cloud-spanner-v1 1.12.0.
Add a Using queues section to OVERVIEW.md that sends a message, receives messages with the RECEIVE_ function, and acks each one in the same transaction as its write. Add a queues paragraph to the Client overview and a Client#execute_query example that reads from RECEIVE_.
@torreypayne

Copy link
Copy Markdown
Member Author

Split into a five-PR stack for easier review: #261 (deps), #262 (Commit), #263 (Transaction), #264 (acceptance tests), #265 (docs). Together they match this PR's diff, plus the matching one-line Gemfile.lock update. This PR's Kokoro acceptance run passed today (490 runs, 0 failures). Closing in favor of the stack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: spanner Issues related to the Spanner API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant