In this project, I want to demonstrate how to use Sidekiq as message queue system between two different application.
The producer application "ruby-app" is written in Ruby. Once it starts, it will create a job to be processed by the receiver application "crystal-app", which is written in Crystal.
The communication between both apps is handled by Redis and Sidekiq, via queues. The ruby-app listens to jobs in "ruby" queue. The crystal-app listens to jobs in "crystal" queue.
Both applications use Sidekiqs API to write the jobs into the other application queue.
The receiver worker will then take a random integer number (N) generated by the producer, and sleep for N seconds, then it will generate a new job into producer queue.
Also, it writes some output into tmp/output.txt file:
3 seconds sleep received 9 seconds sleep received
I provide a way to set up the application via the setup.sh script. It installs brew, bundler, foreman, Redis, and crystal language.
In order to get the application running, execute in the terminal:
Once executed, it will install all dependencies, compile crystal-app, and start both applications via foreman.
When fired up, foreman output should look like this:
12:19:09 ruby.1 | 2017-10-09T15:19:09.599Z 32609 TID-ox626dzv0 RubyApp::Workers::ProducerWorker JID-2bef1352ac43b2197e2d9d9f INFO: start 12:19:09 crystal.1 | 2017-10-09T15:19:09.600Z 32606 TID-1zee83k JID=dc4136909e800817b7c3e3de INFO: Start 12:19:09 ruby.1 | 2017-10-09T15:19:09.600Z 32609 TID-ox626dzv0 RubyApp::Workers::ProducerWorker JID-2bef1352ac43b2197e2d9d9f INFO: done: 0.001 sec 12:19:09 tail.1 | 6 seconds sleep received 12:19:10 crystal.1 | 2017-10-09T15:19:10.580Z 32606 TID-1zee6tc JID=2a385f1009cb3aca94b9c4bf INFO: Done: 9.002191 sec
In the sample above you may see three distinct applications writing down:
The last one is going to print out every new line written into tmp/output.txt.
If you want to see the Sidekiq web dashboard, open the following URL in your browser:
- Fork it ( https://github.com/andersondias/multiplatform-sidekiq/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
- andersondias Anderson Dias - creator, maintainer