No commit activity in last 3 years
No release in over 3 years
A simple RabbitMQ message producer using Gadz.org JSON Schema policy
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 0.1.6
~> 1.11
~> 10.0
~> 3.0

Runtime

>= 2.2.2, ~> 2.2
 Project Readme

GorgMessageSender

Code Climate Test Coverage Build Status Gem Version Dependency Status

GorgMessageSender is a very simple RabbitMQ message sender using Gadz.org SOA JSON Schema

Installation

Add this line to your application's Gemfile:

gem 'gorg_message_sender'

And then execute:

$ bundle

Or install it yourself as:

$ gem install gorg_message_sender

Usage

###Configuration GorgMessageSender can be configure to change its default values :

GorgMessageSender.configure do |c|
  
  # Id used to set the event_sender_id
  #c.application_id = "gms"
  
  # RabbitMQ network and authentification
  #c.host = "localhost" 
  #c.port = 5672 
  #c.vhost = "/"
  #c.user = nil
  #c.password = nil
  
  # Exchange configuration
  #c.exchange_name ="exchange"        
  #c.durable_exchange= true
end

This based configuration can be overridden when needed :

sender=GorgMessageSender.new(host: "my_host",
                             port: 1234,
                             user: "My_user",
                             pass: "1zae125a",
                             exchange_name: "some_exchange",
                             vhost: "/foo",
                             app_id: "bar",
                             durable_exchange: false)

###Generating a message

sender=GorgMessageSender.new()
sender.message({this_is: "my data hash"},"some.routing.key")

# With default configuration
# => "{\"event_uuid\":\"095dcff6-665d-4194-bdfe-f889f8cedb09\",\"event_name\":\"some.routing.key\",\"event_creation_time\":\"2016-05-31T08:53:32+02:00\",\"event_sender_id\":\"gms\",\"data\":{\"this_is\":\"my data hash\"}}"

event_uuid, event_creation_time and event_sender_id can be overridden :

sender=GorgMessageSender.new()

sender.message({this_is: "my data hash"},
               "some.routing.key",
               event_uuid: "8c4abe62-26fe-11e6-b67b-9e71128cae77",
               event_creation_time: DateTime.new(2084,05,10,01,57,00),
               event_sender_id: "some_app_id"
               )
# => "{\"event_uuid\":\"8c4abe62-26fe-11e6-b67b-9e71128cae77\",\"event_name\":\"some.routing.key\",\"event_creation_time\":\"2084-05-10T01:57:00+00:00\",\"event_sender_id\":\"some_app_id\",\"data\":{\"this_is\":\"my data hash\"}}"

###Message validation By default, GorgMessageSender validate message against the Gadz.org SOA JSON Schema. You can force message generation for testing purpose with the option skip_validation

sender.message({this_is: "my data hash"},
               "some.routing.key",
               event_uuid: "this is not a valid uuid"
               )

# With default configuration
# => RAISE JSON::Schema::ValidationError

sender.message({this_is: "my data hash"},
               "some.routing.key",
               event_uuid: "this is not a valid uuid",
               skip_validation: true
               )

# With default configuration
# => "{\"event_uuid\":\"this is not a valid uuid\",\"event_name\":\"some.routing.key\",\"event_creation_time\":\"2016-05-31T09:15:21+02:00\",\"event_sender_id\":\"gms\",\"data\":{\"this_is\":\"my data hash\"}}"

###Sending a message To send a message, use the send command. It expects the same params than message :

sender=GorgMessageSender.new(exchange_name: "my_exchange")
sender.send_message({this_is: "my data hash"},"some.routing.key")

# Message is sent to the exchange "my_exchange" with routing key "some.routing.key"
# => "{\"event_uuid\":\"095dcff6-665d-4194-bdfe-f889f8cedb09\",\"event_name\":\"some.routing.key\",\"event_creation_time\":\"2016-05-31T08:53:32+02:00\",\"event_sender_id\":\"gms\",\"data\":{\"this_is\":\"my data hash\"}}"

sender.send_message({this_is: "my data hash"},
               "some.routing.key",
               event_uuid: "8c4abe62-26fe-11e6-b67b-9e71128cae77",
               event_creation_time: DateTime.new(2084,05,10,01,57,00),
               event_sender_id: "some_app_id"
               )
           
# Message is sent to the exchange "my_exchange" with routing key "some.routing.key"
# => "{\"event_uuid\":\"8c4abe62-26fe-11e6-b67b-9e71128cae77\",\"event_name\":\"some.routing.key\",\"event_creation_time\":\"2084-05-10T01:57:00+00:00\",\"event_sender_id\":\"some_app_id\",\"data\":{\"this_is\":\"my data hash\"}}"


sender.send_message({this_is: "my data hash"},
               "some.routing.key",
               event_uuid: "this is not a valid uuid"
               )

# => RAISE JSON::Schema::ValidationError


sender.message_message({this_is: "my data hash"},
               "some.routing.key",
               event_uuid: "this is not a valid uuid",
               skip_validation: true
               )

# Message is sent to the exchange "my_exchange" with routing key "some.routing.key"
# => "{\"event_uuid\":\"this is not a valid uuid\",\"event_name\":\"some.routing.key\",\"event_creation_time\":\"2016-05-31T09:15:21+02:00\",\"event_sender_id\":\"gms\",\"data\":{\"this_is\":\"my data hash\"}}"

send_messagealso accepts the verbose params to print sending informations in SDOUT

sender.send_message({this_is: "my data hash"},
               "some.routing.key",
               verbose: true
               )

###Sending a raw message You can also send any raw string with send_raw

sender.send_raw("my message content",
               "some.routing.key",
               verbose: true
               )

##To Do

  • Bunny error handling
  • Allow sending messages in queues

Development

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.

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.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/Zooip/gorg_message_sender.

License

The gem is available as open source under the terms of the MIT License.