eventhub-processor 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/eventhub-processor.rb +1 -0
- data/lib/eventhub/processor.rb +32 -18
- data/lib/eventhub/version.rb +1 -1
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06a1de3723da25c81697e5925cfd68ab79f9caa0
|
4
|
+
data.tar.gz: 50d6ec8c75afd1f001e41e3d1df67e99ca479efe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c0ee52229f2c725e891ea4d29efaa42b0fccf356c18c053791ed67da28c508e35c7d7db3f44511dff5e86270a0f5db91ab473aec9850e32f98748a63f26f971
|
7
|
+
data.tar.gz: 5fb890baad3bbad02ba3d7cd01d5917bc0b18faf7e4d41964fafd6dfd4764b47e042a315b54dda32e17f9223854f1e7a7ec7318fc8730c3bc54859306b79ed5d
|
data/lib/eventhub-processor.rb
CHANGED
data/lib/eventhub/processor.rb
CHANGED
@@ -41,30 +41,34 @@ module EventHub
|
|
41
41
|
|
42
42
|
begin
|
43
43
|
AMQP.start(configuration.get('server')) do |connection, open_ok|
|
44
|
+
|
45
|
+
@connection = connection
|
44
46
|
|
45
47
|
# deal with tcp connection issues
|
46
|
-
connection.on_tcp_connection_loss do |conn, settings|
|
48
|
+
@connection.on_tcp_connection_loss do |conn, settings|
|
47
49
|
EventHub.logger.warn("Processor lost tcp connection. Trying to restart in 5 seconds...")
|
48
50
|
sleep 5
|
49
51
|
EventMachine.stop
|
50
52
|
end
|
51
53
|
|
52
54
|
# create channel
|
53
|
-
channel = AMQP::Channel.new(connection)
|
54
|
-
channel.auto_recovery = true
|
55
|
+
@channel = AMQP::Channel.new(@connection)
|
56
|
+
@channel.auto_recovery = true
|
55
57
|
|
56
58
|
# connect to queue
|
57
|
-
queue = channel.queue(
|
59
|
+
@queue = @channel.queue(queue_name, durable: true, auto_delete: false)
|
58
60
|
|
59
61
|
# subscribe to queue
|
60
|
-
queue.subscribe do |metadata, payload|
|
62
|
+
@queue.subscribe(:ack => true) do |metadata, payload|
|
61
63
|
handle_heartbeat(payload)
|
62
|
-
handle_message(metadata,payload)
|
64
|
+
if handle_message(metadata,payload)
|
65
|
+
metadata.ack
|
66
|
+
end
|
63
67
|
end
|
64
68
|
|
65
69
|
# Features to stop main event loop
|
66
70
|
stop_main_loop = Proc.new {
|
67
|
-
connection.disconnect {
|
71
|
+
@connection.disconnect {
|
68
72
|
EventHub.logger.info("Processor is stopping main event loop")
|
69
73
|
EventMachine.stop
|
70
74
|
restart = false
|
@@ -79,8 +83,7 @@ module EventHub
|
|
79
83
|
EventHub.logger.info("Processor is listening to queue [#{[configuration.get('server.vhost'),configuration.get('processor.queue')].compact.join(".")}]")
|
80
84
|
end
|
81
85
|
rescue => e
|
82
|
-
EventHub.logger.error("Unexpected exception: #{e}
|
83
|
-
sleep 5
|
86
|
+
EventHub.logger.error("Unexpected exception: #{e}")
|
84
87
|
end
|
85
88
|
|
86
89
|
end # while
|
@@ -123,16 +126,27 @@ module EventHub
|
|
123
126
|
EventMachine.add_timer(watchdog_cycle) { watchdog }
|
124
127
|
end
|
125
128
|
|
126
|
-
def
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
129
|
+
def send_to_dispatcher(payload)
|
130
|
+
confirmed = true
|
131
|
+
|
132
|
+
connection = Bunny.new({hostname: self.hostname, user: self.user, password: self.password, vhost: "event_hub"})
|
133
|
+
connection.start
|
134
|
+
|
135
|
+
channel = connection.create_channel
|
136
|
+
channel.confirm_select
|
137
|
+
|
138
|
+
channel.default_exchange.publish(payload,routing_key: 'inbound', persistent: true)
|
139
|
+
success = channel.wait_for_confirms
|
140
|
+
|
141
|
+
if !success
|
142
|
+
EventHub.logger.error("Message has not been confirmed by the server to be received !!!")
|
143
|
+
confirmed = false
|
144
|
+
end
|
145
|
+
|
146
|
+
channel.close
|
147
|
+
connection.close
|
131
148
|
|
132
|
-
|
133
|
-
|
134
|
-
# send_channel.close
|
135
|
-
# send_conncetion.close
|
149
|
+
confirmed
|
136
150
|
end
|
137
151
|
|
138
152
|
end
|
data/lib/eventhub/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eventhub-processor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Steiner
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bunny
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
description: Gem to build Event Hub processors
|
70
84
|
email:
|
71
85
|
- thomas.steiner@ikey.ch
|