kafka_event_hub 1.0.0 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8e482b41980cd0dfe27e3a501fab289ee5ebd7d81e58aa9d1d88c9fe485d95c9
4
- data.tar.gz: 1e3f4ae0f1c8442684365277b2d94ad1ec33812a6111af891ee6af1c3be6c31e
3
+ metadata.gz: 376525f485f73ea729e460154f69178ed5c62eab2255dd746386e5bff0e4e7f6
4
+ data.tar.gz: bcc93865915d1ec526cbf70032030e0a7ceca7a5aa163ba86942e42348ae3ca6
5
5
  SHA512:
6
- metadata.gz: 22f2611efe7633c8c17b07c49deaec98e55361b6ee3c77739fdb584b05b8ec3b5f38e834e675cbd65ae89e565582a21fe87a3f41e857a3aafc0cec15a3ecc98d
7
- data.tar.gz: dba58745fe1c8d7bcda9cddd50943d5ab67d4f48c5b71f67e21a0ec8e290d3a456b65c2ff798509e3a5d978b2bb13a2d383e7f2bcefec1d9069edc9e09ff3cc8
6
+ metadata.gz: 2013e2c844dd9346c1e076470967aad13621db009679c77e0873ce317c91355bcd66fe68ee887272f6b1a3d4a2c800373dc6048e26beace2e8355c0e5d600f2b
7
+ data.tar.gz: d0d77508e2e0c7fdbf4418e7ce4e71c0e2d00e562c04fa3e89e4e693eafe8de46e92a1abe7918fc374d20755aabc848c7849ffcb1cec40a76286d67b7beb7941
data/README.md CHANGED
@@ -1,43 +1,158 @@
1
1
  # KafkaEventHub
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/kafka_event_hub`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ [![Build Status](https://github.com/marryam-shahzad/kafka_event_hub/actions/workflows/ci.yml/badge.svg)](https://github.com/marryam-shahzad/kafka_event_hub/actions)
4
+ [![Gem Version](https://badge.fury.io/rb/kafka_event_hub.svg)](https://badge.fury.io/rb/kafka_event_hub)
4
5
 
5
- TODO: Delete this and the text above, and describe your gem
6
+ KafkaEventHub is a Ruby gem providing a clean, generic, and configurable interface for producing and consuming Kafka messages in Ruby and Rails applications. It abstracts Kafka connection management and offers flexible producer and consumer classes for easy event streaming integration.
7
+
8
+ ---
9
+
10
+ ## Features
11
+
12
+ - Generic Kafka Producer with topic, key, payload, and partition support.
13
+ - Generic Kafka Consumer supporting message polling and subscription.
14
+ - Easily configurable via environment variables or programmatically.
15
+ - Lightweight and reusable across multiple Ruby or Rails projects.
16
+ - Handles message serialization/deserialization seamlessly.
17
+ - Retry mechanisms can be implemented externally in jobs or services.
18
+
19
+ ---
6
20
 
7
21
  ## Installation
8
22
 
9
23
  Add this line to your application's Gemfile:
10
24
 
11
- ```ruby
12
- gem 'kafka_event_hub'
13
- ```
25
+ gem 'kafka_event_hub'
14
26
 
15
- And then execute:
27
+ Then execute:
16
28
 
17
- $ bundle
29
+ bundle install
18
30
 
19
31
  Or install it yourself as:
20
32
 
21
- $ gem install kafka_event_hub
33
+ gem install kafka_event_hub
34
+
35
+ ---
36
+
37
+ ## Configuration
38
+
39
+ Before using the gem, set the following environment variables (adjust as per your Kafka setup):
40
+
41
+ ```bash
42
+ DEFAULT_TOPIC=default # Default Kafka topic
43
+ EVENT_HUB_NAMESPACE=your-namespace.servicebus.windows.net:9093
44
+ EVENT_HUB_URL="Endpoint=sb://your-namespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=your-access-key"
45
+ EVENT_HUB_CONSUMER_GROUP=Default
46
+ APP_NAME=your-app-name
47
+ KAFKA_POLL_TIMEOUT=120000 # in milliseconds
48
+ ```
49
+ ---
22
50
 
23
51
  ## Usage
24
52
 
25
- TODO: Write usage instructions here
53
+ ### Producer
54
+
55
+ Create a producer instance and send messages to Kafka topics easily:
56
+
57
+ producer = KafkaEventHub::Producer.new('your-topic')
58
+
59
+ producer.produce(
60
+ key: 'Entity#123',
61
+ payload: { event: 'event_name', data: 'your data here', timestamp: Time.now }
62
+ )
63
+
64
+ ### Consumer
65
+
66
+ Create a consumer instance and process incoming messages with a block:
67
+
68
+ consumer = KafkaEventHub::Consumer.new('your-topic')
69
+
70
+ consumer.each_message do |message|
71
+ puts "Received message: #{message.payload}"
72
+ # Your message processing logic here
73
+ end
74
+
75
+ Alternatively, use `poll_messages` with a timeout (in milliseconds):
76
+
77
+ consumer.poll_messages(1000) do |message|
78
+ # Process each message here
79
+ end
80
+
81
+ ---
82
+
83
+ ## Integration with Rails Jobs
84
+
85
+ You can wrap your Kafka producer and consumer in Rails ActiveJobs for background processing and retries.
86
+
87
+ ### Example Producer Job
88
+
89
+ class GenericKafkaProducerJob < ActiveJob::Base
90
+ queue_as :kafka_stream
91
+
92
+ def perform(key, payload, topic = 'default-topic', partition = 0)
93
+ KafkaEventHub::Producer.new(topic).produce(
94
+ key: key,
95
+ payload: payload,
96
+ partition: partition
97
+ )
98
+ end
99
+ end
100
+
101
+ Customize the job code to suit your app’s background job system or retry logic.
102
+
103
+ ### Example Consumer Job
104
+
105
+ class GenericKafkaConsumerJob < ActiveJob::Base
106
+ queue_as :kafka_consumer
107
+
108
+ def perform(topic = 'default-topic')
109
+ consumer = KafkaEventHub::Consumer.new(topic)
110
+
111
+ consumer.each_message do |message|
112
+ payload = JSON.parse(message.payload)
113
+ # Process your payload here
114
+ end
115
+ end
116
+ end
117
+
118
+ ---
26
119
 
27
120
  ## Development
28
121
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
122
+ To set up the development environment:
123
+
124
+ bundle install
125
+ rake spec
126
+
127
+ To build and install the gem locally:
128
+
129
+ gem build kafka_event_hub.gemspec
130
+ gem install ./kafka_event_hub-0.1.0.gem
131
+
132
+ To release a new version:
30
133
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
134
+ 1. Update the version in `lib/kafka_event_hub/version.rb`.
135
+ 2. Run:
136
+
137
+ bundle exec rake release
138
+
139
+ This will create a git tag, push commits and tags, and push the gem to [RubyGems.org](https://rubygems.org).
140
+
141
+ ---
32
142
 
33
143
  ## Contributing
34
144
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/kafka_event_hub. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
145
+ Bug reports and pull requests are welcome on [GitHub](https://github.com/marryam-shahzad/kafka_event_hub).
146
+ Please follow the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
147
+
148
+ ---
36
149
 
37
150
  ## License
38
151
 
39
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
152
+ This gem is licensed under the [MIT License](https://opensource.org/licenses/MIT).
153
+
154
+ ---
40
155
 
41
156
  ## Code of Conduct
42
157
 
43
- Everyone interacting in the KafkaEventHub project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/kafka_event_hub/blob/master/CODE_OF_CONDUCT.md).
158
+ Everyone participating in this project is expected to follow the [code of conduct](https://github.com/marryam-shahzad/kafka_event_hub/blob/master/CODE_OF_CONDUCT.md).
@@ -15,14 +15,16 @@ Gem::Specification.new do |spec|
15
15
  Centralizes ENV-based Rd-kafka setup into a single gem.
16
16
  DESC
17
17
 
18
- # Once this gem is published, its RubyGems page will be:
19
- spec.homepage = "https://rubygems.org/gems/kafka_event_hub"
18
+ # Homepage and source links
19
+ spec.homepage = "https://github.com/marryam-shahzad/kafka_event_hub"
20
20
  spec.license = "MIT"
21
21
 
22
- # Only allow pushing to RubyGems.org
22
+ # Only allow pushing to RubyGems.org and link to GitHub
23
23
  if spec.respond_to?(:metadata)
24
24
  spec.metadata["allowed_push_host"] = "https://rubygems.org"
25
25
  spec.metadata["homepage_uri"] = spec.homepage
26
+ spec.metadata["source_code_uri"] = "https://github.com/marryam-shahzad/kafka_event_hub"
27
+ spec.metadata["documentation_uri"] = "https://github.com/marryam-shahzad/kafka_event_hub/blob/master/README.md"
26
28
  end
27
29
 
28
30
  # Files to include in the gem
@@ -36,5 +38,5 @@ Gem::Specification.new do |spec|
36
38
  spec.add_development_dependency "bundler", "~> 1.17"
37
39
  spec.add_development_dependency "rake", "~> 10.0"
38
40
  spec.add_development_dependency "rspec", "~> 3.0"
39
- spec.add_dependency 'uri', '~> 1.0.3'
41
+ spec.add_dependency "uri", "~> 1.0.3"
40
42
  end
@@ -1,3 +1,3 @@
1
1
  module KafkaEventHub
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kafka_event_hub
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marryam Shahzad
@@ -109,12 +109,14 @@ files:
109
109
  - lib/kafka_event_hub/consumer.rb
110
110
  - lib/kafka_event_hub/producer.rb
111
111
  - lib/kafka_event_hub/version.rb
112
- homepage: https://rubygems.org/gems/kafka_event_hub
112
+ homepage: https://github.com/marryam-shahzad/kafka_event_hub
113
113
  licenses:
114
114
  - MIT
115
115
  metadata:
116
116
  allowed_push_host: https://rubygems.org
117
- homepage_uri: https://rubygems.org/gems/kafka_event_hub
117
+ homepage_uri: https://github.com/marryam-shahzad/kafka_event_hub
118
+ source_code_uri: https://github.com/marryam-shahzad/kafka_event_hub
119
+ documentation_uri: https://github.com/marryam-shahzad/kafka_event_hub/blob/master/README.md
118
120
  post_install_message:
119
121
  rdoc_options: []
120
122
  require_paths: