totoro 1.0.5 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +6 -0
  3. data/lib/generators/totoro/templates/totoro.yml +3 -2
  4. data/lib/totoro/config.rb +8 -0
  5. data/lib/totoro/services/broadcast_service.rb +5 -1
  6. data/lib/totoro/services/enqueue_service.rb +6 -2
  7. data/lib/totoro/version.rb +1 -1
  8. data/pkg/totoro-1.0.5.gem +0 -0
  9. data/pkg/totoro-1.0.5/CODE_OF_CONDUCT.md +74 -0
  10. data/pkg/totoro-1.0.5/Dockerfile +14 -0
  11. data/pkg/totoro-1.0.5/Gemfile +8 -0
  12. data/pkg/totoro-1.0.5/Gemfile.lock +68 -0
  13. data/pkg/totoro-1.0.5/LICENSE.txt +21 -0
  14. data/pkg/totoro-1.0.5/README.md +169 -0
  15. data/pkg/totoro-1.0.5/Rakefile +8 -0
  16. data/pkg/totoro-1.0.5/bin/console +15 -0
  17. data/pkg/totoro-1.0.5/bin/setup +8 -0
  18. data/pkg/totoro-1.0.5/bin/totoro +16 -0
  19. data/pkg/totoro-1.0.5/docker-compose.yml +43 -0
  20. data/pkg/totoro-1.0.5/lib/generators/totoro/config_generator.rb +12 -0
  21. data/pkg/totoro-1.0.5/lib/generators/totoro/init_generator.rb +14 -0
  22. data/pkg/totoro-1.0.5/lib/generators/totoro/templates/create_totoro_failed_messages.rb +12 -0
  23. data/pkg/totoro-1.0.5/lib/generators/totoro/templates/initializer.rb +1 -0
  24. data/pkg/totoro-1.0.5/lib/generators/totoro/templates/totoro.yml +33 -0
  25. data/pkg/totoro-1.0.5/lib/generators/totoro/templates/update_totoro_failed_messages.rb +6 -0
  26. data/pkg/totoro-1.0.5/lib/generators/totoro/templates/worker.rb.erb +10 -0
  27. data/pkg/totoro-1.0.5/lib/generators/totoro/update_generator.rb +12 -0
  28. data/pkg/totoro-1.0.5/lib/generators/totoro/worker_generator.rb +17 -0
  29. data/pkg/totoro-1.0.5/lib/totoro.rb +21 -0
  30. data/pkg/totoro-1.0.5/lib/totoro/base_queue.rb +44 -0
  31. data/pkg/totoro-1.0.5/lib/totoro/base_worker.rb +61 -0
  32. data/pkg/totoro-1.0.5/lib/totoro/config.rb +44 -0
  33. data/pkg/totoro-1.0.5/lib/totoro/errors/connection_break_error.rb +6 -0
  34. data/pkg/totoro-1.0.5/lib/totoro/errors/need_queue_name_error.rb +5 -0
  35. data/pkg/totoro-1.0.5/lib/totoro/initializer.rb +39 -0
  36. data/pkg/totoro-1.0.5/lib/totoro/message_resender.rb +17 -0
  37. data/pkg/totoro-1.0.5/lib/totoro/models/totoro_failed_message.rb +8 -0
  38. data/pkg/totoro-1.0.5/lib/totoro/railtie.rb +15 -0
  39. data/pkg/totoro-1.0.5/lib/totoro/services/broadcast_service.rb +33 -0
  40. data/pkg/totoro-1.0.5/lib/totoro/services/enqueue_service.rb +38 -0
  41. data/pkg/totoro-1.0.5/lib/totoro/services/resend_service.rb +19 -0
  42. data/pkg/totoro-1.0.5/lib/totoro/services/subscribe_service.rb +34 -0
  43. data/pkg/totoro-1.0.5/lib/totoro/tasks/resend_message.rake +8 -0
  44. data/pkg/totoro-1.0.5/lib/totoro/utils.rb +22 -0
  45. data/pkg/totoro-1.0.5/lib/totoro/version.rb +5 -0
  46. data/pkg/totoro-1.0.5/pkg/totoro-1.0.4.gem +0 -0
  47. data/pkg/totoro-1.0.5/spec/spec_helper.rb +14 -0
  48. data/pkg/totoro-1.0.5/spec/totoro_spec.rb +9 -0
  49. data/pkg/totoro-1.0.5/test/rabbitmq_commands.txt +6 -0
  50. data/pkg/totoro-1.0.5/test/totoro_test/Gemfile +43 -0
  51. data/pkg/totoro-1.0.5/test/totoro_test/Gemfile.lock +157 -0
  52. data/pkg/totoro-1.0.5/test/totoro_test/README.md +24 -0
  53. data/pkg/totoro-1.0.5/test/totoro_test/Rakefile +6 -0
  54. data/pkg/totoro-1.0.5/test/totoro_test/app/channels/application_cable/channel.rb +4 -0
  55. data/pkg/totoro-1.0.5/test/totoro_test/app/channels/application_cable/connection.rb +4 -0
  56. data/pkg/totoro-1.0.5/test/totoro_test/app/controllers/application_controller.rb +2 -0
  57. data/pkg/totoro-1.0.5/test/totoro_test/app/jobs/application_job.rb +2 -0
  58. data/pkg/totoro-1.0.5/test/totoro_test/app/mailers/application_mailer.rb +4 -0
  59. data/pkg/totoro-1.0.5/test/totoro_test/app/models/application_record.rb +3 -0
  60. data/pkg/totoro-1.0.5/test/totoro_test/app/models/worker/example_queue.rb +10 -0
  61. data/pkg/totoro-1.0.5/test/totoro_test/app/models/worker/exchange_queue.rb +10 -0
  62. data/pkg/totoro-1.0.5/test/totoro_test/app/models/worker/shu_queue.rb +10 -0
  63. data/pkg/totoro-1.0.5/test/totoro_test/app/services/bench_mark.txt +7 -0
  64. data/pkg/totoro-1.0.5/test/totoro_test/app/services/load_test.rb +19 -0
  65. data/pkg/totoro-1.0.5/test/totoro_test/app/views/layouts/mailer.html.erb +13 -0
  66. data/pkg/totoro-1.0.5/test/totoro_test/app/views/layouts/mailer.text.erb +1 -0
  67. data/pkg/totoro-1.0.5/test/totoro_test/bin/bundle +3 -0
  68. data/pkg/totoro-1.0.5/test/totoro_test/bin/delayed_job +5 -0
  69. data/pkg/totoro-1.0.5/test/totoro_test/bin/rails +9 -0
  70. data/pkg/totoro-1.0.5/test/totoro_test/bin/rake +9 -0
  71. data/pkg/totoro-1.0.5/test/totoro_test/bin/setup +34 -0
  72. data/pkg/totoro-1.0.5/test/totoro_test/bin/spring +17 -0
  73. data/pkg/totoro-1.0.5/test/totoro_test/bin/update +29 -0
  74. data/pkg/totoro-1.0.5/test/totoro_test/config.ru +5 -0
  75. data/pkg/totoro-1.0.5/test/totoro_test/config/application.rb +34 -0
  76. data/pkg/totoro-1.0.5/test/totoro_test/config/boot.rb +3 -0
  77. data/pkg/totoro-1.0.5/test/totoro_test/config/cable.yml +10 -0
  78. data/pkg/totoro-1.0.5/test/totoro_test/config/database.yml +55 -0
  79. data/pkg/totoro-1.0.5/test/totoro_test/config/environment.rb +5 -0
  80. data/pkg/totoro-1.0.5/test/totoro_test/config/environments/development.rb +47 -0
  81. data/pkg/totoro-1.0.5/test/totoro_test/config/environments/production.rb +82 -0
  82. data/pkg/totoro-1.0.5/test/totoro_test/config/environments/test.rb +41 -0
  83. data/pkg/totoro-1.0.5/test/totoro_test/config/initializers/application_controller_renderer.rb +8 -0
  84. data/pkg/totoro-1.0.5/test/totoro_test/config/initializers/backtrace_silencers.rb +7 -0
  85. data/pkg/totoro-1.0.5/test/totoro_test/config/initializers/cors.rb +16 -0
  86. data/pkg/totoro-1.0.5/test/totoro_test/config/initializers/filter_parameter_logging.rb +4 -0
  87. data/pkg/totoro-1.0.5/test/totoro_test/config/initializers/inflections.rb +16 -0
  88. data/pkg/totoro-1.0.5/test/totoro_test/config/initializers/mime_types.rb +4 -0
  89. data/pkg/totoro-1.0.5/test/totoro_test/config/initializers/totoro.rb +1 -0
  90. data/pkg/totoro-1.0.5/test/totoro_test/config/initializers/wrap_parameters.rb +14 -0
  91. data/pkg/totoro-1.0.5/test/totoro_test/config/locales/en.yml +33 -0
  92. data/pkg/totoro-1.0.5/test/totoro_test/config/puma.rb +56 -0
  93. data/pkg/totoro-1.0.5/test/totoro_test/config/routes.rb +3 -0
  94. data/pkg/totoro-1.0.5/test/totoro_test/config/secrets.yml +32 -0
  95. data/pkg/totoro-1.0.5/test/totoro_test/config/spring.rb +6 -0
  96. data/pkg/totoro-1.0.5/test/totoro_test/config/totoro.yml +42 -0
  97. data/pkg/totoro-1.0.5/test/totoro_test/db/migrate/20181019041208_create_delayed_jobs.rb +22 -0
  98. data/pkg/totoro-1.0.5/test/totoro_test/db/migrate/20181019070846_create_totoro_failed_messages.rb +11 -0
  99. data/pkg/totoro-1.0.5/test/totoro_test/db/migrate/20181228033422_update_totoro_failed_messages.rb +5 -0
  100. data/pkg/totoro-1.0.5/test/totoro_test/db/schema.rb +42 -0
  101. data/pkg/totoro-1.0.5/test/totoro_test/db/seeds.rb +7 -0
  102. data/pkg/totoro-1.0.5/test/totoro_test/public/robots.txt +1 -0
  103. data/pkg/totoro-1.0.5/test/totoro_test/test/test_helper.rb +10 -0
  104. data/pkg/totoro-1.0.5/totoro.gemspec +29 -0
  105. metadata +99 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d5eec7c12e6dde49a945a21c48be6db1a773b28e1a1cceb5bc1dd8f63c741d15
4
- data.tar.gz: 44c24808e0603cecdf0883a9df55681487830d48aecbc38ac8c8db6fac93666d
3
+ metadata.gz: 74a844282fa52f395d79a90a5df63dbe574467dc173f7641a9ac1b870fc36e11
4
+ data.tar.gz: e9405fd1e77370f43cb2aae761986924cd772cbf5df5b7df6ca29e7d9260b647
5
5
  SHA512:
6
- metadata.gz: c6c8e432b961bc807045d60587983aae53e663ec8e9b78d0e92f8c3c1aa09dc583574a06a3b14c220eb573971145010940bb90e521dacd0b17bd35004738f22d
7
- data.tar.gz: 067b6429ee06870dc084f4671c7581c81223d9219b6e46359e68b11545329a78a154d6b62402db99ad1e8f2bf5f386736686a010c033244f0663404dbc35c28a
6
+ metadata.gz: faeafba0999a947e94861532c1e08cc296865b9ef163b258f91180de6b5f5c4b954eb3cbb9110b360b2924a2a5e7328e8020e3d5168810e62a887477ec9ee392
7
+ data.tar.gz: 3905b199f723493c9b3212482b84d804c74aed1dc769d863b2ee547aefeceffe97e75aa727d1d781de9b9bb0e3e2dc5e3eeb616bcf7e28da394dff240d54cb41
data/README.md CHANGED
@@ -33,6 +33,10 @@ This command will generate two files
33
33
  rails g delayed_job:active_record
34
34
  ```
35
35
 
36
+ #### delayed job configuration
37
+
38
+ https://github.com/collectiveidea/delayed_job
39
+
36
40
  #### Run DB migraion
37
41
  `rake db:migrate`
38
42
 
@@ -49,6 +53,7 @@ default: &default
49
53
  queue:
50
54
  normal_queue_for_both_enqueue_and_subscribe:
51
55
  name: default_exchange.queue.name
56
+ persistent: true
52
57
  durable: true
53
58
  clean_start: false
54
59
  exchange_queue_for_subscribe:
@@ -58,6 +63,7 @@ default: &default
58
63
  exchange:
59
64
  exchange_for_fanout_enqueue:
60
65
  name: fanout.exchange.name
66
+ persistent: false
61
67
 
62
68
  custom:
63
69
  connect:
@@ -8,9 +8,10 @@ default: &default
8
8
  example_queue:
9
9
  name: real.queue.name
10
10
  durable: true
11
+ persistent: true
11
12
  clean_start: false
12
- manual_ack: true
13
- force_ack: true
13
+ manual_ack: false
14
+ force_ack: false
14
15
 
15
16
  custom:
16
17
  connect:
@@ -23,6 +23,14 @@ module Totoro
23
23
  @data[:queue][queue_id][:exchange]
24
24
  end
25
25
 
26
+ def queue_persistent?(id)
27
+ !!@data[:queue][id][:persistent]
28
+ end
29
+
30
+ def exchange_persistent?(id)
31
+ !!@data[:exchange][id][:persistent]
32
+ end
33
+
26
34
  def clean_start?(id)
27
35
  !!@data[:queue][id][:clean_start]
28
36
  end
@@ -11,7 +11,7 @@ module Totoro
11
11
  @connection.start unless @connection.connected?
12
12
  exchange = channel.fanout(@config.exchange(exchange_id))
13
13
  payload = JSON.dump payload
14
- exchange.publish(payload)
14
+ exchange.publish(payload, options(attrs))
15
15
  Rails.logger.debug "send message to exchange #{@config.exchange(exchange_id)}"
16
16
  STDOUT.flush
17
17
  channel.close
@@ -26,6 +26,10 @@ module Totoro
26
26
 
27
27
  private
28
28
 
29
+ def options(exchange_id, attrs)
30
+ { persistent: @config.exchange_persistent?(exchange_id) }.merge(attrs)
31
+ end
32
+
29
33
  def channel
30
34
  @channel ||= @connection.create_channel
31
35
  end
@@ -7,11 +7,11 @@ module Totoro
7
7
  @config = config
8
8
  end
9
9
 
10
- def enqueue(id, payload)
10
+ def enqueue(id, payload, attrs = {})
11
11
  @connection.start unless @connection.connected?
12
12
  queue = channel.queue(*@config.queue(id))
13
13
  payload = JSON.dump payload
14
- exchange.publish(payload, routing_key: queue.name)
14
+ exchange.publish(payload, options(id, queue.name, attrs))
15
15
  Rails.logger.debug "send message to #{queue.name}"
16
16
  STDOUT.flush
17
17
  channel.close
@@ -26,6 +26,10 @@ module Totoro
26
26
 
27
27
  private
28
28
 
29
+ def options(queue_id, queue_name, attrs)
30
+ { persistent: @config.queue_persistent?(queue_id), routing_key: queue_name }.merge(attrs)
31
+ end
32
+
29
33
  def channel
30
34
  @channel ||= @connection.create_channel
31
35
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Totoro
4
- VERSION = '1.0.5'
4
+ VERSION = '1.0.6'
5
5
  end
Binary file
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at shu.hui@blockchaintech.net.au. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
@@ -0,0 +1,14 @@
1
+ FROM ruby:2.5.0
2
+
3
+ #Cache bundle install
4
+ WORKDIR /tmp
5
+ ADD . /totoro
6
+ ADD ./test/totoro_test/Gemfile Gemfile
7
+ ADD ./test/totoro_test/Gemfile.lock Gemfile.lock
8
+ RUN bundle install
9
+
10
+ RUN mkdir /app
11
+ WORKDIR /app
12
+ ADD ./test/totoro_test /app
13
+
14
+ CMD ["rails", "c"]
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in totoro.gemspec
8
+ gemspec
@@ -0,0 +1,68 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ totoro (1.0.4)
5
+ bunny (~> 2.10)
6
+ delayed_job_active_record (~> 4.1.3)
7
+ delayed_job_recurring (~> 0.3.7)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activemodel (5.2.2)
13
+ activesupport (= 5.2.2)
14
+ activerecord (5.2.2)
15
+ activemodel (= 5.2.2)
16
+ activesupport (= 5.2.2)
17
+ arel (>= 9.0)
18
+ activesupport (5.2.2)
19
+ concurrent-ruby (~> 1.0, >= 1.0.2)
20
+ i18n (>= 0.7, < 2)
21
+ minitest (~> 5.1)
22
+ tzinfo (~> 1.1)
23
+ amq-protocol (2.3.0)
24
+ arel (9.0.0)
25
+ bunny (2.13.0)
26
+ amq-protocol (~> 2.3, >= 2.3.0)
27
+ concurrent-ruby (1.1.4)
28
+ delayed_job (4.1.5)
29
+ activesupport (>= 3.0, < 5.3)
30
+ delayed_job_active_record (4.1.3)
31
+ activerecord (>= 3.0, < 5.3)
32
+ delayed_job (>= 3.0, < 5)
33
+ delayed_job_recurring (0.3.8)
34
+ delayed_job (>= 3.0)
35
+ delayed_job_active_record
36
+ diff-lcs (1.3)
37
+ i18n (1.5.3)
38
+ concurrent-ruby (~> 1.0)
39
+ minitest (5.11.3)
40
+ rake (10.5.0)
41
+ rspec (3.7.0)
42
+ rspec-core (~> 3.7.0)
43
+ rspec-expectations (~> 3.7.0)
44
+ rspec-mocks (~> 3.7.0)
45
+ rspec-core (3.7.1)
46
+ rspec-support (~> 3.7.0)
47
+ rspec-expectations (3.7.0)
48
+ diff-lcs (>= 1.2.0, < 2.0)
49
+ rspec-support (~> 3.7.0)
50
+ rspec-mocks (3.7.0)
51
+ diff-lcs (>= 1.2.0, < 2.0)
52
+ rspec-support (~> 3.7.0)
53
+ rspec-support (3.7.1)
54
+ thread_safe (0.3.6)
55
+ tzinfo (1.2.5)
56
+ thread_safe (~> 0.1)
57
+
58
+ PLATFORMS
59
+ ruby
60
+
61
+ DEPENDENCIES
62
+ bundler (~> 1.16)
63
+ rake (~> 10.0)
64
+ rspec (~> 3.0)
65
+ totoro!
66
+
67
+ BUNDLED WITH
68
+ 1.16.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 ShuHui18
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,169 @@
1
+ # Totoro, a RabbitMQ Util
2
+
3
+ Totoro is a RabbitMQ util that focuses on samplify queue operation.
4
+ ## Dependencies
5
+ Please install [Delayed Job active record](https://rubygems.org/gems/delayed_job_active_record) and [Delayed Job recurring](https://rubygems.org/gems/delayed_job_recurring) before use Totoro.
6
+ Totoro basically use delayed job to cache and resend falied messages.
7
+ ## Installation
8
+
9
+ ### Install gem
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'totoro'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ #### Initialize Totoro for Rails app
21
+ ```
22
+ rails g totoro:init
23
+ ```
24
+
25
+ This command will generate two files
26
+
27
+ 1. `totoro.yml` (Rabbitmq configuration file)
28
+ 2. `initilizers/totoro.rb` (Rails initializer)
29
+ 3. `db/migrate/[tiemstamp]_create_totoro_failed_messages.rb` (DB migration to create messages caching table)
30
+
31
+ #### if you havn't install gem delayed_jobs, then run initialization scripts
32
+ ```
33
+ rails g delayed_job:active_record
34
+ ```
35
+
36
+ #### Run DB migraion
37
+ `rake db:migrate`
38
+
39
+ ## Sample configuration
40
+
41
+ ```yaml
42
+ default: &default
43
+ default:
44
+ connect:
45
+ host: rabbitmq
46
+ port: 5672
47
+ user: app
48
+ pass: app
49
+ queue:
50
+ normal_queue_for_both_enqueue_and_subscribe:
51
+ name: default_exchange.queue.name
52
+ durable: true
53
+ clean_start: false
54
+ exchange_queue_for_subscribe:
55
+ name: fanout.exchange.queue
56
+ durable: true
57
+ exchange: fanout.exchange.name
58
+ exchange:
59
+ exchange_for_fanout_enqueue:
60
+ name: fanout.exchange.name
61
+
62
+ custom:
63
+ connect:
64
+ host: rabbitmq
65
+ port: 5672
66
+ user: app
67
+ pass: app
68
+ queue:
69
+ custom_queue:
70
+ name: custom.queue.name
71
+ durable: true
72
+
73
+ development:
74
+ <<: *default
75
+
76
+ test:
77
+ <<: *default
78
+
79
+ production:
80
+ <<: *default
81
+
82
+ ```
83
+ ## Quick Start
84
+
85
+ ### Resend Failed messages daemon
86
+
87
+ Please run `rake totoro:resend_msg` before you start your app.
88
+
89
+ ### Default rabbitmq server
90
+
91
+ #### Enqueue
92
+
93
+ ```
94
+ Totoro::Queue.enqueue('queue_id', payload)
95
+ ```
96
+
97
+ #### BroadCast (Enqueue to fanout exchange)
98
+
99
+ ```
100
+ Totoro::Queue.broadcast('exchange_id', payload)
101
+ ```
102
+
103
+ #### Dequeue
104
+ To create a dequeue daemon, first you need to create a worker
105
+ ```
106
+ rails g totoro:worker <worker_name> <queue_name>
107
+ ```
108
+ after that, add business logic in the process method
109
+ ```
110
+ module Worker
111
+ class WorkerClass < Totoro::BaseWorker
112
+ setup queue_name: <queue_name>
113
+ def process(payload, metadata, delivery_info)
114
+ # worker process
115
+ end
116
+ end
117
+ end
118
+ ```
119
+ finally, run the background deamon
120
+ ```
121
+ bundle exec totoro worker_class
122
+ ```
123
+
124
+ ### Custom rabbitmq server
125
+
126
+ When you have more than one rabbitmq server to connect, you need to add custom configuration.
127
+
128
+ To use the custom rabbitmq server you need to add `ServerName` between `Totoro` and `Queue`
129
+
130
+ For example:
131
+
132
+ #### Enqueue
133
+
134
+ ```
135
+ Totoro::<ServerName>::Queue.enqueue('queue', payload)
136
+ ```
137
+
138
+ #### Dequeue
139
+ To create a dequeue daemon, first you need to create a worker
140
+ ```
141
+ rails g totoro:wroker <worker_name> <queue_name> <prefix>
142
+ ```
143
+ after that, add business logic in the process method
144
+ ```
145
+ module Worker
146
+ class WorkerClass < Totoro::BaseWorker
147
+ setup queue_name: <queue_name>, prefix: <prefix>
148
+ def process(payload, metadata, delivery_info)
149
+ # worker process
150
+ end
151
+ end
152
+ end
153
+ ```
154
+ finally, run the background deamon
155
+ ```
156
+ bundle exec totoro worker_class
157
+ ```
158
+
159
+ ## Contributing
160
+
161
+ Bug reports and pull requests are welcome on GitHub at https://github.com/blockchaintech-au/totoro. 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.
162
+
163
+ ## License
164
+
165
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
166
+
167
+ ## Code of Conduct
168
+
169
+ Everyone interacting in the Totoro project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/totoro/blob/master/CODE_OF_CONDUCT.md).