google-cloud-spanner 2.37.0 → 2.37.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/OVERVIEW.md +71 -0
- data/lib/google/cloud/spanner/client.rb +20 -0
- data/lib/google/cloud/spanner/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 85dbbe5aa02ac93080c438688ca3f120a8435c8816fcd17ce64660e3b6bbc7ae
|
|
4
|
+
data.tar.gz: 741c37bb89f744d42fbd0d081511de90e069c999b6978f66482cca282d154200
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 49ef3061971e4673bac749c9fe8515db3d59c055261139113d432491a402093f37c27c9e92ed9dfedd85a9b5440b0f84538aa76b9e56fb41c10fb9eab0a05f33
|
|
7
|
+
data.tar.gz: 17d0238b2433dda6e57732d4a081fb1556b68ed2422b7f15cbedd48ca1ebd46705209eca4f28f9af61541a68ea846676e658e9566d11e95b57705e7f4670f7a8
|
data/CHANGELOG.md
CHANGED
data/OVERVIEW.md
CHANGED
|
@@ -298,6 +298,77 @@ db.snapshot do |snp|
|
|
|
298
298
|
end
|
|
299
299
|
```
|
|
300
300
|
|
|
301
|
+
## Using queues
|
|
302
|
+
|
|
303
|
+
A queue holds messages for consumers to receive. You create queues with the
|
|
304
|
+
`CREATE QUEUE` statement (see the [DDL
|
|
305
|
+
reference](https://cloud.google.com/spanner/docs/reference/standard-sql/data-definition-language)).
|
|
306
|
+
The examples in this section use this queue:
|
|
307
|
+
|
|
308
|
+
```sql
|
|
309
|
+
CREATE QUEUE OrderQueue (
|
|
310
|
+
Id INT64 NOT NULL,
|
|
311
|
+
Payload STRING(MAX) NOT NULL
|
|
312
|
+
) PRIMARY KEY (Id)
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
Use {Google::Cloud::Spanner::Commit#send_message Commit#send_message} to send a
|
|
316
|
+
message. The payload is converted the same way as column values, so pass a
|
|
317
|
+
`String` for a `STRING` payload column:
|
|
318
|
+
|
|
319
|
+
```ruby
|
|
320
|
+
require "google/cloud/spanner"
|
|
321
|
+
|
|
322
|
+
spanner = Google::Cloud::Spanner.new
|
|
323
|
+
|
|
324
|
+
db = spanner.client "my-instance", "my-database"
|
|
325
|
+
|
|
326
|
+
db.commit do |c|
|
|
327
|
+
c.send_message "OrderQueue", 101, "Order payload"
|
|
328
|
+
end
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
If a queue's payload column is `BYTES`, wrap the binary data in a `StringIO`,
|
|
332
|
+
as you would for a `BYTES` column in a table:
|
|
333
|
+
|
|
334
|
+
```ruby
|
|
335
|
+
db.commit do |c|
|
|
336
|
+
c.send_message "LabelQueue", 101, StringIO.new(File.binread("label.png"))
|
|
337
|
+
end
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
Receive messages with the `RECEIVE_<queue>` table-valued function, and use
|
|
341
|
+
{Google::Cloud::Spanner::Transaction#ack_message Transaction#ack_message} to
|
|
342
|
+
acknowledge each one in the same transaction as the write it caused:
|
|
343
|
+
|
|
344
|
+
```ruby
|
|
345
|
+
require "google/cloud/spanner"
|
|
346
|
+
|
|
347
|
+
spanner = Google::Cloud::Spanner.new
|
|
348
|
+
|
|
349
|
+
db = spanner.client "my-instance", "my-database"
|
|
350
|
+
|
|
351
|
+
results = db.execute_query "SELECT Id, Payload FROM RECEIVE_OrderQueue()"
|
|
352
|
+
|
|
353
|
+
results.rows.each do |row|
|
|
354
|
+
db.transaction do |tx|
|
|
355
|
+
tx.update "orders", [{ id: row[:Id], status: "PROCESSED" }]
|
|
356
|
+
tx.ack_message "OrderQueue", row[:Id]
|
|
357
|
+
end
|
|
358
|
+
end
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
To delay delivery, pass `deliver_time:`. To ack a message that might not
|
|
362
|
+
exist, pass `ignore_not_found: true`:
|
|
363
|
+
|
|
364
|
+
```ruby
|
|
365
|
+
db.commit do |c|
|
|
366
|
+
c.send_message "OrderQueue", 102, "Order payload",
|
|
367
|
+
deliver_time: Time.now + 300
|
|
368
|
+
c.ack_message "OrderQueue", 101, ignore_not_found: true
|
|
369
|
+
end
|
|
370
|
+
```
|
|
371
|
+
|
|
301
372
|
## Deleting databases
|
|
302
373
|
|
|
303
374
|
Use {Google::Cloud::Spanner::Admin::Database#database_admin
|
|
@@ -35,6 +35,12 @@ module Google
|
|
|
35
35
|
#
|
|
36
36
|
# A client is used to read and/or modify data in a Cloud Spanner database.
|
|
37
37
|
#
|
|
38
|
+
# A client also works with queues. Send and acknowledge messages with
|
|
39
|
+
# {Commit#send_message} and {Commit#ack_message} inside {#commit}, or with
|
|
40
|
+
# {Transaction#send_message} and {Transaction#ack_message} inside
|
|
41
|
+
# {#transaction}. Receive messages by querying the queue's `RECEIVE_`
|
|
42
|
+
# function with {#execute_query}.
|
|
43
|
+
#
|
|
38
44
|
# See {Google::Cloud::Spanner::Project#client}.
|
|
39
45
|
#
|
|
40
46
|
# @example
|
|
@@ -506,6 +512,20 @@ module Google
|
|
|
506
512
|
# puts "User #{row[:id]} is #{row[:name]}"
|
|
507
513
|
# end
|
|
508
514
|
#
|
|
515
|
+
# @example Receive messages from a queue with the RECEIVE_ function:
|
|
516
|
+
# require "google/cloud/spanner"
|
|
517
|
+
#
|
|
518
|
+
# spanner = Google::Cloud::Spanner.new
|
|
519
|
+
#
|
|
520
|
+
# db = spanner.client "my-instance", "my-database"
|
|
521
|
+
#
|
|
522
|
+
# # RECEIVE_ needs a strong read, which is the default here.
|
|
523
|
+
# results = db.execute_query "SELECT Id, Payload FROM RECEIVE_OrderQueue()"
|
|
524
|
+
#
|
|
525
|
+
# results.rows.each do |row|
|
|
526
|
+
# puts "Received message #{row[:Id]}"
|
|
527
|
+
# end
|
|
528
|
+
#
|
|
509
529
|
def execute_query sql, params: nil, types: nil, single_use: nil,
|
|
510
530
|
query_options: nil, request_options: nil,
|
|
511
531
|
call_options: nil, directed_read_options: nil
|