qwirk 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.md +7 -0
- data/LICENSE.txt +201 -0
- data/README.md +180 -0
- data/Rakefile +34 -0
- data/examples/README +1 -0
- data/examples/activemq.xml +84 -0
- data/examples/advanced_requestor/README.md +15 -0
- data/examples/advanced_requestor/base_request_worker.rb +18 -0
- data/examples/advanced_requestor/char_count_worker.rb +16 -0
- data/examples/advanced_requestor/config.ru +24 -0
- data/examples/advanced_requestor/exception_raiser_worker.rb +17 -0
- data/examples/advanced_requestor/length_worker.rb +14 -0
- data/examples/advanced_requestor/print_worker.rb +14 -0
- data/examples/advanced_requestor/publisher.rb +49 -0
- data/examples/advanced_requestor/qwirk.yml +16 -0
- data/examples/advanced_requestor/reverse_worker.rb +14 -0
- data/examples/advanced_requestor/triple_worker.rb +14 -0
- data/examples/batch/my_batch_worker.rb +30 -0
- data/examples/batch/my_line_worker.rb +8 -0
- data/examples/qwirk.yml +20 -0
- data/examples/requestor/README.md +13 -0
- data/examples/requestor/config.ru +13 -0
- data/examples/requestor/qwirk_persist.yml +5 -0
- data/examples/requestor/requestor.rb +68 -0
- data/examples/requestor/reverse_echo_worker.rb +15 -0
- data/examples/setup.rb +13 -0
- data/examples/shared/README.md +24 -0
- data/examples/shared/config.ru +13 -0
- data/examples/shared/publisher.rb +49 -0
- data/examples/shared/qwirk_persist.yml +5 -0
- data/examples/shared/shared_worker.rb +16 -0
- data/examples/simple/README +53 -0
- data/examples/simple/bar_worker.rb +10 -0
- data/examples/simple/baz_worker.rb +10 -0
- data/examples/simple/config.ru +14 -0
- data/examples/simple/publisher.rb +49 -0
- data/examples/simple/qwirk_persist.yml +4 -0
- data/examples/simple/tmp/kahadb/db-1.log +0 -0
- data/examples/simple/tmp/kahadb/db.data +0 -0
- data/examples/simple/tmp/kahadb/db.redo +0 -0
- data/examples/task/README +47 -0
- data/examples/task/config.ru +14 -0
- data/examples/task/foo_worker.rb +10 -0
- data/examples/task/messages.out +1000 -0
- data/examples/task/publisher.rb +25 -0
- data/examples/task/qwirk_persist.yml +5 -0
- data/examples/task/task.rb +36 -0
- data/lib/qwirk.rb +63 -0
- data/lib/qwirk/adapter.rb +45 -0
- data/lib/qwirk/base_worker.rb +96 -0
- data/lib/qwirk/batch.rb +4 -0
- data/lib/qwirk/batch/acquire_file_strategy.rb +47 -0
- data/lib/qwirk/batch/active_record.rb +3 -0
- data/lib/qwirk/batch/active_record/batch_job.rb +111 -0
- data/lib/qwirk/batch/active_record/failed_record.rb +5 -0
- data/lib/qwirk/batch/active_record/outstanding_record.rb +6 -0
- data/lib/qwirk/batch/file_status_strategy.rb +86 -0
- data/lib/qwirk/batch/file_worker.rb +228 -0
- data/lib/qwirk/batch/job_status.rb +29 -0
- data/lib/qwirk/batch/parse_file_strategy.rb +48 -0
- data/lib/qwirk/engine.rb +9 -0
- data/lib/qwirk/loggable.rb +23 -0
- data/lib/qwirk/manager.rb +140 -0
- data/lib/qwirk/marshal_strategy.rb +74 -0
- data/lib/qwirk/marshal_strategy/bson.rb +37 -0
- data/lib/qwirk/marshal_strategy/json.rb +37 -0
- data/lib/qwirk/marshal_strategy/none.rb +26 -0
- data/lib/qwirk/marshal_strategy/ruby.rb +26 -0
- data/lib/qwirk/marshal_strategy/string.rb +25 -0
- data/lib/qwirk/marshal_strategy/yaml.rb +25 -0
- data/lib/qwirk/publish_handle.rb +170 -0
- data/lib/qwirk/publisher.rb +67 -0
- data/lib/qwirk/queue_adapter.rb +3 -0
- data/lib/qwirk/queue_adapter/active_mq.rb +13 -0
- data/lib/qwirk/queue_adapter/active_mq/publisher.rb +12 -0
- data/lib/qwirk/queue_adapter/active_mq/worker_config.rb +16 -0
- data/lib/qwirk/queue_adapter/in_mem.rb +7 -0
- data/lib/qwirk/queue_adapter/in_mem/factory.rb +45 -0
- data/lib/qwirk/queue_adapter/in_mem/publisher.rb +98 -0
- data/lib/qwirk/queue_adapter/in_mem/queue.rb +88 -0
- data/lib/qwirk/queue_adapter/in_mem/reply_queue.rb +56 -0
- data/lib/qwirk/queue_adapter/in_mem/topic.rb +48 -0
- data/lib/qwirk/queue_adapter/in_mem/worker.rb +63 -0
- data/lib/qwirk/queue_adapter/in_mem/worker_config.rb +59 -0
- data/lib/qwirk/queue_adapter/jms.rb +50 -0
- data/lib/qwirk/queue_adapter/jms/connection.rb +42 -0
- data/lib/qwirk/queue_adapter/jms/consumer.rb +37 -0
- data/lib/qwirk/queue_adapter/jms/publisher.rb +126 -0
- data/lib/qwirk/queue_adapter/jms/worker.rb +89 -0
- data/lib/qwirk/queue_adapter/jms/worker_config.rb +38 -0
- data/lib/qwirk/remote_exception.rb +42 -0
- data/lib/qwirk/request_worker.rb +62 -0
- data/lib/qwirk/task.rb +177 -0
- data/lib/qwirk/task.rb.sav +194 -0
- data/lib/qwirk/version.rb +3 -0
- data/lib/qwirk/worker.rb +222 -0
- data/lib/qwirk/worker_config.rb +187 -0
- data/lib/rails/generators/qwirk/qwirk_generator.rb +82 -0
- data/lib/rails/generators/qwirk/templates/initializer.rb +6 -0
- data/lib/rails/generators/qwirk/templates/migration.rb +9 -0
- data/lib/rails/generators/qwirk/templates/schema.rb +28 -0
- data/lib/rails/railties/tasks.rake +8 -0
- data/lib/tasks/qwirk_tasks.rake +4 -0
- data/test/base_test.rb +248 -0
- data/test/database.yml +14 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +45 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +22 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +26 -0
- data/test/dummy/config/environments/production.rb +49 -0
- data/test/dummy/config/environments/test.rb +35 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +10 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +58 -0
- data/test/dummy/log/development.log +0 -0
- data/test/dummy/log/production.log +0 -0
- data/test/dummy/log/server.log +0 -0
- data/test/dummy/log/test.log +0 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +26 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/public/javascripts/application.js +2 -0
- data/test/dummy/public/javascripts/controls.js +965 -0
- data/test/dummy/public/javascripts/dragdrop.js +974 -0
- data/test/dummy/public/javascripts/effects.js +1123 -0
- data/test/dummy/public/javascripts/prototype.js +6001 -0
- data/test/dummy/public/javascripts/rails.js +191 -0
- data/test/dummy/script/rails +6 -0
- data/test/integration/navigation_test.rb +7 -0
- data/test/jms.yml +9 -0
- data/test/jms_fail_test.rb +149 -0
- data/test/jms_requestor_block_test.rb +278 -0
- data/test/jms_requestor_test.rb +238 -0
- data/test/jms_test.rb +287 -0
- data/test/marshal_strategy_test.rb +62 -0
- data/test/support/integration_case.rb +5 -0
- data/test/test_helper.rb +7 -0
- data/test/test_helper.rbold +22 -0
- data/test/test_helper_active_record.rb +61 -0
- data/test/unit/qwirk/batch/acquire_file_strategy_test.rb +101 -0
- data/test/unit/qwirk/batch/active_record/batch_job_test.rb +35 -0
- data/test/unit/qwirk/batch/parse_file_strategy_test.rb +49 -0
- metadata +366 -0
data/History.md
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2011 Clarity Services, Inc.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
data/README.md
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
# qwirk
|
|
2
|
+
|
|
3
|
+
http://github.com/ClarityServices/qwirk
|
|
4
|
+
|
|
5
|
+
## Description:
|
|
6
|
+
|
|
7
|
+
JRuby library for performing background tasks via JMS.
|
|
8
|
+
|
|
9
|
+
Alpha version. API still subject to change.
|
|
10
|
+
|
|
11
|
+
## Features/Problems:
|
|
12
|
+
|
|
13
|
+
Currently tested only for ActiveMQ
|
|
14
|
+
|
|
15
|
+
## Install:
|
|
16
|
+
|
|
17
|
+
gem install qwirk
|
|
18
|
+
|
|
19
|
+
## Rails Usage:
|
|
20
|
+
|
|
21
|
+
TODO: This stuff is all obsolete modern_times documentation. Look at the examples for usage information.
|
|
22
|
+
|
|
23
|
+
Create config/jms.yml which might look as follows:
|
|
24
|
+
|
|
25
|
+
development_server: &defaults
|
|
26
|
+
:factory: org.apache.activemq.ActiveMQConnectionFactory
|
|
27
|
+
:broker_url: tcp://127.0.0.1:61616
|
|
28
|
+
:require_jars:
|
|
29
|
+
- <%= Rails.root %>/lib/activemq/activemq-all.jar
|
|
30
|
+
|
|
31
|
+
development_vm:
|
|
32
|
+
<<: *defaults
|
|
33
|
+
:broker_url: vm://127.0.0.1
|
|
34
|
+
:object_message_serialization_defered: true
|
|
35
|
+
|
|
36
|
+
staging:
|
|
37
|
+
<<: *defaults
|
|
38
|
+
:broker_url: tcp://stage2:61616
|
|
39
|
+
:username: myuser
|
|
40
|
+
:password: mypassword
|
|
41
|
+
|
|
42
|
+
production:
|
|
43
|
+
<<: *defaults
|
|
44
|
+
:broker_url: failover://(tcp://msg1:61616,tcp://msg2:61616)?randomize=false&initialReconnectDelay=100&useExponentialBackOff=true&maxCacheSize=524288&trackMessages=true
|
|
45
|
+
:username: myuser
|
|
46
|
+
:password: mypassword
|
|
47
|
+
|
|
48
|
+
In development and test mode, you will notice that there is no configuration defined. In this case, published messages will cause
|
|
49
|
+
synchronous calls to the Worker's perform method which matches the destination queue or topic.
|
|
50
|
+
This will allow your coworkers to use the functionality
|
|
51
|
+
of the queueing system without having to startup a JMS server. If you wanted to start up in an actual server-type mode, you
|
|
52
|
+
might set the QWIRK_ENV environment variable to "development_server" to override the Rails.env. This will allow you to test
|
|
53
|
+
the queueing system without having to make temporary changes to the config file which could accidentally get checked in.
|
|
54
|
+
For staging and production
|
|
55
|
+
modes, you will need to have a JMS server running. Note that this library has only been tested with ActiveMQ.
|
|
56
|
+
|
|
57
|
+
Create config/workers.yml which might look as follows:
|
|
58
|
+
|
|
59
|
+
development:
|
|
60
|
+
Analytics:
|
|
61
|
+
:count: 1
|
|
62
|
+
Dashboard:
|
|
63
|
+
:count: 1
|
|
64
|
+
|
|
65
|
+
stage1:
|
|
66
|
+
Analytics:
|
|
67
|
+
:count: 2
|
|
68
|
+
Dashboard:
|
|
69
|
+
:count: 2
|
|
70
|
+
|
|
71
|
+
app1: &default_setup
|
|
72
|
+
Analytics:
|
|
73
|
+
:count: 2
|
|
74
|
+
Dashboard:
|
|
75
|
+
:count: 2
|
|
76
|
+
|
|
77
|
+
app2:
|
|
78
|
+
<<: *default_setup
|
|
79
|
+
|
|
80
|
+
app3:
|
|
81
|
+
<<: *default_setup
|
|
82
|
+
|
|
83
|
+
In this file, the count represents the number of threads dedicated per worker. The worker first looks for a key that matches
|
|
84
|
+
the Rails.env. If it doesn't find one, it will look for a key matching the non-qualified hostname of the machine. (TODO: Show how to add options
|
|
85
|
+
that get passed to the constructor and a single worker class that operates on 2 different queues). This file is optional and workers
|
|
86
|
+
can be configured ad-hoc instead.
|
|
87
|
+
|
|
88
|
+
If you don't want to explicitly define your workers in a config file, you can create them ad-hoc instead.
|
|
89
|
+
Configure your workers by starting jconsole and connecting to
|
|
90
|
+
the manager process. Go to the MBeans tab and open the tree to
|
|
91
|
+
Qwirk => Manager => Operations => start_worker
|
|
92
|
+
|
|
93
|
+
Start/stop/increase/decrease workers as needed. The state is stored in the log directory (by default)
|
|
94
|
+
so you can stop and start the manager and not have to reconfigure your workers.
|
|
95
|
+
|
|
96
|
+
Create config/initializers/qwirk.rb which might look as follows (TODO: Maybe add or refer to
|
|
97
|
+
examples for registering marshal strategies):
|
|
98
|
+
|
|
99
|
+
Qwirk.init_rails
|
|
100
|
+
# Publishers can be defined wherever appropriate, probably as class variables within the class that uses it
|
|
101
|
+
$foo_publisher = Qwirk::QueueAdapter::JMS::Publisher.new('Foo')
|
|
102
|
+
|
|
103
|
+
When creating publishers, you will probably want to store the value in a class variable. Publishers internally
|
|
104
|
+
make use of a session pool for communicating with the JMS server so you wouldn't want to create a new connection
|
|
105
|
+
every time you published an object.
|
|
106
|
+
|
|
107
|
+
In your code, queue foo objects:
|
|
108
|
+
|
|
109
|
+
$foo_publisher.publish(my_foo_object)
|
|
110
|
+
|
|
111
|
+
In app/workers, create a FooWorker class:
|
|
112
|
+
|
|
113
|
+
class FooWorker
|
|
114
|
+
include Qwirk::QueueAdapter::JMS::Worker
|
|
115
|
+
def perform(my_foo_object)
|
|
116
|
+
# Operate on my_foo_object
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
For the staging and production environment, you will need to startup a Manager process on each machine that handles messages. You
|
|
121
|
+
might create script/worker_manager as follows (assumes Rails.root/script is in your PATH):
|
|
122
|
+
|
|
123
|
+
#!/usr/bin/env runner
|
|
124
|
+
|
|
125
|
+
manager = Qwirk.create_rails_manager
|
|
126
|
+
manager.join
|
|
127
|
+
|
|
128
|
+
TODO: Refer to example jsvc daemon script
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
## Multiple Workers For a Virtual Topic:
|
|
132
|
+
|
|
133
|
+
By default, a worker operates on the queue with the same name as the class minus the Worker postfix. You can override
|
|
134
|
+
this by explicitily by specifying a queue or a virtual topic instead. A virtual_topic (ActiveMQ only) allows you to publish to one destination
|
|
135
|
+
and allow for multiple workers to subscribe. (TODO: need to completely remove the use of topics as every thread for every worker
|
|
136
|
+
receives all messages instead of a group of workers (threads) collectively receiving all messages. Virtual topics get around this
|
|
137
|
+
problem). For instance, suppose you have the following workers:
|
|
138
|
+
|
|
139
|
+
class FooWorker
|
|
140
|
+
include Qwirk::QueueAdapter::JMS::Worker
|
|
141
|
+
virtual_topic 'inquiry'
|
|
142
|
+
|
|
143
|
+
def perform(my_inquiry)
|
|
144
|
+
# Operate on my_inquiry
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
class BarWorker
|
|
149
|
+
include Qwirk::QueueAdapter::JMS::Worker
|
|
150
|
+
virtual_topic 'inquiry'
|
|
151
|
+
|
|
152
|
+
def perform(my_inquiry)
|
|
153
|
+
# Operate on my_inquiry
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
Then you can create a publisher where messages are delivered to both workers:
|
|
158
|
+
|
|
159
|
+
@@publisher = Qwirk::QueueAdapter::JMS::Publisher.new(:virtual_topic_name => 'inquiry')
|
|
160
|
+
...
|
|
161
|
+
@@publisher.publish(my_inquiry)
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
## Requestor Pattern:
|
|
165
|
+
|
|
166
|
+
TODO: See examples/requestor
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
## Requestor Pattern with Multiple RequestWorkers:
|
|
170
|
+
|
|
171
|
+
TODO: See examples/advanced_requestor
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
## Author
|
|
175
|
+
|
|
176
|
+
Brad Pardee
|
|
177
|
+
|
|
178
|
+
## Copyright
|
|
179
|
+
|
|
180
|
+
Copyright (c) 2012 Clarity Services. See LICENSE for details.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#!/usr/bin/env rake
|
|
2
|
+
begin
|
|
3
|
+
require 'bundler/setup'
|
|
4
|
+
rescue LoadError
|
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
|
6
|
+
end
|
|
7
|
+
begin
|
|
8
|
+
require 'rdoc/task'
|
|
9
|
+
rescue LoadError
|
|
10
|
+
require 'rdoc/rdoc'
|
|
11
|
+
require 'rake/rdoctask'
|
|
12
|
+
RDoc::Task = Rake::RDocTask
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
17
|
+
rdoc.title = 'Qwirk'
|
|
18
|
+
rdoc.options << '--line-numbers'
|
|
19
|
+
rdoc.rdoc_files.include('README.md')
|
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
Bundler::GemHelper.install_tasks
|
|
24
|
+
|
|
25
|
+
require 'rake/testtask'
|
|
26
|
+
|
|
27
|
+
Rake::TestTask.new(:test) do |t|
|
|
28
|
+
t.libs << 'lib'
|
|
29
|
+
t.libs << 'test'
|
|
30
|
+
t.pattern = 'test/**/*_test.rb'
|
|
31
|
+
t.verbose = false
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
task :default => :test
|
data/examples/README
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Modify the qwirk.yml file to setup the proper credentials for you ActiveMQ server.
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
ActiveMQ Configuration where the Broker is in-vm
|
|
3
|
+
|
|
4
|
+
Settings objectives:
|
|
5
|
+
- Use available resources
|
|
6
|
+
- No indefinite limiting of producers to prevent "hanging" of producers
|
|
7
|
+
when consumers are slow
|
|
8
|
+
- Use store based message flow so that slow consumers do not slow down producers
|
|
9
|
+
-->
|
|
10
|
+
<beans
|
|
11
|
+
xmlns="http://www.springframework.org/schema/beans"
|
|
12
|
+
xmlns:amq="http://activemq.apache.org/schema/core"
|
|
13
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
14
|
+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
|
15
|
+
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
|
|
16
|
+
|
|
17
|
+
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="qwirk" dataDirectory="tmp" destroyApplicationContextOnStop="true">
|
|
18
|
+
|
|
19
|
+
<!-- Set producerFlowControl limits -->
|
|
20
|
+
<destinationPolicy>
|
|
21
|
+
<policyMap>
|
|
22
|
+
<policyEntries>
|
|
23
|
+
<policyEntry topic=">" producerFlowControl="true" memoryLimit="1024mb" />
|
|
24
|
+
<policyEntry queue=">" producerFlowControl="true" memoryLimit="1024mb" />
|
|
25
|
+
</policyEntries>
|
|
26
|
+
</policyMap>
|
|
27
|
+
</destinationPolicy>
|
|
28
|
+
|
|
29
|
+
<!-- Use the JMX context already created by the JVM -->
|
|
30
|
+
<managementContext>
|
|
31
|
+
<managementContext createConnector="false"/>
|
|
32
|
+
</managementContext>
|
|
33
|
+
|
|
34
|
+
<!--
|
|
35
|
+
Configure message persistence for the broker. The default persistence
|
|
36
|
+
mechanism is the KahaDB store (identified by the kahaDB tag).
|
|
37
|
+
For more information, see:
|
|
38
|
+
|
|
39
|
+
http://activemq.apache.org/persistence.html
|
|
40
|
+
-->
|
|
41
|
+
<persistenceAdapter>
|
|
42
|
+
<kahaDB directory="tmp/kahadb"/>
|
|
43
|
+
</persistenceAdapter>
|
|
44
|
+
|
|
45
|
+
<plugins>
|
|
46
|
+
<!-- Configure authentication of remote connections -->
|
|
47
|
+
<simpleAuthenticationPlugin>
|
|
48
|
+
<users>
|
|
49
|
+
<authenticationUser username="qwirkadmin" password="qwirkadmin" groups="users,admins"/>
|
|
50
|
+
<authenticationUser username="qwirk" password="qwirk" groups="users"/>
|
|
51
|
+
</users>
|
|
52
|
+
</simpleAuthenticationPlugin>
|
|
53
|
+
</plugins>
|
|
54
|
+
|
|
55
|
+
<!-- Limits for the broker before it slows down or fails producers.
|
|
56
|
+
Cause producers to fail with javax.jms.ResourceAllocationException
|
|
57
|
+
if no space is available after 3 seconds -->
|
|
58
|
+
<systemUsage>
|
|
59
|
+
<systemUsage sendFailIfNoSpaceAfterTimeout="3000">
|
|
60
|
+
<!-- Memory limit for NON_PERSISTENT messages
|
|
61
|
+
Apparently no longer used since ActiveMQ 5 now uses store
|
|
62
|
+
based cursors for NON_PERSISTENT messages -->
|
|
63
|
+
<memoryUsage>
|
|
64
|
+
<memoryUsage limit="2 gb"/>
|
|
65
|
+
</memoryUsage>
|
|
66
|
+
<!-- Disk storage limit for PERSISTENT messages -->
|
|
67
|
+
<storeUsage>
|
|
68
|
+
<storeUsage limit="50 gb"/>
|
|
69
|
+
</storeUsage>
|
|
70
|
+
<!-- Disk storage limit for temporary (NON_PERSISTENT) messages -->
|
|
71
|
+
<tempUsage>
|
|
72
|
+
<tempUsage limit="50 gb"/>
|
|
73
|
+
</tempUsage>
|
|
74
|
+
</systemUsage>
|
|
75
|
+
</systemUsage>
|
|
76
|
+
|
|
77
|
+
<!-- Allow remote connections using openwire protocols -->
|
|
78
|
+
<transportConnectors>
|
|
79
|
+
<transportConnector name="openwire" uri="tcp://0.0.0.0:61616"/>
|
|
80
|
+
</transportConnectors>
|
|
81
|
+
|
|
82
|
+
</broker>
|
|
83
|
+
|
|
84
|
+
</beans>
|