euston-rabbitmq 1.0.1-java → 1.0.2-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/Gemfile +2 -0
  2. data/Rakefile +0 -21
  3. data/euston-rabbitmq.gemspec +26 -38
  4. data/lib/euston-rabbitmq/{bindings → euston}/command_handler_binder.rb +2 -2
  5. data/lib/euston-rabbitmq/{errors.rb → euston/errors.rb} +1 -1
  6. data/lib/euston-rabbitmq/{bindings → euston}/event_handler_binder.rb +4 -4
  7. data/lib/euston-rabbitmq/{exchanges.rb → euston/exchanges.rb} +1 -1
  8. data/lib/euston-rabbitmq/{bindings → euston}/handler_binder.rb +2 -1
  9. data/lib/euston-rabbitmq/{queues.rb → euston/queues.rb} +1 -1
  10. data/lib/euston-rabbitmq/{subscriptions/retriable_subscription.rb → euston/retrying_subscription.rb} +17 -16
  11. data/lib/euston-rabbitmq/rabbitmq_client/queue.rb +70 -0
  12. data/lib/euston-rabbitmq/rabbitmq_client/reactive_message.rb +15 -0
  13. data/lib/euston-rabbitmq/{constant_loader.rb → reflection/constant_loader.rb} +0 -0
  14. data/lib/euston-rabbitmq/{handler_finder.rb → reflection/handler_finder.rb} +0 -0
  15. data/lib/euston-rabbitmq/{handler_reference.rb → reflection/handler_reference.rb} +0 -0
  16. data/lib/euston-rabbitmq/version.rb +1 -1
  17. data/lib/euston-rabbitmq.rb +8 -22
  18. data/spec/euston/command_handler_binder_spec.rb +24 -0
  19. data/spec/euston/event_handler_binder_spec.rb +36 -0
  20. data/spec/euston/exchanges_spec.rb +27 -0
  21. data/spec/euston/queues_spec.rb +24 -0
  22. data/spec/euston/retrying_subscription_spec.rb +74 -0
  23. data/spec/rabbitmq_client/queue_spec.rb +69 -0
  24. data/spec/{constant_loader_spec.rb → reflection/constant_loader_spec.rb} +3 -1
  25. data/spec/{handler_finder_spec.rb → reflection/handler_finder_spec.rb} +3 -1
  26. data/spec/spec_helper.rb +19 -52
  27. data/spec/support/filters.rb +10 -0
  28. data/spec/support/queue_subscription_thread_harness.rb +29 -0
  29. data/spec/support/rabbitmqadmin.rb +74 -0
  30. metadata +60 -76
  31. data/Gemfile.lock +0 -76
  32. data/lib/euston-rabbitmq/command_handlers/retry_failed_message.rb +0 -29
  33. data/lib/euston-rabbitmq/event_handlers/message_failure.rb +0 -27
  34. data/lib/euston-rabbitmq/message_buffer.rb +0 -67
  35. data/lib/euston-rabbitmq/message_logger.rb +0 -50
  36. data/lib/euston-rabbitmq/queue.rb +0 -30
  37. data/lib/euston-rabbitmq/read_model/failed_message.rb +0 -36
  38. data/lib/euston-rabbitmq/read_model/message_buffer.rb +0 -57
  39. data/lib/euston-rabbitmq/read_model/message_log.rb +0 -37
  40. data/spec/command_buffer_spec.rb +0 -69
  41. data/spec/event_buffer_spec.rb +0 -69
  42. data/spec/exchange_declaration_spec.rb +0 -28
  43. data/spec/message_failure_spec.rb +0 -77
  44. data/spec/mt_safe_queue_subscription_spec.rb +0 -72
  45. data/spec/safe_queue_subscription_spec.rb +0 -50
  46. data/spec/support/factories.rb +0 -18
@@ -1,72 +0,0 @@
1
- require File.expand_path('../spec_helper.rb', __FILE__)
2
-
3
- if RUBY_PLATFORM == 'java'
4
- require 'spec_helper'
5
-
6
- describe 'message-failure-aware queue subscription' do
7
- include EustonRmqSpec
8
-
9
- PUBLISH_OPTS = { :immediate => false,
10
- :mandatory => true,
11
- :persistent => true,
12
- :routing_key => 'messages.xyz' }
13
-
14
- before :each do
15
- @queue = @exchange = nil
16
- @exchange = @channel.topic "test-#{Euston.uuid.generate}", :durable => true, :nowait => false
17
- @queue = @channel.queue "test-#{Euston.uuid.generate}", :durable => true, :nowait => false
18
-
19
- @queue.bind @exchange, :routing_key => 'messages.#'
20
- @th = Thread.new do
21
- Thread.current[:failed_count] = 0
22
- Thread.current[:succeed_count] = 0
23
-
24
- def on_message_decode_failed(message, error)
25
- Thread.current[:failed_count] += 1
26
- end
27
-
28
- def on_message_failed(message, error, msg)
29
- Thread.current[:failed_count] += 1
30
- end
31
-
32
- def on_message_received(message)
33
- if message[:a] == 'oops'
34
- raise 'Something bad happened'
35
- else
36
- Thread.current[:succeed_count] += 1
37
- end
38
- end
39
-
40
- @queue.when(:message_decode_failed => method(:on_message_decode_failed),
41
- :message_failed => method(:on_message_failed),
42
- :message_received => method(:on_message_received))
43
-
44
- @queue.safe_subscribe
45
- end
46
-
47
- @th.abort_on_exception = true
48
- end
49
-
50
- after :each do
51
- @th.kill
52
- end
53
-
54
- it 'adds a failure-aware subscription function to the amqp queue object' do
55
- @queue.class.should == AMQP::Queue
56
- @queue.should respond_to(:safe_subscribe)
57
-
58
- @exchange.publish ' *897d- -', PUBLISH_OPTS
59
- sleep 0.25
60
- @th[:failed_count].should == 1
61
-
62
- jsn = JSON.generate({ :a => :b })
63
- @exchange.publish jsn, PUBLISH_OPTS
64
- sleep 0.25
65
- @th[:succeed_count].should == 1
66
-
67
- @exchange.publish JSON.generate({ :a => 'oops' }), PUBLISH_OPTS
68
- sleep 0.25
69
- @th[:failed_count].should == 2
70
- end
71
- end
72
- end
@@ -1,50 +0,0 @@
1
- require File.expand_path('../spec_helper.rb', __FILE__)
2
-
3
- unless RUBY_PLATFORM == 'java'
4
- describe 'message-failure-aware queue subscription' do
5
- include EustonRmqSpec
6
-
7
- PUBLISH_OPTS = { :immediate => false,
8
- :mandatory => true,
9
- :persistent => true,
10
- :routing_key => 'messages.xyz' }
11
-
12
- amqp_before do
13
- @exchange = @channel.topic "test-#{Euston.uuid.generate}", :durable => true, :nowait => false
14
- @queue = @channel.queue "test-#{Euston.uuid.generate}", :durable => true, :nowait => false
15
- @queue.bind @exchange, :routing_key => 'messages.#'
16
- @queue.safe_subscribe
17
- end
18
-
19
- it 'adds a failure-aware subscription function to the amqp queue object' do
20
- @queue.should respond_to(:safe_subscribe)
21
-
22
- done 1
23
- end
24
-
25
- it 'publishes the message-decode-failed event when a non-json message is received by the queue' do
26
- count = 0
27
- @queue.when :message_decode_failed => ->(message, error) { count = count + 1 }
28
-
29
- delayed(0.3) { @exchange.publish ' *897d- -', PUBLISH_OPTS }
30
- done(1) { count.should == 1 }
31
- end
32
-
33
- it 'publishes the message-received event when a message is received by the queue' do
34
- count = 0
35
- @queue.when :message_received => ->(message) { count = count + 1 }
36
-
37
- delayed(0.3) { @exchange.publish ::ActiveSupport::JSON.encode({ :a => :b }), PUBLISH_OPTS }
38
- done(1) { count.should == 1 }
39
- end
40
-
41
- it 'publishes the message-failed event when an exception occurs during the message-received handler' do
42
- count = 0
43
- @queue.when(:message_failed => ->(message, error, header) { count = count + 1 },
44
- :message_received => ->(message) { raise 'Something bad happened' })
45
-
46
- delayed(0.3) { @exchange.publish ::ActiveSupport::JSON.encode({ :a => :b }), PUBLISH_OPTS }
47
- done(1) { count.should == 1 }
48
- end
49
- end
50
- end
@@ -1,18 +0,0 @@
1
- module Factory
2
- class << self
3
- def command_headers
4
- {
5
- :id => Euston.uuid.generate,
6
- :type => Faker::Lorem.words(2).join('_'),
7
- :version => 1
8
- }
9
- end
10
-
11
- def command
12
- {
13
- :headers => Factory.command_headers,
14
- :body => Hash[Faker::Lorem.words(3).map { |w| [w.downcase.to_sym, Faker::Lorem.words(3).join(' ')] }]
15
- }
16
- end
17
- end
18
- end