marples 0.0.22 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +7 -7
- data/lib/marples/client.rb +26 -8
- data/lib/marples/model_action_broadcast.rb +2 -1
- data/lib/marples/version.rb +1 -1
- metadata +8 -8
data/README.md
CHANGED
@@ -19,16 +19,15 @@ go to by enforcing a naming scheme.
|
|
19
19
|
|
20
20
|
### Sending a message
|
21
21
|
|
22
|
-
|
23
|
-
m = Marples::Client.new
|
22
|
+
stomp = Stomp::Client.new ...
|
23
|
+
m = Marples::Client.new transport: stomp, client_name: "publisher"
|
24
24
|
m.updated publication
|
25
25
|
# => /topic/marples.publisher.publications.updated
|
26
|
-
{ 'guide' => { 'id' => 12345, 'title' => '...', ... }}
|
27
26
|
|
28
27
|
### Listening for messages
|
29
28
|
|
30
|
-
|
31
|
-
m = Marples::Client.new
|
29
|
+
stomp = Stomp::Client.new ...
|
30
|
+
m = Marples::Client.new stomp
|
32
31
|
m.when 'publisher', 'publication', 'updated' do |publication|
|
33
32
|
puts publication['slug']
|
34
33
|
# => "how-postcodes-work"
|
@@ -42,9 +41,10 @@ You can inject your logger into Marples to get some debugging information.
|
|
42
41
|
|
43
42
|
logger = Logger.new STDOUT
|
44
43
|
logger.level = Logger::DEBUG
|
45
|
-
producer = Marples::Client.new
|
44
|
+
producer = Marples::Client.new transport: stomp, client_name: "publisher",
|
45
|
+
logger: logger
|
46
46
|
...
|
47
|
-
consumer = Marples::Client.new
|
47
|
+
consumer = Marples::Client.new transport: stomp, logger: logger
|
48
48
|
|
49
49
|
|
50
50
|
## ActiveModel(ish) integration
|
data/lib/marples/client.rb
CHANGED
@@ -1,12 +1,25 @@
|
|
1
1
|
module Marples
|
2
2
|
class Client
|
3
|
-
|
4
|
-
|
3
|
+
[ :transport, :client_name, :logger ].each do |attribute|
|
4
|
+
attr_accessor attribute
|
5
|
+
private "#{attribute}=", attribute
|
6
|
+
end
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
def initialize *args
|
9
|
+
if args[0].kind_of? Hash
|
10
|
+
self.transport = options[:transport]
|
11
|
+
self.client_name = options[:client_name]
|
12
|
+
self.logger = options[:logger]
|
13
|
+
else
|
14
|
+
self.transport = args.shift
|
15
|
+
self.client_name = args.shift
|
16
|
+
self.logger = args.shift
|
17
|
+
logger.warn "Positional arguments to Marples::Client#new are " + \
|
18
|
+
"deprecated and will be removed."
|
19
|
+
end
|
20
|
+
raise "You must provide a transport" if transport.nil?
|
21
|
+
self.logger ||= NullLogger.instance
|
22
|
+
end
|
10
23
|
|
11
24
|
def join
|
12
25
|
logger.debug "Listening on #{transport}"
|
@@ -36,7 +49,12 @@ module Marples
|
|
36
49
|
|
37
50
|
def publish action, object
|
38
51
|
object_type = object.class.name.tableize
|
39
|
-
|
52
|
+
if client_name.nil?
|
53
|
+
logger.fatal "You must provide Marples::Client with a client_name" + \
|
54
|
+
" to publish actions"
|
55
|
+
raise "Provide Marples::Client with a client_name to publish messages"
|
56
|
+
end
|
57
|
+
destination = destination_for client_name, object_type, action
|
40
58
|
logger.debug "Using transport #{transport}"
|
41
59
|
logger.debug "Sending XML to #{destination}"
|
42
60
|
logger.debug "XML: #{object.to_xml}"
|
@@ -45,7 +63,7 @@ module Marples
|
|
45
63
|
end
|
46
64
|
private :publish
|
47
65
|
|
48
|
-
def destination_for application_name
|
66
|
+
def destination_for application_name, object_type, action
|
49
67
|
"/topic/marples.#{application_name}.#{object_type}.#{action}"
|
50
68
|
end
|
51
69
|
private :destination_for
|
@@ -28,7 +28,8 @@ module Marples
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def self.build_marples_client
|
31
|
-
Marples::Client.new
|
31
|
+
Marples::Client.new :transport: marples_transport,
|
32
|
+
client_name: marples_client_name, logger: marples_logger
|
32
33
|
end
|
33
34
|
end
|
34
35
|
end
|
data/lib/marples/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: marples
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2011-11-
|
13
|
+
date: 2011-11-23 00:00:00.000000000Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: pethau
|
17
|
-
requirement: &
|
17
|
+
requirement: &70334323087180 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: 0.0.2
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70334323087180
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: null_logger
|
28
|
-
requirement: &
|
28
|
+
requirement: &70334323086760 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70334323086760
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: activesupport
|
39
|
-
requirement: &
|
39
|
+
requirement: &70334323086300 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,7 +44,7 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :runtime
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *70334323086300
|
48
48
|
description: Message destination arbiter
|
49
49
|
email:
|
50
50
|
- craig@barkingiguana.com
|