tlq-client 0.2.0 → 0.2.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/README.md +1 -1
- data/lib/tlq_client/version.rb +3 -1
- data/lib/tlq_client.rb +133 -7
- metadata +22 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '0888c52bfd5c94d767673f92efe410094daa86fa50d844408e4830cee364130a'
|
|
4
|
+
data.tar.gz: 796ed9252ce96e44464f39b99296d09ce7a3763cb2d0eb62594e40fad98c3a41
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c986e9700b352ebb948511e61fdb48a5cf92387456c5e1e40bad75f9a7d03bd2b852f985439c9662c91e92ffa28a530d2aef2d60ab3882555a9b76ae09563148
|
|
7
|
+
data.tar.gz: c9aabb8ad51cf2e4e70b072c6fe42291506bef4ef556a240be2529df03f8599cb1cf2ea0826d6586f912fa7b9cc8273fe7c48cce442743c5031fa0ba666c300b
|
data/README.md
CHANGED
|
@@ -30,7 +30,7 @@ require 'tlq_client'
|
|
|
30
30
|
# Initialize client (defaults to localhost:1337)
|
|
31
31
|
client = TLQClient.new
|
|
32
32
|
# or with custom host/port
|
|
33
|
-
client = TLQClient.new(host: '
|
|
33
|
+
client = TLQClient.new(host: 'tlq.skyak.tech', port: 8080)
|
|
34
34
|
|
|
35
35
|
# Add messages to the queue
|
|
36
36
|
message = client.add_message("Process order #123")
|
data/lib/tlq_client/version.rb
CHANGED
data/lib/tlq_client.rb
CHANGED
|
@@ -5,16 +5,67 @@ require 'net/http'
|
|
|
5
5
|
require 'uri'
|
|
6
6
|
require_relative 'tlq_client/version'
|
|
7
7
|
|
|
8
|
+
# A client library for communicating with a TLQ (Tiny Little Queue) server.
|
|
9
|
+
#
|
|
10
|
+
# TLQClient provides a simple interface for message queue operations including
|
|
11
|
+
# adding, retrieving, deleting, and retrying messages.
|
|
12
|
+
#
|
|
13
|
+
# @example Basic usage
|
|
14
|
+
# client = TLQClient.new(host: 'localhost', port: 1337)
|
|
15
|
+
#
|
|
16
|
+
# # Add a message
|
|
17
|
+
# message = client.add_message("Hello, TLQ!")
|
|
18
|
+
#
|
|
19
|
+
# # Retrieve messages
|
|
20
|
+
# messages = client.get_messages(5)
|
|
21
|
+
#
|
|
22
|
+
# # Process and delete
|
|
23
|
+
# ids = messages.map { |m| m['id'] }
|
|
24
|
+
# client.delete_messages(ids)
|
|
25
|
+
#
|
|
26
|
+
# @see https://github.com/robinbakker/tiny-little-queue TLQ Server
|
|
8
27
|
class TLQClient
|
|
9
|
-
|
|
28
|
+
# @return [String] the hostname of the TLQ server
|
|
29
|
+
attr_reader :host
|
|
10
30
|
|
|
31
|
+
# @return [Integer] the port number of the TLQ server
|
|
32
|
+
attr_reader :port
|
|
33
|
+
|
|
34
|
+
# @return [String] the base URI for API requests
|
|
35
|
+
attr_reader :base_uri
|
|
36
|
+
|
|
37
|
+
# Creates a new TLQClient instance.
|
|
38
|
+
#
|
|
39
|
+
# @param host [String] the hostname of the TLQ server (default: 'localhost')
|
|
40
|
+
# @param port [Integer] the port number of the TLQ server (default: 1337)
|
|
41
|
+
#
|
|
42
|
+
# @example Connect to default server
|
|
43
|
+
# client = TLQClient.new
|
|
44
|
+
#
|
|
45
|
+
# @example Connect to custom server
|
|
46
|
+
# client = TLQClient.new(host: 'tlq.skyak.tech', port: 8080)
|
|
11
47
|
def initialize(host: 'localhost', port: 1337)
|
|
12
48
|
@host = host
|
|
13
49
|
@port = port
|
|
14
50
|
@base_uri = "http://#{@host}:#{@port}"
|
|
15
51
|
end
|
|
16
52
|
|
|
17
|
-
#
|
|
53
|
+
# Adds a message to the queue.
|
|
54
|
+
#
|
|
55
|
+
# @param body [String, Hash, Array] the message body to add to the queue.
|
|
56
|
+
# Can be a string or any JSON-serializable object.
|
|
57
|
+
#
|
|
58
|
+
# @return [Hash] the created message object containing 'id', 'body', and metadata
|
|
59
|
+
#
|
|
60
|
+
# @raise [RuntimeError] if the server response cannot be parsed as JSON
|
|
61
|
+
# @raise [RuntimeError] if the HTTP request fails
|
|
62
|
+
#
|
|
63
|
+
# @example Add a simple string message
|
|
64
|
+
# message = client.add_message("Hello, World!")
|
|
65
|
+
# puts message['id'] # => "abc123"
|
|
66
|
+
#
|
|
67
|
+
# @example Add a hash message
|
|
68
|
+
# message = client.add_message({ event: 'user_signup', user_id: 42 })
|
|
18
69
|
def add_message(body)
|
|
19
70
|
response = post('/add', { body: body })
|
|
20
71
|
JSON.parse(response.body)
|
|
@@ -24,7 +75,26 @@ class TLQClient
|
|
|
24
75
|
raise "HTTP request failed: #{e.message}"
|
|
25
76
|
end
|
|
26
77
|
|
|
27
|
-
#
|
|
78
|
+
# Retrieves messages from the queue.
|
|
79
|
+
#
|
|
80
|
+
# Messages are leased to the client and must be either deleted (to acknowledge
|
|
81
|
+
# successful processing) or retried (to return them to the queue).
|
|
82
|
+
#
|
|
83
|
+
# @param count [Integer] the number of messages to retrieve (default: 1)
|
|
84
|
+
#
|
|
85
|
+
# @return [Array<Hash>] an array of message objects, each containing 'id' and 'body'
|
|
86
|
+
#
|
|
87
|
+
# @raise [RuntimeError] if the server response cannot be parsed as JSON
|
|
88
|
+
# @raise [RuntimeError] if the HTTP request fails
|
|
89
|
+
#
|
|
90
|
+
# @example Get a single message
|
|
91
|
+
# messages = client.get_messages
|
|
92
|
+
# message = messages.first
|
|
93
|
+
# puts message['body']
|
|
94
|
+
#
|
|
95
|
+
# @example Get multiple messages
|
|
96
|
+
# messages = client.get_messages(10)
|
|
97
|
+
# messages.each { |m| process(m) }
|
|
28
98
|
def get_messages(count = 1)
|
|
29
99
|
response = post('/get', { count: count })
|
|
30
100
|
parsed = JSON.parse(response.body)
|
|
@@ -35,7 +105,22 @@ class TLQClient
|
|
|
35
105
|
raise "HTTP request failed: #{e.message}"
|
|
36
106
|
end
|
|
37
107
|
|
|
38
|
-
#
|
|
108
|
+
# Deletes messages from the queue permanently.
|
|
109
|
+
#
|
|
110
|
+
# Use this method to acknowledge successful processing of messages.
|
|
111
|
+
# Once deleted, messages cannot be recovered.
|
|
112
|
+
#
|
|
113
|
+
# @param ids [String, Array<String>] a single message ID or array of message IDs to delete
|
|
114
|
+
#
|
|
115
|
+
# @return [Boolean] true if the deletion was successful
|
|
116
|
+
#
|
|
117
|
+
# @raise [RuntimeError] if the HTTP request fails
|
|
118
|
+
#
|
|
119
|
+
# @example Delete a single message
|
|
120
|
+
# client.delete_messages("abc123")
|
|
121
|
+
#
|
|
122
|
+
# @example Delete multiple messages
|
|
123
|
+
# client.delete_messages(["abc123", "def456", "ghi789"])
|
|
39
124
|
def delete_messages(ids)
|
|
40
125
|
response = post('/delete', { ids: Array(ids) })
|
|
41
126
|
response.body == '"Success"'
|
|
@@ -43,7 +128,22 @@ class TLQClient
|
|
|
43
128
|
raise "HTTP request failed: #{e.message}"
|
|
44
129
|
end
|
|
45
130
|
|
|
46
|
-
#
|
|
131
|
+
# Returns messages to the queue for reprocessing.
|
|
132
|
+
#
|
|
133
|
+
# Use this method when message processing fails and you want to retry later.
|
|
134
|
+
# The messages will be returned to the queue and can be retrieved again.
|
|
135
|
+
#
|
|
136
|
+
# @param ids [String, Array<String>] a single message ID or array of message IDs to retry
|
|
137
|
+
#
|
|
138
|
+
# @return [Boolean] true if the retry was successful
|
|
139
|
+
#
|
|
140
|
+
# @raise [RuntimeError] if the HTTP request fails
|
|
141
|
+
#
|
|
142
|
+
# @example Retry a single message
|
|
143
|
+
# client.retry_messages("abc123")
|
|
144
|
+
#
|
|
145
|
+
# @example Retry multiple messages
|
|
146
|
+
# client.retry_messages(["abc123", "def456"])
|
|
47
147
|
def retry_messages(ids)
|
|
48
148
|
response = post('/retry', { ids: Array(ids) })
|
|
49
149
|
response.body == '"Success"'
|
|
@@ -51,7 +151,16 @@ class TLQClient
|
|
|
51
151
|
raise "HTTP request failed: #{e.message}"
|
|
52
152
|
end
|
|
53
153
|
|
|
54
|
-
#
|
|
154
|
+
# Purges all messages from the queue.
|
|
155
|
+
#
|
|
156
|
+
# @note This operation is irreversible. All messages will be permanently deleted.
|
|
157
|
+
#
|
|
158
|
+
# @return [Boolean] true if the purge was successful
|
|
159
|
+
#
|
|
160
|
+
# @raise [RuntimeError] if the HTTP request fails
|
|
161
|
+
#
|
|
162
|
+
# @example Clear the queue
|
|
163
|
+
# client.purge_queue
|
|
55
164
|
def purge_queue
|
|
56
165
|
response = post('/purge', {})
|
|
57
166
|
response.body == '"Success"'
|
|
@@ -59,7 +168,16 @@ class TLQClient
|
|
|
59
168
|
raise "HTTP request failed: #{e.message}"
|
|
60
169
|
end
|
|
61
170
|
|
|
62
|
-
#
|
|
171
|
+
# Checks if the TLQ server is reachable and responding.
|
|
172
|
+
#
|
|
173
|
+
# @return [Boolean] true if the server is healthy and responding
|
|
174
|
+
#
|
|
175
|
+
# @raise [RuntimeError] if the health check request fails
|
|
176
|
+
#
|
|
177
|
+
# @example Check server status
|
|
178
|
+
# if client.health_check
|
|
179
|
+
# puts "Server is running"
|
|
180
|
+
# end
|
|
63
181
|
def health_check
|
|
64
182
|
uri = URI("#{@base_uri}/hello")
|
|
65
183
|
response = Net::HTTP.get_response(uri)
|
|
@@ -70,6 +188,14 @@ class TLQClient
|
|
|
70
188
|
|
|
71
189
|
private
|
|
72
190
|
|
|
191
|
+
# Sends a POST request to the TLQ server.
|
|
192
|
+
#
|
|
193
|
+
# @param path [String] the API endpoint path
|
|
194
|
+
# @param data [Hash] the request body data to send as JSON
|
|
195
|
+
#
|
|
196
|
+
# @return [Net::HTTPResponse] the HTTP response object
|
|
197
|
+
#
|
|
198
|
+
# @api private
|
|
73
199
|
def post(path, data)
|
|
74
200
|
uri = URI("#{@base_uri}#{path}")
|
|
75
201
|
http = Net::HTTP.new(uri.host, uri.port)
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: tlq-client
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nebojsa Jakovljevic
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2025-11-
|
|
11
|
+
date: 2025-11-28 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -52,6 +52,20 @@ dependencies:
|
|
|
52
52
|
- - "~>"
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
54
|
version: '13.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: yard
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0.9'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0.9'
|
|
55
69
|
description: A Ruby client library to interact with TLQ message queue
|
|
56
70
|
email:
|
|
57
71
|
- nebojsa@skyak.tech
|
|
@@ -71,7 +85,8 @@ metadata:
|
|
|
71
85
|
homepage_uri: https://tinylittlequeue.app/
|
|
72
86
|
source_code_uri: https://github.com/skyaktech/tlq-client-ruby
|
|
73
87
|
changelog_uri: https://github.com/skyaktech/tlq-client-ruby/blob/main/CHANGELOG.md
|
|
74
|
-
|
|
88
|
+
documentation_uri: https://rubydoc.info/gems/tlq-client
|
|
89
|
+
post_install_message:
|
|
75
90
|
rdoc_options: []
|
|
76
91
|
require_paths:
|
|
77
92
|
- lib
|
|
@@ -79,15 +94,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
79
94
|
requirements:
|
|
80
95
|
- - ">="
|
|
81
96
|
- !ruby/object:Gem::Version
|
|
82
|
-
version:
|
|
97
|
+
version: 3.1.0
|
|
83
98
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
99
|
requirements:
|
|
85
100
|
- - ">="
|
|
86
101
|
- !ruby/object:Gem::Version
|
|
87
102
|
version: '0'
|
|
88
103
|
requirements: []
|
|
89
|
-
rubygems_version: 3.
|
|
90
|
-
signing_key:
|
|
104
|
+
rubygems_version: 3.4.19
|
|
105
|
+
signing_key:
|
|
91
106
|
specification_version: 4
|
|
92
107
|
summary: Ruby client for TLQ (Tiny Little Queue)
|
|
93
108
|
test_files: []
|