stapfen 3.0.0-java → 3.0.1-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +0 -3
- data/activemq-all-5.8.0.jar +0 -0
- data/lib/stapfen/client/kafka.rb +1 -2
- data/lib/stapfen/version.rb +1 -1
- data/lib/stapfen/worker.rb +13 -6
- data/lib/stapfen.rb +2 -0
- data/spec/client/kafka_spec.rb +1 -5
- data/spec/spec_helper.rb +2 -4
- data/spec/worker_spec.rb +67 -44
- data/stapfen.gemspec +2 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ecd2146309c4a8507d81bb459f7bee767d41d33
|
4
|
+
data.tar.gz: 60d7060c0d9fd30a33ca4190d15f5f82568b2f60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a937d878a0e1a2f1c35d8c7d8570573ca6b7ac423ddc3e6a4a6606f95889f9bc1bacd6034ee7ccb4ae9803751e0e1550a09c9467001bf1b763cf9ee616f46dc
|
7
|
+
data.tar.gz: 3404d490697c47372068d3013b964704f5f7217e81fa57fc1b16a21f185f64c4ca97b664cadf7ded55f88c5e56f120637ef6ccbb6c2a4eaad3699734f15104e5
|
data/Gemfile
CHANGED
Binary file
|
data/lib/stapfen/client/kafka.rb
CHANGED
@@ -71,8 +71,7 @@ module Stapfen
|
|
71
71
|
#
|
72
72
|
# @params [block] block to yield consumed messages
|
73
73
|
def subscribe(destination, headers={}, &block)
|
74
|
-
|
75
|
-
connection.consume(destination.as_kafka, &block)
|
74
|
+
connection.consume(destination, &block)
|
76
75
|
end
|
77
76
|
|
78
77
|
def runloop
|
data/lib/stapfen/version.rb
CHANGED
data/lib/stapfen/worker.rb
CHANGED
@@ -35,7 +35,7 @@ module Stapfen
|
|
35
35
|
unless block_given?
|
36
36
|
raise Stapfen::ConsumeError, "Method `consume` requires a block"
|
37
37
|
end
|
38
|
-
@consumers ||=
|
38
|
+
@consumers ||= ThreadSafe::Array.new
|
39
39
|
@consumers << [config_overrides, consume_block]
|
40
40
|
end
|
41
41
|
|
@@ -96,7 +96,7 @@ module Stapfen
|
|
96
96
|
# functionality if needed. Useful for testing (see worker_spec.rb).
|
97
97
|
def set_class_variable_defaults
|
98
98
|
@@signals_handled = false
|
99
|
-
@@workers =
|
99
|
+
@@workers = ThreadSafe::Array.new
|
100
100
|
end
|
101
101
|
|
102
102
|
end
|
@@ -139,7 +139,7 @@ module Stapfen
|
|
139
139
|
end
|
140
140
|
|
141
141
|
def stomp?
|
142
|
-
@protocol
|
142
|
+
@protocol == STOMP
|
143
143
|
end
|
144
144
|
|
145
145
|
# Force the worker to use JMS as the messaging protocol.
|
@@ -194,16 +194,23 @@ module Stapfen
|
|
194
194
|
@protocol == KAFKA
|
195
195
|
end
|
196
196
|
|
197
|
+
def protocol
|
198
|
+
@protocol ||= KAFKA
|
199
|
+
end
|
200
|
+
|
197
201
|
def run
|
198
|
-
|
202
|
+
case protocol
|
203
|
+
when STOMP
|
199
204
|
require 'stapfen/client/stomp'
|
200
205
|
stapfen_client = Stapfen::Client::Stomp.new(client_options)
|
201
|
-
|
206
|
+
when JMS
|
202
207
|
require 'stapfen/client/jms'
|
203
208
|
stapfen_client = Stapfen::Client::JMS.new(client_options)
|
204
|
-
|
209
|
+
when KAFKA
|
205
210
|
require 'stapfen/client/kafka'
|
206
211
|
stapfen_client = Stapfen::Client::Kafka.new(client_options)
|
212
|
+
else
|
213
|
+
raise 'No client specified'
|
207
214
|
end
|
208
215
|
|
209
216
|
logger.info("Running with #{stapfen_client} inside of Thread:#{Thread.current.inspect}")
|
data/lib/stapfen.rb
CHANGED
data/spec/client/kafka_spec.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'hermann/consumer'
|
3
2
|
require 'stapfen/client/kafka'
|
4
3
|
|
5
4
|
|
@@ -84,15 +83,12 @@ describe Stapfen::Client::Kafka, :java => true do
|
|
84
83
|
|
85
84
|
describe '#subscribe' do
|
86
85
|
let(:topic) { 'topic' }
|
87
|
-
let(:destination) { double('Destination') }
|
88
86
|
let(:msg) { 'foo' }
|
89
87
|
it 'yields to the block and passes in consumed message' do
|
90
|
-
allow(destination).to receive(:as_kafka) { topic }
|
91
|
-
allow(Stapfen::Destination).to receive(:from_string) { destination }
|
92
88
|
allow(consumer).to receive(:consume).with(topic).and_yield(msg)
|
93
89
|
|
94
90
|
expect{ |b|
|
95
|
-
client.subscribe(
|
91
|
+
client.subscribe(topic, nil, &b)
|
96
92
|
}.to yield_with_args(msg)
|
97
93
|
end
|
98
94
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/worker_spec.rb
CHANGED
@@ -4,6 +4,19 @@ require 'stapfen/client/stomp'
|
|
4
4
|
class ExampleWorker < Stapfen::Worker
|
5
5
|
end
|
6
6
|
|
7
|
+
# `exit` is private in 1.9.3 so this is a little hack to add the
|
8
|
+
# namespace for java and make that `exit` method public. Since we use
|
9
|
+
# it in our tests below.
|
10
|
+
module Java
|
11
|
+
module JavaLang
|
12
|
+
class System
|
13
|
+
class << self
|
14
|
+
public :exit
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
7
20
|
describe Stapfen::Worker do
|
8
21
|
|
9
22
|
after(:each) do
|
@@ -79,6 +92,7 @@ describe Stapfen::Worker do
|
|
79
92
|
end
|
80
93
|
|
81
94
|
it 'cleanly exits the worker and java environment' do
|
95
|
+
described_class.const_set(:RUBY_PLATFORM, 'java')
|
82
96
|
described_class.workers << example_worker
|
83
97
|
expect(Java::JavaLang::System).to receive(:exit).with(0)
|
84
98
|
expect(example_worker).to receive(:exit_cleanly)
|
@@ -94,6 +108,7 @@ describe Stapfen::Worker do
|
|
94
108
|
end
|
95
109
|
|
96
110
|
it 'is false if an exception is raised' do
|
111
|
+
described_class.const_set(:RUBY_PLATFORM, 'java')
|
97
112
|
expect(Java::JavaLang::System).to receive(:exit).with(0)
|
98
113
|
described_class.workers << example_worker
|
99
114
|
expect(example_worker).to receive(:exit_cleanly).and_raise(StandardError)
|
@@ -357,61 +372,69 @@ describe Stapfen::Worker do
|
|
357
372
|
described_class.class_variable_set(:@@workers, [])
|
358
373
|
end
|
359
374
|
|
360
|
-
context '
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
described_class.consume(client_options) {|msg| false }
|
366
|
-
described_class.new.run
|
375
|
+
context 'using stomp' do
|
376
|
+
before do
|
377
|
+
described_class.configure do |w|
|
378
|
+
w.use_stomp!
|
367
379
|
end
|
368
380
|
end
|
369
|
-
context 'on a successful message' do
|
370
|
-
it 'should not unreceive' do
|
371
|
-
stapfen_client.should_receive(:unreceive).never
|
372
381
|
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
end
|
378
|
-
|
379
|
-
context 'with a queue name and headers for a dead_letter_queue and max_redeliveries' do
|
380
|
-
let(:unrec_headers) do
|
381
|
-
{ :dead_letter_queue => '/queue/foo',
|
382
|
-
:max_redeliveries => 3 }
|
383
|
-
end
|
382
|
+
context 'with just a queue name' do
|
383
|
+
context 'on a failed message' do
|
384
|
+
it 'should not unreceive' do
|
385
|
+
stapfen_client.should_receive(:unreceive).never
|
384
386
|
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
387
|
+
described_class.consume(client_options) {|msg| false }
|
388
|
+
described_class.new.run
|
389
|
+
end
|
390
|
+
end
|
391
|
+
context 'on a successful message' do
|
392
|
+
it 'should not unreceive' do
|
393
|
+
stapfen_client.should_receive(:unreceive).never
|
391
394
|
|
392
|
-
|
393
|
-
|
395
|
+
described_class.consume(client_options) {|msg| true }
|
396
|
+
described_class.new.run
|
397
|
+
end
|
394
398
|
end
|
395
|
-
|
396
|
-
stapfen_client.should_receive(:unreceive).with(message, config_overrides).once
|
399
|
+
end
|
397
400
|
|
398
|
-
|
399
|
-
|
401
|
+
context 'with a queue name and headers for a dead_letter_queue and max_redeliveries' do
|
402
|
+
let(:unrec_headers) do
|
403
|
+
{ :dead_letter_queue => '/queue/foo',
|
404
|
+
:max_redeliveries => 3 }
|
400
405
|
end
|
401
|
-
it 'should not remove the unreceive headers from the consumer' do
|
402
|
-
described_class.consume(config_overrides) {|msg| false}
|
403
|
-
described_class.new.run
|
404
406
|
|
405
|
-
|
406
|
-
|
407
|
+
let(:raw_headers) { unrec_headers.merge(:other_header => 'foo!') }
|
408
|
+
let(:client_options) { {:topic => name}.merge(raw_headers) }
|
409
|
+
let(:config_overrides) { client_options.merge(unrec_headers) }
|
410
|
+
context 'on a failed message' do
|
411
|
+
it 'should unreceive' do
|
412
|
+
stapfen_client.should_receive(:unreceive).once
|
413
|
+
|
414
|
+
described_class.consume(config_overrides) {|msg| false }
|
415
|
+
described_class.new.run
|
416
|
+
end
|
417
|
+
it 'should pass :unreceive_headers through to the unreceive call' do
|
418
|
+
stapfen_client.should_receive(:unreceive).with(message, config_overrides).once
|
419
|
+
|
420
|
+
described_class.consume(config_overrides) {|msg| false }
|
421
|
+
described_class.new.run
|
422
|
+
end
|
423
|
+
it 'should not remove the unreceive headers from the consumer' do
|
424
|
+
described_class.consume(config_overrides) {|msg| false}
|
425
|
+
described_class.new.run
|
426
|
+
|
427
|
+
expect(described_class.consumers.last[0][:dead_letter_queue]).to eql unrec_headers[:dead_letter_queue]
|
428
|
+
expect(described_class.consumers.last[0][:max_redeliveries]).to eql unrec_headers[:max_redeliveries]
|
429
|
+
end
|
407
430
|
end
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
stapfen_client.should_receive(:unreceive).never
|
431
|
+
context 'on a successfully handled message' do
|
432
|
+
it 'should not unreceive' do
|
433
|
+
stapfen_client.should_receive(:unreceive).never
|
412
434
|
|
413
|
-
|
414
|
-
|
435
|
+
described_class.consume(config_overrides) {|msg| true }
|
436
|
+
described_class.new.run
|
437
|
+
end
|
415
438
|
end
|
416
439
|
end
|
417
440
|
end
|
data/stapfen.gemspec
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stapfen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.1
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- R. Tyler Croy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02
|
11
|
+
date: 2015-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - '>='
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '0'
|
19
|
+
name: thread_safe
|
20
|
+
prerelease: false
|
21
|
+
type: :runtime
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
requirement: !ruby/object:Gem::Requirement
|
15
29
|
requirements:
|
@@ -38,6 +52,7 @@ files:
|
|
38
52
|
- LICENSE.txt
|
39
53
|
- README.md
|
40
54
|
- Rakefile
|
55
|
+
- activemq-all-5.8.0.jar
|
41
56
|
- examples/simple.rb
|
42
57
|
- lib/stapfen.rb
|
43
58
|
- lib/stapfen/client.rb
|