{"id":27934824,"url":"https://github.com/uri/tin-can","last_synced_at":"2025-05-07T06:08:32.695Z","repository":{"id":142775935,"uuid":"106956155","full_name":"uri/tin-can","owner":"uri","description":"Easy pubsub between applications using the same redis host.","archived":false,"fork":false,"pushed_at":"2015-08-25T21:13:35.000Z","size":368,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-07T06:08:29.325Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/uri.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-14T19:21:57.000Z","updated_at":"2021-12-01T20:27:17.000Z","dependencies_parsed_at":"2023-03-15T01:18:33.098Z","dependency_job_id":null,"html_url":"https://github.com/uri/tin-can","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uri%2Ftin-can","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uri%2Ftin-can/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uri%2Ftin-can/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uri%2Ftin-can/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uri","download_url":"https://codeload.github.com/uri/tin-can/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252823918,"owners_count":21809713,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-05-07T06:08:32.208Z","updated_at":"2025-05-07T06:08:32.683Z","avatar_url":"https://github.com/uri.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tin-can\n[![Circle CI](https://circleci.com/gh/HealthWave/tin-can.svg?style=svg)](https://circleci.com/gh/HealthWave/tin-can)\n[![Code Climate](https://codeclimate.com/github/HealthWave/tin-can/badges/gpa.svg)](https://codeclimate.com/github/HealthWave/tin-can)\n[![Test Coverage](https://codeclimate.com/github/HealthWave/tin-can/badges/coverage.svg)](https://codeclimate.com/github/HealthWave/tin-can/coverage)\n\ntin-can is a Rails gem that allows you to do pub/sub between apps using redis.\n\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'tin-can'\n```\n\nAnd then execute:\n\n    $ bundle install\n\n\n## Listening to events\nThe steps below should be applied on all apps that are receiving messages.\n\nFirst create a initializer on config/tin_can_routes.rb\n\n```ruby\nTinCan.routes do\n  route 'event_name', to: MyEventController, action: :my_action\nend\n```\n\nThen create an EventController: app/event_controllers/my_event_controller.rb\n```ruby\nclass MyEventController \u003c TinCan::EventController\n  def my_action\n    # awesome stuff here!\n  end\nend\n```\n\nNow create a rake task to start the TinCan Handler. Here is an example:\n```ruby\nnamespace 'tin-can' do\n  require 'tin_can'\n\n\n  desc 'Start the tin-can handler'\n  task start: :environment do\n    TinCan.start\n  end\n  desc 'Stop the tin-can handler'\n  task stop: :environment do\n    TinCan.stop\n  end\n  desc 'Check if the handler is running'\n  task status: :environment do\n    TinCan.status\n  end\n  desc 'Restart the tin-can handler'\n  task restart: :environment do\n    puts \"Restarting TinCan\"\n    TinCan.stop\n    system \"rake tin-can:start\"\n  end\n\nend\n```\nAnd start by doing:\n```\nrake tin-can:start\n```\nTo stop:\n```ruby\nrake tin-can:stop\n```\nRestart:\n```ruby\nrake tin-can:restart\n```\nTo run TinCan on foreground, do:\n```ruby\nFOREGROUND=true rake tin-can:start\n```\nEvery time the TinCan receives an event, the TinCan::EventHandler will match and route to the desired event controller and action.\n\n## Sending events\nSending an event is as easy as\n```ruby\n# payload must be an object that responds to to_json\npayload = {message: 'This is a message', wharever: true}\nevent = TinCan::Event.new('event_name', payload)\nevent.broadcast!\n```\nIf you broadcast an event when nobody is listening, the event will be lost. You can handle this case by bassing a block to the broadcast! method:\n```ruby\nTinCan::Event.new(channel_name, payload).broadcast! do |event|\n  # Saves the event to resque\n  Resque.enqueue( EventRetry, event.channel, event.payload )\nend\n```\n\n## TODO\n- Add option to use RPUSH and BLPOP instead of pub/sub.\n- Add option to run as a separate thread inside Rails.\n- Add start/stop/status rake task to gem\n- Test usage outside Rails\n- Refactor a bit\n\n\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/tin-can. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.\n\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Furi%2Ftin-can","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Furi%2Ftin-can","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Furi%2Ftin-can/lists"}