tlq-client 0.2.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 23e82549788eabfb735a5035d8b8f478df7e570a6b1c43338ea28714f2ef0824
4
+ data.tar.gz: 584f2eb0f74e20b8df96401630c5843184c15b31f48e693739f159f5ba22f42a
5
+ SHA512:
6
+ metadata.gz: a2da29977ea8ea209bcd448c8928b59e58ef76c3bf0b55ce0f8008edd9a12070832eb3af46c1c5c350cefee41484a43f41dc279ab7b78effa0c928e84de05645
7
+ data.tar.gz: 44d102142b0750efca0db88d4f7fba9f9cf8891117c8456bf852604a0eb59d65f63b6e590b6b9a4da8ffd034449e771d230a19423a4d4a813f46f13c05684c4d
data/CHANGELOG.md ADDED
@@ -0,0 +1,18 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.2.0] - 2025-11-26
9
+
10
+ ### Added
11
+
12
+ - Initial release of TLQ Client gem
13
+ - `add_message(body)` - Add a message to the queue
14
+ - `get_messages(count)` - Retrieve messages from the queue
15
+ - `delete_messages(ids)` - Delete processed messages
16
+ - `retry_messages(ids)` - Return messages to the queue
17
+ - `purge_queue` - Clear all messages
18
+ - `health_check` - Check server status
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,137 @@
1
+ # TLQ Client
2
+
3
+ Ruby client for [TLQ (Tiny Little Queue)](https://tinylittlequeue.app/) message queue service.
4
+
5
+ ## Installation
6
+
7
+ Add to your Gemfile:
8
+
9
+ ```ruby
10
+ gem 'tlq-client'
11
+ ```
12
+
13
+ Then run:
14
+
15
+ ```bash
16
+ bundle install
17
+ ```
18
+
19
+ Or install directly:
20
+
21
+ ```bash
22
+ gem install tlq-client
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ ```ruby
28
+ require 'tlq_client'
29
+
30
+ # Initialize client (defaults to localhost:1337)
31
+ client = TLQClient.new
32
+ # or with custom host/port
33
+ client = TLQClient.new(host: 'queue.example.com', port: 8080)
34
+
35
+ # Add messages to the queue
36
+ message = client.add_message("Process order #123")
37
+ puts message['id'] # => "019ac13f-3286-7f00-bcb7-c86fe88798b4"
38
+
39
+ # Get messages (default: 1, max configurable on server)
40
+ messages = client.get_messages(10)
41
+
42
+ # Process messages
43
+ messages.each do |msg|
44
+ begin
45
+ # Your processing logic here
46
+ process(msg['body'])
47
+
48
+ # Success - delete the message
49
+ client.delete_messages(msg['id'])
50
+ rescue => e
51
+ # Failed - return to queue for retry
52
+ client.retry_messages(msg['id'])
53
+ end
54
+ end
55
+
56
+ # Batch operations
57
+ ids = messages.map { |m| m['id'] }
58
+ client.delete_messages(ids) # Delete multiple
59
+ client.retry_messages(ids) # Retry multiple
60
+
61
+ # Health check
62
+ client.health_check # => true
63
+
64
+ # Purge all messages (use with caution!)
65
+ client.purge_queue
66
+ ```
67
+
68
+ ## API Reference
69
+
70
+ ### `TLQClient.new(host: 'localhost', port: 1337)`
71
+
72
+ Creates a new client instance.
73
+
74
+ ### `add_message(body) → Hash`
75
+
76
+ Adds a message to the queue. Returns the message object:
77
+
78
+ ```ruby
79
+ {
80
+ 'id' => 'uuid-v7',
81
+ 'body' => 'your message',
82
+ 'state' => 'Ready',
83
+ 'retry_count' => 0
84
+ }
85
+ ```
86
+
87
+ ### `get_messages(count = 1) → Array`
88
+
89
+ Retrieves messages from the queue. Messages transition to "Processing" state and become invisible to other consumers.
90
+
91
+ ### `delete_messages(ids) → Boolean`
92
+
93
+ Permanently removes messages from the queue. Accepts a single ID or array of IDs.
94
+
95
+ ### `retry_messages(ids) → Boolean`
96
+
97
+ Returns messages to the queue for reprocessing. Increments `retry_count`. Accepts a single ID or array of IDs.
98
+
99
+ ### `purge_queue → Boolean`
100
+
101
+ Removes all messages from the queue. Cannot be undone.
102
+
103
+ ### `health_check → Boolean`
104
+
105
+ Returns `true` if the TLQ server is reachable.
106
+
107
+ ## Requirements
108
+
109
+ - Ruby >= 2.6
110
+ - Running [TLQ server](https://github.com/skyaktech/tlq)
111
+
112
+ ## Development
113
+
114
+ ```bash
115
+ # Install dependencies
116
+ bundle install
117
+
118
+ # Run unit tests
119
+ bundle exec rake test
120
+
121
+ # Run integration tests (requires TLQ server)
122
+ bundle exec rake integration
123
+
124
+ # Run all tests
125
+ bundle exec rake test_all
126
+ ```
127
+
128
+ ## Other Client Libraries
129
+
130
+ - [Go](https://github.com/skyaktech/tlq-client-go)
131
+ - [Node.js](https://github.com/skyaktech/tlq-client-node)
132
+ - [Python](https://github.com/skyaktech/tlq-client-py)
133
+ - [Rust](https://github.com/skyaktech/tlq-client-rust)
134
+
135
+ ## License
136
+
137
+ MIT
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class TLQClient
4
+ VERSION = "0.2.0"
5
+ end
data/lib/tlq_client.rb ADDED
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'net/http'
5
+ require 'uri'
6
+ require_relative 'tlq_client/version'
7
+
8
+ class TLQClient
9
+ attr_reader :host, :port, :base_uri
10
+
11
+ def initialize(host: 'localhost', port: 1337)
12
+ @host = host
13
+ @port = port
14
+ @base_uri = "http://#{@host}:#{@port}"
15
+ end
16
+
17
+ # Add a message to the queue
18
+ def add_message(body)
19
+ response = post('/add', { body: body })
20
+ JSON.parse(response.body)
21
+ rescue JSON::ParserError => e
22
+ raise "Failed to parse response: #{e.message}"
23
+ rescue StandardError => e
24
+ raise "HTTP request failed: #{e.message}"
25
+ end
26
+
27
+ # Get messages from the queue
28
+ def get_messages(count = 1)
29
+ response = post('/get', { count: count })
30
+ parsed = JSON.parse(response.body)
31
+ parsed.is_a?(Array) ? parsed : Array(parsed['messages'] || parsed)
32
+ rescue JSON::ParserError => e
33
+ raise "Failed to parse response: #{e.message}"
34
+ rescue StandardError => e
35
+ raise "HTTP request failed: #{e.message}"
36
+ end
37
+
38
+ # Delete messages from the queue
39
+ def delete_messages(ids)
40
+ response = post('/delete', { ids: Array(ids) })
41
+ response.body == '"Success"'
42
+ rescue StandardError => e
43
+ raise "HTTP request failed: #{e.message}"
44
+ end
45
+
46
+ # Retry messages (return to queue)
47
+ def retry_messages(ids)
48
+ response = post('/retry', { ids: Array(ids) })
49
+ response.body == '"Success"'
50
+ rescue StandardError => e
51
+ raise "HTTP request failed: #{e.message}"
52
+ end
53
+
54
+ # Purge all messages from the queue
55
+ def purge_queue
56
+ response = post('/purge', {})
57
+ response.body == '"Success"'
58
+ rescue StandardError => e
59
+ raise "HTTP request failed: #{e.message}"
60
+ end
61
+
62
+ # Check server health
63
+ def health_check
64
+ uri = URI("#{@base_uri}/hello")
65
+ response = Net::HTTP.get_response(uri)
66
+ response.body == '"Hello World"'
67
+ rescue StandardError => e
68
+ raise "Health check failed: #{e.message}"
69
+ end
70
+
71
+ private
72
+
73
+ def post(path, data)
74
+ uri = URI("#{@base_uri}#{path}")
75
+ http = Net::HTTP.new(uri.host, uri.port)
76
+ request = Net::HTTP::Post.new(uri)
77
+ request['Content-Type'] = 'application/json'
78
+ request.body = JSON.generate(data)
79
+ http.request(request)
80
+ end
81
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tlq-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Nebojsa Jakovljevic
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2025-11-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '13.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '13.0'
55
+ description: A Ruby client library to interact with TLQ message queue
56
+ email:
57
+ - nebojsa@skyak.tech
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - CHANGELOG.md
63
+ - LICENSE
64
+ - README.md
65
+ - lib/tlq_client.rb
66
+ - lib/tlq_client/version.rb
67
+ homepage: https://tinylittlequeue.app/
68
+ licenses:
69
+ - MIT
70
+ metadata:
71
+ homepage_uri: https://tinylittlequeue.app/
72
+ source_code_uri: https://github.com/skyaktech/tlq-client-ruby
73
+ changelog_uri: https://github.com/skyaktech/tlq-client-ruby/blob/main/CHANGELOG.md
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 2.6.0
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubygems_version: 3.0.3.1
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: Ruby client for TLQ (Tiny Little Queue)
93
+ test_files: []