em-posixmq 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,38 @@
1
+ require "eventmachine"
2
+ require "posix_mq"
3
+
4
+
5
+ module EventMachine::PosixMQ
6
+
7
+ class Watcher < EM::Connection
8
+ def initialize(posix_mq)
9
+ @posix_mq = posix_mq
10
+ @posix_mq.nonblock = true
11
+ end
12
+
13
+ def notify_readable
14
+ begin
15
+ message, priority = @posix_mq.receive
16
+ receive_message message, priority
17
+ rescue Errno::EAGAIN
18
+ end
19
+ end
20
+
21
+ def receive_message(message, priority)
22
+ end
23
+ end
24
+
25
+ def self.run(posix_mq, handler)
26
+ raise Error, "EventMachine is not running" unless EM.reactor_running?
27
+
28
+ raise Error, "`posix_mq' argument must be a POSIX_MQ instance" unless
29
+ posix_mq.is_a? POSIX_MQ
30
+
31
+ EM.watch posix_mq.to_io, handler, posix_mq do |conn|
32
+ conn.notify_readable = true
33
+ end
34
+
35
+ self
36
+ end
37
+
38
+ end
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require "rubygems"
4
+ require "posix_mq"
5
+ require "securerandom"
6
+
7
+
8
+ posix_mq = POSIX_MQ.new "/my_posix_mq", IO::CREAT | IO::WRONLY | IO::NONBLOCK
9
+
10
+ while true do
11
+ message = SecureRandom.hex 6
12
+ priority = SecureRandom.random_number 9
13
+
14
+ puts "sending message '#{message}' with priority #{priority} to the queue..."
15
+ posix_mq.send message, priority
16
+
17
+ sleep SecureRandom.random_number
18
+ end
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require "rubygems"
4
+ require "em-posixmq"
5
+
6
+
7
+ class MyPosixMQ < EM::PosixMQ::Watcher
8
+ def receive_message(message, priority)
9
+ puts "received message '#{message}' with priority #{priority} from the queue"
10
+ end
11
+ end
12
+
13
+ EM.run do
14
+ posix_mq = POSIX_MQ.new "/my_posix_mq", IO::CREAT | IO::RDONLY | IO::NONBLOCK
15
+ EM::PosixMQ.run posix_mq, MyPosixMQ
16
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: em-posixmq
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - "I\xC3\xB1aki Baz Castillo"
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-02-20 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: eventmachine
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: posix_mq
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :runtime
45
+ version_requirements: *id002
46
+ description: em-posixmq integrates posix_mq Ruby library into the EventMachine reactor allowing asynchronous reading from a POSIX message queue
47
+ email: ibc@aliax.net
48
+ executables: []
49
+
50
+ extensions: []
51
+
52
+ extra_rdoc_files: []
53
+
54
+ files:
55
+ - lib/em-posixmq.rb
56
+ - test/test-em-posixmq-client.rb
57
+ - test/test-em-posixmq-server.rb
58
+ has_rdoc: true
59
+ homepage: https://github.com/ibc/em-posixmq
60
+ licenses: []
61
+
62
+ post_install_message:
63
+ rdoc_options: []
64
+
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ segments:
73
+ - 1
74
+ - 8
75
+ - 7
76
+ version: 1.8.7
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ segments:
83
+ - 0
84
+ version: "0"
85
+ requirements: []
86
+
87
+ rubyforge_project:
88
+ rubygems_version: 1.3.7
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: posix_mq library integrated into EventMachine reactor for asynchronous reading
92
+ test_files: []
93
+