jruby-hornetq 0.2.0.alpha
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY.md +5 -0
- data/LICENSE.txt +201 -0
- data/README.md +249 -0
- data/Rakefile +23 -0
- data/bin/hornetq_server +70 -0
- data/examples/backup_server.yml +4 -0
- data/examples/batch_client.rb +124 -0
- data/examples/client.rb +49 -0
- data/examples/consumer.rb +35 -0
- data/examples/hornetq.yml +36 -0
- data/examples/live_server.yml +5 -0
- data/examples/multi_client.rb +63 -0
- data/examples/multi_consumer.rb +54 -0
- data/examples/producer.rb +36 -0
- data/examples/run_broker.rb +59 -0
- data/examples/server.rb +42 -0
- data/examples/standalone_server.yml +3 -0
- data/lib/hornetq/client_requestor.rb +30 -0
- data/lib/hornetq/client_server.rb +47 -0
- data/lib/hornetq/hornet_q_client.rb +388 -0
- data/lib/hornetq/lib/hornetq-core-client.jar +0 -0
- data/lib/hornetq/lib/hornetq-core.jar +0 -0
- data/lib/hornetq/lib/netty.jar +0 -0
- data/lib/hornetq/org_hornetq_api_core_client_client_session.rb +16 -0
- data/lib/hornetq/org_hornetq_core_client_impl_client_message_impl.rb +166 -0
- data/lib/hornetq/org_hornetq_core_client_impl_client_producer_impl.rb +5 -0
- data/lib/hornetq/org_hornetq_utils_typed_properties.rb +60 -0
- data/lib/hornetq/session_pool.rb +175 -0
- data/lib/hornetq.rb +9 -0
- metadata +106 -0
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,249 @@
|
|
1
|
+
jruby-hornetq
|
2
|
+
=============
|
3
|
+
|
4
|
+
* http://github.com/ClarityServices/jruby-hornetq
|
5
|
+
|
6
|
+
### WARNING: Alpha code!!
|
7
|
+
|
8
|
+
This code should only be used for prototyping at this time, since breaking
|
9
|
+
changes are made between every release. Once the code goes to V1.0.0 we will
|
10
|
+
make every effort to not break the existing interface in any way.
|
11
|
+
|
12
|
+
Feedback is welcome and appreciated :)
|
13
|
+
|
14
|
+
### Introduction
|
15
|
+
|
16
|
+
jruby-hornetq attempts to "rubify" the HornetQ Java libraries without
|
17
|
+
compromising performance. It does this by sprinkling "Ruby-goodness" into the
|
18
|
+
existing HornetQ Java classes and interfaces, I.e. By adding Ruby methods to
|
19
|
+
the existing classes and interfaces. Since jruby-hornetq exposes the HornetQ
|
20
|
+
Java classes directly there is no performance impact that would have been
|
21
|
+
introduced had the entire API been wrapped in a Ruby layer.
|
22
|
+
|
23
|
+
In this way, using regular Ruby constructs a Ruby program can easily
|
24
|
+
interact with HornetQ in a highly performant way
|
25
|
+
|
26
|
+
### Install
|
27
|
+
|
28
|
+
gem install jruby-hornetq
|
29
|
+
|
30
|
+
### Important
|
31
|
+
|
32
|
+
jruby-hornetq exposes the HornetQ Core API, not its JMS API. There are
|
33
|
+
several reasons for choosing the HornetQ Core API over its JMS API:
|
34
|
+
* The Core API supports the use of Addresses, not just Queues
|
35
|
+
* The Core API exposes more capabilities than the JMS API (E.g. Management APIs)
|
36
|
+
* The HornetQ team recommend the Core API for performance
|
37
|
+
* The HornetQ JMS API is just another wrapper on top of its Core API
|
38
|
+
|
39
|
+
To use the JMS API, see the jruby-jms project. (Not yet released into the wild,
|
40
|
+
let me know if you want it :) )
|
41
|
+
|
42
|
+
HornetQ
|
43
|
+
-------
|
44
|
+
|
45
|
+
For information on the HornetQ messaging and queuing system, see:
|
46
|
+
|
47
|
+
Concepts & Terminology
|
48
|
+
----------------------
|
49
|
+
|
50
|
+
### Queue
|
51
|
+
|
52
|
+
In order to read messages a consumer needs to the read messages from a queue.
|
53
|
+
The queue is defined prior to the message being sent and is used to hold the
|
54
|
+
messages. The consumer does not have to be running in order to receive messages.
|
55
|
+
|
56
|
+
### Address
|
57
|
+
|
58
|
+
In traditional messaging and queuing systems there is only a queue when both
|
59
|
+
read and writing messages. With the advent of AMQP and in HornetQ we now have
|
60
|
+
the concept of an Address which is different from a Queue.
|
61
|
+
|
62
|
+
An Address can be thought of the address we would put on an envelope before
|
63
|
+
mailing it. We do not have to have any knowlegde of the USPS infrastructure
|
64
|
+
to mail the letter. In HornetQ we Address a message and in HornetQ the Address
|
65
|
+
is routed to one or more Queues.
|
66
|
+
|
67
|
+
### Durable
|
68
|
+
|
69
|
+
Messages in HornetQ can be marked as durable which means they will be persisted
|
70
|
+
to disk to prevent message loss in the event of a power failure or other system
|
71
|
+
failure. This does however mean that every durable message does incur the
|
72
|
+
overhead of a disk write every time it is read or written (produced or consumed).
|
73
|
+
|
74
|
+
### Broker
|
75
|
+
|
76
|
+
HornetQ is a broker based architecture which requires the use of one or more
|
77
|
+
centralized brokers. A broker is much like the "server" through which all
|
78
|
+
messages pass through.
|
79
|
+
|
80
|
+
An in-vm broker can be used for passing messages around within a Java
|
81
|
+
Virtual Machine (JVM) instance without making network calls. Highly recommended
|
82
|
+
for passing messages between threads in the same JVM.
|
83
|
+
|
84
|
+
### Consumer
|
85
|
+
|
86
|
+
### Producer
|
87
|
+
|
88
|
+
### Asynchronous Messaging
|
89
|
+
|
90
|
+
It is recommended to keep the state of the message flow in the message itself.
|
91
|
+
|
92
|
+
### Synchronous Messaging
|
93
|
+
|
94
|
+
### Messaging Patterns
|
95
|
+
|
96
|
+
### Message Priority
|
97
|
+
|
98
|
+
|
99
|
+
Overview
|
100
|
+
--------
|
101
|
+
|
102
|
+
jruby-hornetq is primarily intended to make it easy to use the HornetQ client
|
103
|
+
core API. It also supports running the HornetQ broker for scenarios such as
|
104
|
+
in-vm messaging.
|
105
|
+
|
106
|
+
The examples below address some of the messaging patterns that are used in
|
107
|
+
messaging and queuing.
|
108
|
+
|
109
|
+
Producer-Consumer
|
110
|
+
-----------------
|
111
|
+
|
112
|
+
Producer: Write messages to a queue:
|
113
|
+
|
114
|
+
....
|
115
|
+
|
116
|
+
Consumer: Read message from a queue:
|
117
|
+
....
|
118
|
+
|
119
|
+
Client-Server
|
120
|
+
-------------
|
121
|
+
|
122
|
+
|
123
|
+
Threading
|
124
|
+
---------
|
125
|
+
|
126
|
+
A factory instance can be shared between threads, whereas a session and any
|
127
|
+
artifacts created by the session should only be used by one thread at a time.
|
128
|
+
|
129
|
+
For consumers, it is recommended to create a session for each thread and leave
|
130
|
+
that thread blocked on ClientConsumer::receive
|
131
|
+
A timeout can be used if the thread needs to do any other work. At this time
|
132
|
+
it is Not recommended to use ClientConsumer::receive_immediate across
|
133
|
+
multiple threads due to known issues in HornetQ with this API.
|
134
|
+
|
135
|
+
### Example
|
136
|
+
|
137
|
+
Logging
|
138
|
+
-------
|
139
|
+
|
140
|
+
Dependencies
|
141
|
+
------------
|
142
|
+
|
143
|
+
### JRuby
|
144
|
+
|
145
|
+
jruby-hornetq has been tested against JRuby 1.5.1, but should work with any
|
146
|
+
current JRuby version.
|
147
|
+
|
148
|
+
### HornetQ
|
149
|
+
|
150
|
+
The libraries required for the HornetQ Client and to start a simple Core API
|
151
|
+
only Broker are included with the Gem.
|
152
|
+
|
153
|
+
### GenePool
|
154
|
+
|
155
|
+
GenePool is used to implement session pooling
|
156
|
+
|
157
|
+
Running the Broker
|
158
|
+
------------------
|
159
|
+
|
160
|
+
Not only does jruby-hornetq make it easy to work with HornetQ from JRuby as a
|
161
|
+
client, it also supports using JRuby to launch a Broker instance
|
162
|
+
|
163
|
+
### Example Usage
|
164
|
+
|
165
|
+
#### Starting up a standalone hornetq server:
|
166
|
+
|
167
|
+
bin/hornetq_server examples/standalone_server.yml
|
168
|
+
|
169
|
+
#### Starting up a backup/live combination
|
170
|
+
|
171
|
+
bin/hornetq_server examples/backup_server.yml
|
172
|
+
bin/hornetq_server examples/live_server.yml
|
173
|
+
|
174
|
+
Development
|
175
|
+
-----------
|
176
|
+
|
177
|
+
Want to contribute to jruby-hornetq?
|
178
|
+
|
179
|
+
First clone the repo and run the tests:
|
180
|
+
|
181
|
+
git clone git://github.com/reidmorrison/jruby-hornetq.git
|
182
|
+
cd jruby-hornetq
|
183
|
+
jruby -S rake test
|
184
|
+
|
185
|
+
Feel free to ping the mailing list with any issues and we'll try to resolve it.
|
186
|
+
|
187
|
+
|
188
|
+
Contributing
|
189
|
+
------------
|
190
|
+
|
191
|
+
Once you've made your great commits:
|
192
|
+
|
193
|
+
1. [Fork][1] Resque
|
194
|
+
2. Create a topic branch - `git checkout -b my_branch`
|
195
|
+
3. Push to your branch - `git push origin my_branch`
|
196
|
+
4. Create an [Issue][2] with a link to your branch
|
197
|
+
5. That's it!
|
198
|
+
|
199
|
+
You might want to checkout our [Contributing][cb] wiki page for information
|
200
|
+
on coding standards, new features, etc.
|
201
|
+
|
202
|
+
|
203
|
+
Mailing List
|
204
|
+
------------
|
205
|
+
|
206
|
+
TBA
|
207
|
+
|
208
|
+
Meta
|
209
|
+
----
|
210
|
+
|
211
|
+
* Code: `git clone git://github.com/reidmorrison/jruby-hornetq.git`
|
212
|
+
* Home: <http://github.com/reidmorrison/jruby-hornetq>
|
213
|
+
* Docs: <http://jruby-hornetq.github.com/jruby-hornetq/>
|
214
|
+
* Bugs: <http://github.com/reidmorrison/jruby-hornetq/issues>
|
215
|
+
* List: TBA
|
216
|
+
* Gems: <http://gemcutter.org/gems/jruby-hornetq>
|
217
|
+
|
218
|
+
This project uses [Semantic Versioning][sv].
|
219
|
+
|
220
|
+
|
221
|
+
Authors
|
222
|
+
-------
|
223
|
+
|
224
|
+
Reid Morrison :: rubywmq@gmail.com :: @reidmorrison
|
225
|
+
Brad Pardee :: bpardee@gmail.com
|
226
|
+
|
227
|
+
[1]: http://help.github.com/forking/
|
228
|
+
[2]: http://github.com/reidmorrison/jruby-hornetq/issues
|
229
|
+
[sv]: http://semver.org/
|
230
|
+
|
231
|
+
License
|
232
|
+
-------
|
233
|
+
|
234
|
+
Copyright 2011 Clarity Services, Inc.
|
235
|
+
|
236
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
237
|
+
you may not use this file except in compliance with the License.
|
238
|
+
You may obtain a copy of the License at
|
239
|
+
|
240
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
241
|
+
|
242
|
+
Unless required by applicable law or agreed to in writing, software
|
243
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
244
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
245
|
+
See the License for the specific language governing permissions and
|
246
|
+
limitations under the License.
|
247
|
+
|
248
|
+
jruby-hornetq includes files from HornetQ, which is also licensed under
|
249
|
+
the Apache License, Version 2.0: http://www.jboss.org/hornetq
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
raise "jruby-hornetq must be built with JRuby: try again with `jruby -S rake'" unless defined?(JRUBY_VERSION)
|
2
|
+
|
3
|
+
require 'rake/clean'
|
4
|
+
require 'date'
|
5
|
+
require 'java'
|
6
|
+
|
7
|
+
desc "Build gem"
|
8
|
+
task :gem do |t|
|
9
|
+
gemspec = Gem::Specification.new do |s|
|
10
|
+
s.name = 'jruby-hornetq'
|
11
|
+
s.version = '0.2.0.alpha'
|
12
|
+
s.author = 'Reid Morrison'
|
13
|
+
s.email = 'rubywmq@gmail.com'
|
14
|
+
s.homepage = 'http://www.reidmorrison.com/'
|
15
|
+
s.date = Date.today.to_s
|
16
|
+
s.description = 'JRuby-HornetQ is a Java and Ruby library that exposes the HornetQ Java API in a ruby friendly way. For JRuby only.'
|
17
|
+
s.summary = 'JRuby interface into HornetQ'
|
18
|
+
s.files = FileList["./**/*"].exclude('*.gem', './nbproject/*').map{|f| f.sub(/^\.\//, '')}
|
19
|
+
s.has_rdoc = true
|
20
|
+
s.add_dependency "gene_pool", "~> 1.1.1"
|
21
|
+
end
|
22
|
+
Gem::Builder.new(gemspec).build
|
23
|
+
end
|
data/bin/hornetq_server
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
#!/usr/bin/env jruby
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
raise 'Environment variable HORNETQ_HOME not set' unless ENV['HORNETQ_HOME']
|
6
|
+
require "#{ENV['HORNETQ_HOME']}/lib/hornetq-core.jar"
|
7
|
+
require "#{ENV['HORNETQ_HOME']}/lib/netty.jar"
|
8
|
+
|
9
|
+
unless ARGV[0]
|
10
|
+
$stderr.puts "Usage: hornetq_server <yml-file>"
|
11
|
+
exit 1
|
12
|
+
end
|
13
|
+
yaml = YAML.load_file(ARGV[0])
|
14
|
+
data_directory = yaml['data_directory'] || './data'
|
15
|
+
host = yaml['host'] || 'localhost'
|
16
|
+
port = yaml['port'] || 5445
|
17
|
+
|
18
|
+
config = Java::org.hornetq.core.config.impl.ConfigurationImpl.new
|
19
|
+
config.persistence_enabled = false
|
20
|
+
config.security_enabled = false
|
21
|
+
config.paging_directory = "#{data_directory}/paging"
|
22
|
+
config.bindings_directory = "#{data_directory}/bindings"
|
23
|
+
config.journal_directory = "#{data_directory}/journal"
|
24
|
+
config.journal_min_files = 10
|
25
|
+
config.large_messages_directory = "#{data_directory}/large-messages"
|
26
|
+
|
27
|
+
if Java::org.hornetq.core.journal.impl.AIOSequentialFileFactory.isSupported
|
28
|
+
config.journal_type = Java::org.hornetq.core.server.JournalType::ASYNCIO
|
29
|
+
else
|
30
|
+
puts("AIO wasn't located on this platform, it will fall back to using pure Java NIO. If your platform is Linux, install LibAIO to enable the AIO journal");
|
31
|
+
config.journal_type = Java::org.hornetq.core.server.JournalType::NIO
|
32
|
+
end
|
33
|
+
|
34
|
+
netty_acceptor_class_name = Java::org.hornetq.core.remoting.impl.netty.NettyAcceptorFactory.java_class.name
|
35
|
+
netty_connector_class_name = Java::org.hornetq.core.remoting.impl.netty.NettyConnectorFactory.java_class.name
|
36
|
+
|
37
|
+
transport_conf_params = java.util.HashMap.new
|
38
|
+
transport_conf_params.put('host', host)
|
39
|
+
transport_conf_params.put('port', java.lang.Integer.new(port))
|
40
|
+
transport_conf = Java::org.hornetq.api.core.TransportConfiguration.new(netty_acceptor_class_name, transport_conf_params);
|
41
|
+
|
42
|
+
transport_conf_set = java.util.HashSet.new
|
43
|
+
transport_conf_set.add(transport_conf)
|
44
|
+
|
45
|
+
config.acceptor_configurations = transport_conf_set
|
46
|
+
|
47
|
+
if yaml['backup']
|
48
|
+
puts "backup"
|
49
|
+
config.backup = true
|
50
|
+
config.shared_store = false
|
51
|
+
elsif yaml['backup_host']
|
52
|
+
puts "live"
|
53
|
+
backup_params = java.util.HashMap.new
|
54
|
+
backup_params.put('host', yaml['backup_host'])
|
55
|
+
backup_port = yaml['backup_port'] || 5445
|
56
|
+
backup_params.put('port', java.lang.Integer.new(backup_port))
|
57
|
+
#backup_params.put('reconnectAttempts', -1)
|
58
|
+
backup_connector_conf = Java::org.hornetq.api.core.TransportConfiguration.new(netty_connector_class_name, backup_params);
|
59
|
+
|
60
|
+
connector_conf_map = java.util.HashMap.new
|
61
|
+
connector_conf_map.put('backup-connector', backup_connector_conf)
|
62
|
+
|
63
|
+
config.connector_configurations = connector_conf_map
|
64
|
+
config.backup_connector_name = 'backup-connector'
|
65
|
+
else
|
66
|
+
puts 'standalone'
|
67
|
+
end
|
68
|
+
|
69
|
+
server = Java::org.hornetq.core.server.HornetQServers.newHornetQServer(config)
|
70
|
+
server.start
|
@@ -0,0 +1,124 @@
|
|
1
|
+
#
|
2
|
+
# HornetQ Batch Requestor:
|
3
|
+
# Submit a batch of requests and wait for replies
|
4
|
+
#
|
5
|
+
|
6
|
+
# Allow examples to be run in-place without requiring a gem install
|
7
|
+
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
|
8
|
+
|
9
|
+
require 'rubygems'
|
10
|
+
require 'yaml'
|
11
|
+
require 'hornetq'
|
12
|
+
require 'sync'
|
13
|
+
|
14
|
+
total_count = (ARGV[0] || 100).to_i
|
15
|
+
batching_size = (ARGV[1] || 10).to_i
|
16
|
+
timeout = (ARGV[2] || 10000).to_i
|
17
|
+
request_address = 'jms.queue.ExampleQueue'
|
18
|
+
|
19
|
+
config = YAML.load_file(File.dirname(__FILE__) + '/hornetq.yml')['development']
|
20
|
+
|
21
|
+
class BatchClient
|
22
|
+
def initialize(session, request_address)
|
23
|
+
@producer = session.create_producer(request_address)
|
24
|
+
reply_queue = "#{request_address}.#{Java::java.util::UUID.randomUUID.toString}"
|
25
|
+
begin
|
26
|
+
session.create_temporary_queue(reply_queue, reply_queue)
|
27
|
+
rescue NativeException => exc
|
28
|
+
p exc
|
29
|
+
end
|
30
|
+
@consumer = session.create_consumer(reply_queue)
|
31
|
+
@session = session
|
32
|
+
session.start
|
33
|
+
|
34
|
+
@counter_sync = Sync.new
|
35
|
+
@counter = 0
|
36
|
+
end
|
37
|
+
|
38
|
+
# Increment Message Counter
|
39
|
+
def inc_counter(total_count=1)
|
40
|
+
@counter_sync.synchronize(:EX) { @counter += total_count }
|
41
|
+
end
|
42
|
+
|
43
|
+
# Decrement Message counter
|
44
|
+
def dec_counter(total_count=1)
|
45
|
+
@counter_sync.synchronize(:EX) { @counter -= total_count }
|
46
|
+
end
|
47
|
+
|
48
|
+
# Return the current message count
|
49
|
+
def counter
|
50
|
+
@counter_sync.synchronize(:SH) { @counter }
|
51
|
+
end
|
52
|
+
|
53
|
+
# Send x messages
|
54
|
+
def send(total_count)
|
55
|
+
#print "Sending #{total_count} messages"
|
56
|
+
start_time = Time.now
|
57
|
+
total_count.times do |i|
|
58
|
+
message = @session.create_message(HornetQClient::Message::TEXT_TYPE,false)
|
59
|
+
message.reply_to_queue_name = @consumer.queue_name
|
60
|
+
message << "Request Current Time. #{i}"
|
61
|
+
@producer.send(message)
|
62
|
+
print "."
|
63
|
+
#puts "Sent:#{message}"
|
64
|
+
end
|
65
|
+
duration = Time.now - start_time
|
66
|
+
#printf "\nSend %5d msg, %5.2f s, %10.2f msg/s\n", total_count, duration, total_count/duration
|
67
|
+
end
|
68
|
+
|
69
|
+
# Receive Reply messages
|
70
|
+
def receive
|
71
|
+
print "Receiving messages"
|
72
|
+
begin
|
73
|
+
while reply = @consumer.receive
|
74
|
+
print '@'
|
75
|
+
# puts "Received:#{reply}, [#{reply.body}]"
|
76
|
+
inc_counter(1)
|
77
|
+
reply.acknowledge
|
78
|
+
end
|
79
|
+
rescue Exception => exc
|
80
|
+
p exc
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def close
|
85
|
+
@producer.close
|
86
|
+
@consumer.close
|
87
|
+
@session.delete_queue(@consumer.queue_name)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
# Create a HornetQ session
|
92
|
+
HornetQClient::Factory.create_session(config) do |session|
|
93
|
+
batching_size = total_count if batching_size > total_count
|
94
|
+
|
95
|
+
client = BatchClient.new(session, request_address)
|
96
|
+
|
97
|
+
# Start receive thread
|
98
|
+
receive_thread = Thread.new {client.receive}
|
99
|
+
|
100
|
+
times = (total_count/batching_size).to_i
|
101
|
+
puts "Performing #{times} loops"
|
102
|
+
count = 0
|
103
|
+
times.times do |i|
|
104
|
+
client.send(batching_size)
|
105
|
+
count += batching_size
|
106
|
+
# Wait for at least 80% of responses
|
107
|
+
loop do
|
108
|
+
#puts "Waiting for receive"
|
109
|
+
sleep 0.1
|
110
|
+
received_count = client.counter
|
111
|
+
#puts "\nReceived #{received_count} messages"
|
112
|
+
if received_count >= 0.8 * count
|
113
|
+
puts ""
|
114
|
+
break
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
while client.counter < total_count
|
120
|
+
sleep 0.1
|
121
|
+
print "*"
|
122
|
+
end
|
123
|
+
client.close
|
124
|
+
end
|