seanohalpin-smqueue 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Manifest.txt CHANGED
@@ -3,8 +3,8 @@ Manifest.txt
3
3
  README.txt
4
4
  Rakefile
5
5
  examples/input.rb
6
- examples/message_queue.yml
7
6
  examples/output.rb
7
+ examples/config/example_config.yml
8
8
  lib/rstomp.rb
9
9
  lib/smqueue.rb
10
10
  lib/smqueue/adapters/spread.rb
@@ -0,0 +1,40 @@
1
+ mq: &default_mq
2
+ :adapter: StompAdapter
3
+ # :host: localhost
4
+ :host: 192.168.53.134
5
+ :port: 61613
6
+ :reconnect_delay: 5
7
+
8
+ :announce:
9
+ :adapter: SpreadAdapter
10
+ :channel: 4803@localhost
11
+ :group: announce
12
+
13
+ :scheduler:
14
+ <<: *default_mq
15
+ :name: /queue/development.scheduler
16
+ :reliable: true
17
+
18
+ :change_events:
19
+ <<: *default_mq
20
+ :name: /topic/change_events
21
+ :reliable: true
22
+
23
+ :input:
24
+ <<: *default_mq
25
+ :name: /queue/shared
26
+ :reliable: true
27
+
28
+ :output:
29
+ <<: *default_mq
30
+ :name: /queue/shared
31
+ :reliable: true
32
+
33
+ :readline:
34
+ :adapter: ReadlineAdapter
35
+
36
+ :stdio:
37
+ :adapter: StdioAdapter
38
+
39
+ :error:
40
+ :adapter: NullAdapter
data/examples/input.rb CHANGED
@@ -2,7 +2,8 @@ require 'rubygems'
2
2
  require 'smqueue'
3
3
  require 'pp'
4
4
 
5
- configuration = YAML::load(File.read("message_queue.yml"))
5
+ script_path = File.dirname(__FILE__)
6
+ configuration = YAML::load(File.read(File.join(script_path, "config", "example_config.yml")))
6
7
 
7
8
  input_queue = SMQueue.new(:configuration => configuration[:input])
8
9
 
data/examples/output.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  require 'rubygems'
2
2
  require 'smqueue'
3
3
 
4
- configuration = YAML::load(File.read("message_queue.yml"))
4
+ script_path = File.dirname(__FILE__)
5
+ configuration = YAML::load(File.read(File.join(script_path, "config", "example_config.yml")))
5
6
 
6
7
  input_queue = SMQueue.new(:configuration => configuration[:readline])
7
8
  output_queue = SMQueue.new(:configuration => configuration[:output])
data/lib/rstomp.rb CHANGED
@@ -23,6 +23,29 @@ require 'thread'
23
23
  require 'stringio'
24
24
  require 'logger'
25
25
 
26
+
27
+ # use keepalive to detect dead connections (see http://tldp.org/HOWTO/TCP-Keepalive-HOWTO/)
28
+
29
+ module SocketExtensions
30
+ # Linux
31
+ module Linux
32
+ # /usr/include/netinet/tcp.h
33
+ TCP_KEEPIDLE = 4
34
+ TCP_KEEPINTVL = 5
35
+ TCP_KEEPCNT = 6
36
+ end
37
+ module Darwin
38
+ # Mac OSX
39
+ # tcp.h:#define TCP_KEEPALIVE 0x10 /* idle time used when SO_KEEPALIVE is enabled */
40
+ TCP_KEEPALIVE = 0x10
41
+ # these are sysctl vars
42
+ # /usr/include/netinet/tcp_var.h:#define TCPCTL_KEEPIDLE 6 /* keepalive idle timer */
43
+ # /usr/include/netinet/tcp_var.h:#define TCPCTL_KEEPINTVL 7 /* interval to send keepalives */
44
+ # /usr/include/netinet/tcp_var.h:#define TCPCTL_KEEPINIT 10 /* timeout for establishing syn */ end
45
+ end
46
+ end
47
+
48
+
26
49
  if $DEBUG
27
50
  require 'pp'
28
51
  end
@@ -60,7 +83,7 @@ module RStomp
60
83
  :client_id => nil,
61
84
  :logfile => STDERR,
62
85
  :logger => nil,
63
- }
86
+ }
64
87
 
65
88
  # make them attributes
66
89
  DEFAULT_OPTIONS.each do |key, value|
@@ -123,7 +146,7 @@ module RStomp
123
146
  headers = {
124
147
  :user => @user,
125
148
  :password => @password
126
- }
149
+ }
127
150
  headers['client-id'] = @client_id unless @client_id.nil?
128
151
  # logger.debug "headers = #{headers.inspect} client_id = #{ @client_id }"
129
152
  while s.nil? or @failure != nil
@@ -134,6 +157,59 @@ module RStomp
134
157
 
135
158
  s = TCPSocket.open(@current_host, @current_port)
136
159
 
160
+ # use keepalive to detect dead connections (see http://tldp.org/HOWTO/TCP-Keepalive-HOWTO/)
161
+ s.setsockopt(Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, true)
162
+
163
+ case RUBY_PLATFORM
164
+ when /linux/
165
+ # note: if using OpenSSL, you may need to do this:
166
+ # ssl_socket.to_io.setsockopt(Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, true)
167
+ # see http://www.lerfjhax.com/articles/2006/08/22/ruby-ssl-setsockopt
168
+
169
+ # defaults
170
+ # $ cat /proc/sys/net/ipv4/tcp_keepalive_time
171
+ # 7200
172
+ # $ cat /proc/sys/net/ipv4/tcp_keepalive_intvl
173
+ # 75
174
+ # $ cat /proc/sys/net/ipv4/tcp_keepalive_probes
175
+ # 9
176
+
177
+ # these values should all be configurable (but with sensible defaults)
178
+
179
+ # the interval between the last data packet sent (simple
180
+ # ACKs are not considered data) and the first keepalive
181
+ # probe; after the connection is marked to need
182
+ # keepalive, this counter is not used any further
183
+ s.setsockopt(Socket::IPPROTO_TCP, SocketExtensions::Linux::TCP_KEEPIDLE, 20)
184
+ # the interval between subsequential keepalive probes,
185
+ # regardless of what the connection has exchanged in the
186
+ # meantime
187
+ s.setsockopt(Socket::IPPROTO_TCP, SocketExtensions::Linux::TCP_KEEPINTVL, 10)
188
+ # the number of unacknowledged probes to send before
189
+ # considering the connection dead and notifying the
190
+ # application layer
191
+
192
+ # NOTE: I did not see any effect from setting this
193
+ # option
194
+ s.setsockopt(Socket::IPPROTO_TCP, SocketExtensions::Linux::TCP_KEEPCNT, 6)
195
+ when /darwin/
196
+ # this works, with value = 100 actually takes 12 minutes
197
+ # 55 secs to time out (with opt = 100); with value = 10,
198
+ # takes 685 seconds
199
+
200
+ # ttl = KEEPIDLE + (9 * 75) - cannot change INTVL and
201
+ # CNT per socket on Darwin
202
+
203
+ # set KEEPIDLE time (in seconds) - wait one minute
204
+ # before sending KEEPALIVE packet (for testing - use
205
+ # more realistic figure for real)
206
+ #p [:setting_keepalive]
207
+ opt = [60].pack('l')
208
+ s.setsockopt(Socket::IPPROTO_TCP, SocketExtensions::Darwin::TCP_KEEPALIVE, opt)
209
+ when /jruby/
210
+ else
211
+ end
212
+
137
213
  _transmit(s, "CONNECT", headers)
138
214
  @connect = _receive(s)
139
215
  @open = true
@@ -142,7 +218,7 @@ module RStomp
142
218
  @subscriptions.each { |k, v| _transmit(s, "SUBSCRIBE", v) }
143
219
  rescue Interrupt => e
144
220
  #p [:interrupt, e]
145
- # rescue Exception => e
221
+ # rescue Exception => e
146
222
  rescue RStompException, SystemCallError => e
147
223
  #p [:Exception, e]
148
224
  @failure = e
@@ -287,8 +363,8 @@ module RStomp
287
363
  s = socket
288
364
  rv = _receive(s)
289
365
  return rv
290
- # rescue Interrupt
291
- # raise
366
+ # rescue Interrupt
367
+ # raise
292
368
  rescue RStompException, SystemCallError => e
293
369
  @failure = e
294
370
  handle_error ReceiveError, "receive failed: #{e.message}"
@@ -370,8 +446,8 @@ module RStomp
370
446
  begin
371
447
  _transmit(socket, command, headers, body)
372
448
  return
373
- # rescue Interrupt
374
- # raise
449
+ # rescue Interrupt
450
+ # raise
375
451
  rescue RStompException, SystemCallError => e
376
452
  @failure = e
377
453
  handle_error TransmitError, "transmit '#{command}' failed: #{e.message} (#{body})"
@@ -455,13 +531,13 @@ module RStomp
455
531
  break if message.nil?
456
532
  case message.command
457
533
  when 'MESSAGE':
458
- if listener = @listeners[message.headers['destination']]
459
- listener.call(message)
460
- end
534
+ if listener = @listeners[message.headers['destination']]
535
+ listener.call(message)
536
+ end
461
537
  when 'RECEIPT':
462
- if listener = @receipt_listeners[message.headers['receipt-id']]
463
- listener.call(message)
464
- end
538
+ if listener = @receipt_listeners[message.headers['receipt-id']]
539
+ listener.call(message)
540
+ end
465
541
  end
466
542
  end
467
543
  end
data/lib/smqueue.rb CHANGED
@@ -36,7 +36,7 @@ module SMQueue
36
36
 
37
37
  # Mr Bones project skeleton boilerplate
38
38
  # :stopdoc:
39
- VERSION = '0.1.0'
39
+ VERSION = '0.2.0'
40
40
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
41
41
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
42
42
  # :startdoc:
@@ -201,7 +201,11 @@ end
201
201
  base_path = File.expand_path(File.dirname(path))
202
202
  adapter_path = File.join(base_path, 'smqueue', 'adapters', '*.rb')
203
203
  Dir[adapter_path].each do |file|
204
- require file
204
+ begin
205
+ require file
206
+ rescue Object => e
207
+ warn "warning: could not load adapter '#{file}'. Reason: #{e}"
208
+ end
205
209
  end
206
210
  end
207
211
 
@@ -56,4 +56,5 @@ module SMQueue
56
56
  end
57
57
  end
58
58
  end
59
- end
59
+ ReadLineAdapter = ReadlineAdapter
60
+ end
data/smqueue.gemspec CHANGED
@@ -1,8 +1,8 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "smqueue"
3
- s.version = "0.2.0"
3
+ s.version = "0.2.1"
4
4
  s.summary = "Simple Message Queue"
5
- s.email = 'http://github.com/seanohalpin/smqueue'
5
+ s.email = "seanohalpin@gmail.com"
6
6
  s.homepage = 'http://github.com/seanohalpin/smqueue'
7
7
  s.description = "Implements a simple protocol for using message queues, with adapters
8
8
  for ActiveMQ, Spread and stdio (for testing)."
@@ -14,8 +14,8 @@ Gem::Specification.new do |s|
14
14
  "README.txt",
15
15
  "Rakefile",
16
16
  "examples/input.rb",
17
- "examples/message_queue.yml",
18
17
  "examples/output.rb",
18
+ "examples/config/example_config.yml",
19
19
  "lib/rstomp.rb",
20
20
  "lib/smqueue.rb",
21
21
  "lib/smqueue/adapters/spread.rb",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seanohalpin-smqueue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean O'Halpin
@@ -24,7 +24,7 @@ dependencies:
24
24
  version: 0.1.9
25
25
  version:
26
26
  description: Implements a simple protocol for using message queues, with adapters for ActiveMQ, Spread and stdio (for testing).
27
- email: http://github.com/seanohalpin/smqueue
27
+ email: seanohalpin@gmail.com
28
28
  executables: []
29
29
 
30
30
  extensions: []
@@ -37,8 +37,8 @@ files:
37
37
  - README.txt
38
38
  - Rakefile
39
39
  - examples/input.rb
40
- - examples/message_queue.yml
41
40
  - examples/output.rb
41
+ - examples/config/example_config.yml
42
42
  - lib/rstomp.rb
43
43
  - lib/smqueue.rb
44
44
  - lib/smqueue/adapters/spread.rb
@@ -1,29 +0,0 @@
1
- mq: &default_mq
2
- :adapter: StompAdapter
3
- :host: localhost
4
- :port: 61613
5
- :reconnect_delay: 5
6
-
7
- :input:
8
- <<: *default_mq
9
- :name: /topic/example.queue
10
-
11
- :output:
12
- <<: *default_mq
13
- :name: /topic/example.queue
14
-
15
- :null:
16
- :adapter: NullAdapter
17
-
18
- :stdio:
19
- :adapter: StdioAdapter
20
-
21
- :yaml:
22
- :adapter: YamlAdapter
23
-
24
- :stdio_line:
25
- :adapter: StdioLineAdapter
26
-
27
- :readline:
28
- :adapter: ReadlineAdapter
29
-