amqp-client 1.2.1 → 2.0.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.
data/README.md DELETED
@@ -1,193 +0,0 @@
1
- # AMQP::Client
2
-
3
- A modern AMQP 0-9-1 Ruby client. Very fast (just as fast as the Java client, and >4x than other Ruby clients), fully thread-safe, blocking operations and straight-forward error handling.
4
-
5
- It's small, only ~1800 lines of code, and without any dependencies. Other Ruby clients are about 4 times bigger. But without trading functionallity.
6
-
7
- It's safe by default, messages are published as persistent, and is waiting for confirmation from the broker. That can of course be disabled if performance is a priority.
8
-
9
- ## Support
10
-
11
- The library is fully supported by [CloudAMQP](https://www.cloudamqp.com), the largest LavinMQ and RabbitMQ hosting provider in the world. Open [an issue](https://github.com/cloudamqp/amqp-client.rb/issues) or [email our support](mailto:support@cloudamqp.com) if you have problems or questions.
12
-
13
- ## Documentation
14
-
15
- [API reference](https://cloudamqp.github.io/amqp-client.rb/)
16
-
17
- ## Usage
18
-
19
- The client has two APIs.
20
-
21
- ### Low level API
22
-
23
- This API matches the AMQP protocol very well, it can do everything the protocol allows, but requires some knowledge about the protocol, and doesn't handle reconnects.
24
-
25
- ```ruby
26
- require "amqp-client"
27
-
28
- # Opens and establishes a connection
29
- conn = AMQP::Client.new("amqp://guest:guest@localhost").connect
30
-
31
- # Open a channel
32
- ch = conn.channel
33
-
34
- # Create a temporary queue
35
- q = ch.queue_declare
36
-
37
- # Publish a message to said queue
38
- ch.basic_publish_confirm "Hello World!", "", q.queue_name, persistent: true
39
-
40
- # Poll the queue for a message
41
- msg = ch.basic_get(q.queue_name)
42
-
43
- # Print the message's body to STDOUT
44
- puts msg.body
45
- ```
46
-
47
- ### High level API
48
-
49
- The library provides a high-level API that is a bit easier to get started with, and also handles reconnection automatically.
50
-
51
- ```ruby
52
- require "amqp-client"
53
- require "json"
54
- require "zlib"
55
-
56
- # Start the client, it will connect and once connected it will reconnect if that connection is lost
57
- # Operation pending when the connection is lost will raise an exception (not timeout)
58
- amqp = AMQP::Client.new("amqp://localhost").start
59
-
60
- # Declares a durable queue
61
- myqueue = amqp.queue("myqueue")
62
-
63
- # Bind the queue to any exchange, with any binding key
64
- myqueue.bind("amq.topic", "my.events.*")
65
-
66
- # The message will be reprocessed if the client loses connection to the broker
67
- # between message arrival and when the message was supposed to be ack'ed.
68
- myqueue.subscribe(prefetch: 20) do |msg|
69
- puts JSON.parse(msg.body)
70
- msg.ack
71
- rescue => e
72
- puts e.full_message
73
- msg.reject(requeue: false)
74
- end
75
-
76
- # Publish directly to the queue
77
- myqueue.publish({ foo: "bar" }.to_json, content_type: "application/json")
78
-
79
- # Publish to any exchange
80
- amqp.publish("my message", "amq.topic", "topic.foo", headers: { foo: 'bar' })
81
- amqp.publish(Zlib.gzip("an event"), "amq.topic", "my.event", content_encoding: 'gzip')
82
- ```
83
-
84
- ## Benchmark
85
-
86
- 1 byte messages:
87
-
88
- | Client | Publish rate | Consume rate | Memory usage |
89
- | ------ | ------------ | ------------ | ------------ |
90
- | amqp-client.rb | 237.000 msgs/s | 154.000 msgs/s | 23 MB |
91
- | bunny | 39.000 msgs/s | 44.000 msgs/s | 31 MB |
92
-
93
- Gem comparison:
94
-
95
- | Client | Runtime dependencies | [Lines of code](https://github.com/AlDanial/cloc) |
96
- | --- | --- | --- |
97
- | amqp-client.rb | 0 | 1876 |
98
- | bunny | 2 | 4003 |
99
-
100
- ## Supported Ruby versions
101
-
102
- All maintained Ruby versions are supported.
103
-
104
- See the [CI workflow](https://github.com/cloudamqp/amqp-client.rb/blob/main/.github/workflows/main.yml) for the exact versions.
105
-
106
- ## Installation
107
-
108
- Add this line to your application's Gemfile:
109
-
110
- ```ruby
111
- gem 'amqp-client'
112
- ```
113
-
114
- And then execute:
115
-
116
- bundle install
117
-
118
- Or install it yourself as:
119
-
120
- gem install amqp-client
121
-
122
- ## Development
123
-
124
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
125
-
126
- To install this gem onto your local machine, run `bundle exec rake install`.
127
-
128
- ### Release Process
129
-
130
- The gem uses rake tasks to automate the release preparation process. The actual gem building and publishing is handled automatically by GitHub Actions when a tag is pushed.
131
-
132
- #### Quick Release (Patch Version)
133
-
134
- ```bash
135
- rake release:prepare
136
- ```
137
-
138
- This will:
139
-
140
- 1. Run tests and RuboCop to ensure code quality
141
- 2. Bump the patch version (e.g., 1.2.0 → 1.2.1)
142
- 3. Update the CHANGELOG.md with the new version and current date
143
- 4. Create a git commit and tag for the release
144
- 5. Push commits and tags to the remote repository
145
- 6. GitHub Actions will automatically build and publish the gem to RubyGems
146
-
147
- #### Custom Version Bump
148
-
149
- For minor or major version bumps:
150
-
151
- ```bash
152
- # Minor version bump (e.g., 1.2.0 → 1.3.0)
153
- rake release:prepare[minor]
154
-
155
- # Major version bump (e.g., 1.2.0 → 2.0.0)
156
- rake release:prepare[major]
157
- ```
158
-
159
- #### Individual Release Steps
160
-
161
- You can also run individual steps if needed:
162
-
163
- ```bash
164
- # Bump version only
165
- rake release:bump[patch] # or [minor] or [major]
166
-
167
- # Update changelog with current version
168
- rake release:changelog
169
-
170
- # Create git tag with changelog entries
171
- rake release:tag
172
-
173
- # Push tag to remote (handles conflicts)
174
- rake release:push_tag
175
- ```
176
-
177
- #### Manual Release Steps
178
-
179
- If you prefer manual control:
180
-
181
- 1. Update the version number in `lib/amqp/client/version.rb`
182
- 2. Update the CHANGELOG.md with the new version and release notes
183
- 3. Commit your changes: `git add . && git commit -m "Release X.Y.Z"`
184
- 4. Create and push a tag: `git tag vX.Y.Z && git push origin vX.Y.Z`
185
- 5. GitHub Actions will automatically build and publish the gem when the tag is pushed
186
-
187
- ## Contributing
188
-
189
- Bug reports and pull requests are welcome on GitHub at [https://github.com/cloudamqp/amqp-client.rb](https://github.com/cloudamqp/amqp-client.rb/)
190
-
191
- ## License
192
-
193
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile DELETED
@@ -1,197 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "rake/testtask"
4
-
5
- Rake::TestTask.new(:test) do |t|
6
- t.description = "Run all but TLS tests"
7
- t.options = "--exclude=/_tls$/"
8
- t.pattern = "test/**/*_test.rb"
9
- end
10
-
11
- namespace :test do
12
- Rake::TestTask.new(:all) do |t|
13
- t.description = "Run all tests"
14
- t.pattern = "test/**/*_test.rb"
15
- end
16
- end
17
-
18
- require "rubocop/rake_task"
19
-
20
- RuboCop::RakeTask.new
21
-
22
- require "yard"
23
-
24
- YARD::Rake::YardocTask.new
25
-
26
- # Release helper methods
27
- def current_version
28
- version_file = "lib/amqp/client/version.rb"
29
- content = File.read(version_file)
30
- content.match(/VERSION = "(.+)"/)[1]
31
- end
32
-
33
- def extract_changelog_for_version(version)
34
- changelog = File.read("CHANGELOG.md")
35
-
36
- # Find the section for this version
37
- version_pattern = /^## \[#{Regexp.escape(version)}\][^\n]*\n(.*?)(?=^## \[|\z)/m
38
- match = changelog.match(version_pattern)
39
-
40
- if match
41
- # Clean up the changelog entries
42
- entries = match[1].strip
43
- # Remove empty lines at the start and end
44
- entries.gsub(/\A\s*\n+/, "").gsub(/\n+\s*\z/, "")
45
- else
46
- "No changelog entries found for version #{version}"
47
- end
48
- end
49
-
50
- def push_tag_to_remote(version)
51
- # Check if tag exists on remote
52
- remote_tag_exists = system("git ls-remote --tags origin | grep -q refs/tags/v#{version}")
53
-
54
- if remote_tag_exists
55
- puts "Tag v#{version} already exists on remote. Force pushing updated tag..."
56
- system("git push origin v#{version} --force")
57
- else
58
- puts "Pushing new tag v#{version} to remote..."
59
- system("git push origin v#{version}")
60
- end
61
- end
62
-
63
- def bump_version(version_type)
64
- unless %w[major minor patch].include?(version_type)
65
- puts "Invalid version type. Use: major, minor, or patch"
66
- exit 1
67
- end
68
-
69
- version_file = "lib/amqp/client/version.rb"
70
- content = File.read(version_file)
71
-
72
- current_version = content.match(/VERSION = "(.+)"/)[1]
73
- major, minor, patch = current_version.split(".").map(&:to_i)
74
-
75
- case version_type
76
- when "major"
77
- major += 1
78
- minor = 0
79
- patch = 0
80
- when "minor"
81
- minor += 1
82
- patch = 0
83
- when "patch"
84
- patch += 1
85
- end
86
-
87
- new_version = "#{major}.#{minor}.#{patch}"
88
- new_content = content.gsub(/VERSION = ".+"/, %(VERSION = "#{new_version}"))
89
-
90
- File.write(version_file, new_content)
91
- puts "Bumped version from #{current_version} to #{new_version}"
92
- end
93
-
94
- def update_changelog
95
- version = current_version
96
- date = Time.now.strftime("%Y-%m-%d")
97
-
98
- changelog = File.read("CHANGELOG.md")
99
-
100
- if changelog.include?("## [#{version}]")
101
- puts "Version #{version} already exists in CHANGELOG.md"
102
- else
103
- updated_changelog = changelog.sub(
104
- "## [Unreleased]",
105
- "## [Unreleased]\n\n## [#{version}] - #{date}"
106
- )
107
-
108
- File.write("CHANGELOG.md", updated_changelog)
109
- puts "Updated CHANGELOG.md with version #{version}"
110
- end
111
- end
112
-
113
- def create_git_tag
114
- version = current_version
115
-
116
- system("git add .")
117
- system("git commit -m 'Release #{version}'")
118
-
119
- # Check if tag already exists locally and remove it if it does
120
- if system("git tag -l v#{version} | grep -q v#{version}")
121
- puts "Tag v#{version} already exists locally, removing it..."
122
- system("git tag -d v#{version}")
123
- end
124
-
125
- # Extract changelog entries for this version
126
- changelog_entries = extract_changelog_for_version(version)
127
-
128
- # Create tag message with version and changelog
129
- tag_message = "Release #{version}\n\n#{changelog_entries}"
130
-
131
- # Create annotated tag with the changelog
132
- system("git", "tag", "-a", "v#{version}", "-m", tag_message)
133
-
134
- puts "Created git tag v#{version} with changelog entries"
135
- end
136
-
137
- def prepare_release_process(version_type)
138
- puts "Preparing release process..."
139
-
140
- # Ensure working directory is clean
141
- unless system("git diff --quiet && git diff --cached --quiet")
142
- puts "Working directory is not clean. Please commit or stash changes first."
143
- exit 1
144
- end
145
-
146
- # Bump version
147
- Rake::Task["release:bump"].invoke(version_type)
148
- Rake::Task["release:bump"].reenable
149
-
150
- # Update changelog
151
- Rake::Task["release:changelog"].invoke
152
- Rake::Task["release:changelog"].reenable
153
-
154
- # Create tag and push
155
- Rake::Task["release:tag"].invoke
156
- Rake::Task["release:tag"].reenable
157
-
158
- # Push to git
159
- system("git push origin")
160
-
161
- # Handle tag push with potential conflicts
162
- version = current_version
163
- push_tag_to_remote(version)
164
-
165
- puts "Successfully prepared release #{version}!"
166
- puts "The CI will automatically build and publish the gem when the tag is pushed."
167
- end
168
-
169
- namespace :release do
170
- desc "Bump version (usage: rake release:bump[major|minor|patch])"
171
- task :bump, [:type] do |_t, args|
172
- bump_version(args[:type] || "patch")
173
- end
174
-
175
- desc "Update changelog with current version"
176
- task :changelog do
177
- update_changelog
178
- end
179
-
180
- desc "Create git tag for current version"
181
- task :tag do
182
- create_git_tag
183
- end
184
-
185
- desc "Push tag to remote (handles conflicts)"
186
- task :push_tag do
187
- version = current_version
188
- push_tag_to_remote(version)
189
- end
190
-
191
- desc "Prepare release (bump version, update changelog, create tag, push to git)"
192
- task :prepare, [:type] => %i[test rubocop] do |_t, args|
193
- prepare_release_process(args[:type] || "patch")
194
- end
195
- end
196
-
197
- task default: [:test, *(:rubocop if ENV["CI"] != "true")]
data/amqp-client.gemspec DELETED
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "lib/amqp/client/version"
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = "amqp-client"
7
- spec.version = AMQP::Client::VERSION
8
- spec.authors = ["CloudAMQP"]
9
- spec.email = ["team@cloudamqp.com"]
10
-
11
- spec.summary = "AMQP 0-9-1 client"
12
- spec.description = "Modern AMQP 0-9-1 Ruby client"
13
- spec.homepage = "https://github.com/cloudamqp/amqp-client.rb"
14
- spec.license = "MIT"
15
- spec.required_ruby_version = Gem::Requirement.new(">= 3.2.0")
16
-
17
- spec.metadata["homepage_uri"] = spec.homepage
18
- spec.metadata["source_code_uri"] = "#{spec.homepage}.git"
19
- spec.metadata["changelog_uri"] = "https://github.com/cloudamqp/amqp-client.rb/blob/main/CHANGELOG.md"
20
-
21
- # Specify which files should be added to the gem when it is released.
22
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
- spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
25
- end
26
- spec.bindir = "exe"
27
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
28
- spec.require_paths = ["lib"]
29
- end
data/bin/console DELETED
@@ -1,15 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require "bundler/setup"
5
- require "amqp/client"
6
-
7
- # You can add fixtures and/or initialization code here to make experimenting
8
- # with your gem easier. You can also use a different console, if you like.
9
-
10
- # (If you use this, don't forget to add pry to your Gemfile!)
11
- # require "pry"
12
- # Pry.start
13
-
14
- require "irb"
15
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here