
Security News
Rspack Introduces Rslint, a TypeScript-First Linter Written in Go
Rspack launches Rslint, a fast TypeScript-first linter built on typescript-go, joining in on the trend of toolchains creating their own linters.
EventBus provides additional messaging patterns for EmpregoLigado applications. It exposes some methods for messaging-related features:
Let's look at a diagram for EventBus:
Add this line to your application's Gemfile:
gem 'event_bus_rb'
And then execute:
$ bundle
Or install it yourself as:
$ gem install event_bus_rb
And set env vars:
ENV['RABBIT_URL'] = 'amqp://guest:guest@localhost:5672'
ENV['RABBIT_EVENT_BUS_APP_NAME'] = 'EventBusExampleApp'
ENV['RABBIT_EVENT_BUS_VHOST'] = 'event_bus'
ENV['RABBIT_EVENT_BUS_TOPIC_NAME'] = 'event_bus'
A application can trigger events based passing an EventBus::Event instance, so others systems that listens to these events based matching the routing key (used as event_name below) will receive the event payload content.
require 'event_bus_rb'
event_name = 'resource.origin.action'
body = { resource: 'full' }
event = EventBus::Event.new(event_name, body)
EventBus::Emitter.trigger(event)
EventBus::Config.broker.close_connection
An application that uses EventBus
to handle events should be treated as a
daemon like any other. The Listener
api handles the blocking looping system,
so the client doesn`t need to think about those implementation details.
require 'event_bus_rb'
event_name = 'resource.origin.action'
puts 'Start receiving messages'
EventBus::Listener.on(event_name) do |event, _delivery_info|
puts ""
puts " - Received a message from #{event.name}:"
puts " Message: #{event.body}"
puts ""
end
puts 'Stop receiving messages'
EventBus::Config.broker.close_connection
If your application needs to handle with loads of events you can extends EventBus::Listeners::Base
and bind events to methods.
A simplistic example can be written like so:
require 'event_bus_rb'
class CustomEventListener < EventBus::Listeners::Base
bind :pay, 'resource.custom.pay'
bind :receive, 'resource.custom.receive'
def pay(event, delivery_info)
puts "Paid #{event.body['amount']} for #{event.body['name']} ~> #{event.name}"
channel.ack(delivery_info.delivery_tag, false)
end
def receive(event, delivery_info)
puts "Received #{event.body['amount']} from #{event.body['name']} ~> #{event.name}"
channel.ack(delivery_info.delivery_tag, false)
end
end
You can also bind more than one routing keys to methods using *
or #
.
Using resource.*.pay
, for example, you can bind routing keys prefixed by resource. and suffixed by .pay to a method:
# bind resource.everything.pay to pay method
bind :pay, 'resource.*.pay'
Using #
, you can bind all routing keys to a method:
# bind everything to receive method
bind :receive, '#'
After checking out the repo, run bin/setup
to install dependencies. Then, run bundle exec rspec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
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.
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)The gem is available as open source under the terms of the MIT License.
FAQs
Unknown package
We found that event_bus_rb demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Rspack launches Rslint, a fast TypeScript-first linter built on typescript-go, joining in on the trend of toolchains creating their own linters.
Security News
Hacker Demonstrates How Easy It Is To Steal Data From Popular Password Managers
Security News
Oxlint’s new preview brings type-aware linting powered by typescript-go, combining advanced TypeScript rules with native-speed performance.