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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a15bccf07520be4677e0bc9522dc5ba3b89d1d4c
4
- data.tar.gz: 0250d8554c15615b054ca7fa0e7cdba6a33ca298
3
+ metadata.gz: 0ecd2146309c4a8507d81bb459f7bee767d41d33
4
+ data.tar.gz: 60d7060c0d9fd30a33ca4190d15f5f82568b2f60
5
5
  SHA512:
6
- metadata.gz: 79d452fea3dff4f7e1334b9ee833de9170e05e37718e6e22f8fe9db5b0a849be8d0ac2bdab31c06831b74566ee76297d4855af02a57d9b1fd177e6ed2613c80f
7
- data.tar.gz: 609308d82ee199756efce1a9f7dc675ed8f8875101ee2c33b2f5297eb3d3cc615669b516f7a853d679d28b3ee2aebf82d6918941e2cbebfb5868dcdfcecdd35c
6
+ metadata.gz: 8a937d878a0e1a2f1c35d8c7d8570573ca6b7ac423ddc3e6a4a6606f95889f9bc1bacd6034ee7ccb4ae9803751e0e1550a09c9467001bf1b763cf9ee616f46dc
7
+ data.tar.gz: 3404d490697c47372068d3013b964704f5f7217e81fa57fc1b16a21f185f64c4ca97b664cadf7ded55f88c5e56f120637ef6ccbb6c2a4eaad3699734f15104e5
data/Gemfile CHANGED
@@ -10,7 +10,4 @@ group :development do
10
10
  gem 'rake'
11
11
  gem 'rspec'
12
12
  gem 'rspec-its'
13
- gem 'pry'
14
- gem 'debugger', :platform => :mri
15
- gem 'debugger-pry', :platform => :mri
16
13
  end
Binary file
@@ -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
- destination = Stapfen::Destination.from_string(destination)
75
- connection.consume(destination.as_kafka, &block)
74
+ connection.consume(destination, &block)
76
75
  end
77
76
 
78
77
  def runloop
@@ -1,3 +1,3 @@
1
1
  module Stapfen
2
- VERSION = '3.0.0'
2
+ VERSION = '3.0.1'
3
3
  end
@@ -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.nil? || @protocol == STOMP
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
- if stomp?
202
+ case protocol
203
+ when STOMP
199
204
  require 'stapfen/client/stomp'
200
205
  stapfen_client = Stapfen::Client::Stomp.new(client_options)
201
- elsif jms?
206
+ when JMS
202
207
  require 'stapfen/client/jms'
203
208
  stapfen_client = Stapfen::Client::JMS.new(client_options)
204
- elsif kafka?
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
@@ -1,3 +1,5 @@
1
+ require 'thread_safe'
2
+
1
3
  begin
2
4
  require 'stomp'
3
5
  rescue LoadError
@@ -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(destination, nil, &b)
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
@@ -6,12 +6,10 @@ require 'rspec/its'
6
6
 
7
7
  is_java = (RUBY_PLATFORM == 'java')
8
8
 
9
- unless is_java
10
- require 'debugger'
11
- require 'debugger/pry'
9
+ if is_java
10
+ require 'hermann/consumer'
12
11
  end
13
12
 
14
-
15
13
  RSpec.configure do |c|
16
14
  c.color = true
17
15
  c.order = "random"
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 'with just a queue name' do
361
- context 'on a failed message' do
362
- it 'should not unreceive' do
363
- stapfen_client.should_receive(:unreceive).never
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
- described_class.consume(client_options) {|msg| true }
374
- described_class.new.run
375
- end
376
- end
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
- let(:raw_headers) { unrec_headers.merge(:other_header => 'foo!') }
386
- let(:client_options) { {:topic => name}.merge(raw_headers) }
387
- let(:config_overrides) { client_options.merge(unrec_headers) }
388
- context 'on a failed message' do
389
- it 'should unreceive' do
390
- stapfen_client.should_receive(:unreceive).once
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
- described_class.consume(config_overrides) {|msg| false }
393
- described_class.new.run
395
+ described_class.consume(client_options) {|msg| true }
396
+ described_class.new.run
397
+ end
394
398
  end
395
- it 'should pass :unreceive_headers through to the unreceive call' do
396
- stapfen_client.should_receive(:unreceive).with(message, config_overrides).once
399
+ end
397
400
 
398
- described_class.consume(config_overrides) {|msg| false }
399
- described_class.new.run
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
- expect(described_class.consumers.last[0][:dead_letter_queue]).to eql unrec_headers[:dead_letter_queue]
406
- expect(described_class.consumers.last[0][:max_redeliveries]).to eql unrec_headers[:max_redeliveries]
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
- end
409
- context 'on a successfully handled message' do
410
- it 'should not unreceive' do
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
- described_class.consume(config_overrides) {|msg| true }
414
- described_class.new.run
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
@@ -17,6 +17,8 @@ Gem::Specification.new do |s|
17
17
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
18
18
  s.require_paths = ["lib"]
19
19
 
20
+ s.add_dependency 'thread_safe'
21
+
20
22
  if RUBY_PLATFORM == "java"
21
23
  s.add_dependency 'hermann', "~> 0.20.0"
22
24
  s.platform = 'java'
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.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-19 00:00:00.000000000 Z
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