cmis_rabbit_queue 0.0.1 → 0.0.2
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/cmis_rabbit_queue.gemspec
CHANGED
@@ -9,11 +9,11 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Nitesh"]
|
10
10
|
spec.email = ["neethiwin@gmail.com"]
|
11
11
|
spec.summary = ""
|
12
|
-
spec.description = ""
|
12
|
+
spec.description = "Wrapper to Rabbit Queue"
|
13
13
|
spec.homepage = ""
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
|
-
spec.files = ["cmis_rabbit_queue.gemspec","lib/cmis_rabbit_queue.rb","lib/cmis_rabbit_queue/document.rb","lib/cmis_rabbit_queue/folder.rb","lib/cmis_rabbit_queue/object.rb","lib/cmis_rabbit_queue/
|
16
|
+
spec.files = ["cmis_rabbit_queue.gemspec","lib/cmis_rabbit_queue.rb","lib/cmis_rabbit_queue/document.rb","lib/cmis_rabbit_queue/folder.rb","lib/cmis_rabbit_queue/object.rb","lib/cmis_rabbit_queue/server.rb","lib/cmis_rabbit_queue/internal/connection.rb"]
|
17
17
|
spec.require_paths = ["lib"]
|
18
18
|
|
19
19
|
spec.add_development_dependency "bundler", "~> 1.7"
|
@@ -1,36 +1,102 @@
|
|
1
|
-
|
2
1
|
require "bunny"
|
2
|
+
require "thread"
|
3
3
|
|
4
4
|
module CmisRabbitQueue
|
5
5
|
class Connection
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
@
|
7
|
+
attr_reader :reply_queue
|
8
|
+
attr_accessor :response, :call_id
|
9
|
+
attr_reader :lock, :condition
|
10
|
+
def initialize(server_queue, url, port)
|
11
|
+
conn = Bunny.new(:automatically_recover => false, :hostname => url, :port => port)
|
12
|
+
conn.start
|
13
|
+
ch = conn.create_channel
|
14
|
+
@ch = ch
|
15
|
+
@x = ch.default_exchange
|
16
|
+
@server_queue = server_queue
|
17
|
+
@reply_queue = ch.queue("", :exclusive => true)
|
18
|
+
|
19
|
+
@lock = Mutex.new
|
20
|
+
@condition = ConditionVariable.new
|
21
|
+
that = self
|
22
|
+
|
23
|
+
@reply_queue.subscribe do |delivery_info, properties, payload|
|
24
|
+
if properties[:correlation_id] == that.call_id
|
25
|
+
that.response = payload
|
26
|
+
that.lock.synchronize{that.condition.signal}
|
27
|
+
end
|
18
28
|
end
|
19
29
|
end
|
20
30
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
31
|
+
def create_folder(folder)
|
32
|
+
self.call_id = self.generate_uuid
|
33
|
+
@x.publish(folder.path,
|
34
|
+
:routing_key => @server_queue,
|
35
|
+
:correlation_id => call_id,
|
36
|
+
:reply_to => @reply_queue.name,
|
37
|
+
:headers => {
|
38
|
+
:operation => 'create_folder',
|
39
|
+
:path => folder.path,
|
40
|
+
:document_type => folder.type,
|
41
|
+
:created_date => folder.created_date,
|
42
|
+
:modified_date => folder.modified_date,
|
43
|
+
:created_by => folder.created_by,
|
44
|
+
:modified_by => folder.modified_by
|
45
|
+
}
|
46
|
+
)
|
47
|
+
lock.synchronize{condition.wait(lock)}
|
48
|
+
response
|
27
49
|
end
|
28
50
|
|
29
|
-
|
51
|
+
def get_folders(folder)
|
52
|
+
self.call_id = self.generate_uuid
|
53
|
+
@x.publish(folder.path,
|
54
|
+
:routing_key => @server_queue,
|
55
|
+
:correlation_id => call_id,
|
56
|
+
:reply_to => @reply_queue.name,
|
57
|
+
:headers => {
|
58
|
+
:operation => 'find_contents',
|
59
|
+
:folder => folder.path,
|
60
|
+
}
|
61
|
+
)
|
62
|
+
lock.synchronize{condition.wait(lock)}
|
63
|
+
response
|
64
|
+
end
|
65
|
+
|
66
|
+
def upload_document(document)
|
67
|
+
self.call_id = self.generate_uuid
|
68
|
+
@x.publish(document.data,
|
69
|
+
:routing_key => @server_queue,
|
70
|
+
:correlation_id => call_id,
|
71
|
+
:reply_to => @reply_queue.name,
|
72
|
+
:content_type => 'multipart/form-data',
|
73
|
+
:headers => {
|
74
|
+
:operation => 'upload_document',
|
75
|
+
:path => document.path,
|
76
|
+
:document_name => document.name,
|
77
|
+
:document_type => document.type,
|
78
|
+
:created_date => document.created_date,
|
79
|
+
:modified_date => document.modified_date,
|
80
|
+
:created_by => document.created_by,
|
81
|
+
:modified_by => document.modified_by,
|
82
|
+
:content_type => document.mime_type
|
83
|
+
}
|
84
|
+
)
|
85
|
+
lock.synchronize{condition.wait(lock)}
|
86
|
+
response
|
87
|
+
end
|
88
|
+
|
89
|
+
protected
|
90
|
+
|
91
|
+
def generate_uuid
|
92
|
+
# very naive but good enough for code
|
93
|
+
# examples
|
94
|
+
"#{rand}#{rand}#{rand}"
|
95
|
+
end
|
30
96
|
|
31
97
|
# This method should be automatically called during garbage collection
|
32
98
|
def self.finalize
|
33
|
-
|
99
|
+
|
34
100
|
end
|
35
101
|
|
36
102
|
end
|
@@ -4,38 +4,30 @@ module CmisRabbitQueue
|
|
4
4
|
|
5
5
|
# The connection
|
6
6
|
attr_reader :connection
|
7
|
-
|
8
|
-
attr_reader :repository
|
9
|
-
attr_reader :repository_name
|
7
|
+
|
10
8
|
# constructor
|
11
|
-
def initialize(url, port, queue
|
12
|
-
@
|
13
|
-
@connection = Connection.new(url, port)
|
14
|
-
init_message_queue(queue)
|
15
|
-
init_repository(repository)
|
9
|
+
def initialize(url, port, queue)
|
10
|
+
@connection = Connection.new(queue,url, port)
|
16
11
|
end
|
17
12
|
|
18
13
|
|
19
14
|
# create folder object with path and other required data
|
20
15
|
def create_folder(folder)
|
21
|
-
@
|
16
|
+
@connection.create_folder(folder)
|
22
17
|
end
|
23
18
|
|
24
19
|
# create documentobject with path and other required data
|
25
20
|
def create_document(document)
|
26
|
-
|
21
|
+
response = @connection.upload_document(document)
|
22
|
+
return response
|
27
23
|
end
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
@connection.init_channel(queue)
|
24
|
+
|
25
|
+
def find_folders(folder)
|
26
|
+
@connection.get_folders(folder)
|
32
27
|
end
|
28
|
+
#Initalize the channel and create queue
|
33
29
|
|
34
30
|
|
35
|
-
#Initalize repository
|
36
|
-
def init_repository(repository)
|
37
|
-
@repository = Repository.new(repository, @connection.queue, @connection.channel, @connection.connection)
|
38
|
-
end
|
39
31
|
|
40
32
|
|
41
33
|
|
data/lib/cmis_rabbit_queue.rb
CHANGED
@@ -3,6 +3,5 @@ require 'require_relative'
|
|
3
3
|
require_relative 'cmis_rabbit_queue/internal/connection'
|
4
4
|
require_relative 'cmis_rabbit_queue/document'
|
5
5
|
require_relative 'cmis_rabbit_queue/folder'
|
6
|
-
require_relative 'cmis_rabbit_queue/repository'
|
7
6
|
require_relative 'cmis_rabbit_queue/server'
|
8
7
|
require_relative 'cmis_rabbit_queue/object'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cmis_rabbit_queue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-10-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
- - ~>
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '10.0'
|
46
|
-
description:
|
46
|
+
description: Wrapper to Rabbit Queue
|
47
47
|
email:
|
48
48
|
- neethiwin@gmail.com
|
49
49
|
executables: []
|
@@ -55,7 +55,6 @@ files:
|
|
55
55
|
- lib/cmis_rabbit_queue/document.rb
|
56
56
|
- lib/cmis_rabbit_queue/folder.rb
|
57
57
|
- lib/cmis_rabbit_queue/object.rb
|
58
|
-
- lib/cmis_rabbit_queue/repository.rb
|
59
58
|
- lib/cmis_rabbit_queue/server.rb
|
60
59
|
- lib/cmis_rabbit_queue/internal/connection.rb
|
61
60
|
homepage: ''
|
@@ -1,56 +0,0 @@
|
|
1
|
-
module CmisRabbitQueue
|
2
|
-
class Repository
|
3
|
-
# repository name
|
4
|
-
attr_reader :name
|
5
|
-
# queue
|
6
|
-
attr_reader :queue
|
7
|
-
#channel
|
8
|
-
attr_reader :channel
|
9
|
-
#connection
|
10
|
-
attr_reader :connection
|
11
|
-
|
12
|
-
def initialize(name, queue, channel, connection)
|
13
|
-
@name = name
|
14
|
-
@queue = queue
|
15
|
-
@channel = channel
|
16
|
-
@connection = connection
|
17
|
-
end
|
18
|
-
|
19
|
-
def create_folder(folder)
|
20
|
-
@channel.default_exchange.publish(
|
21
|
-
folder.name, :routing_key => @queue.name,
|
22
|
-
:headers => {
|
23
|
-
:path => folder.path,
|
24
|
-
:document_type => folder.type,
|
25
|
-
:created_date => folder.created_date,
|
26
|
-
:modified_date => folder.modified_date,
|
27
|
-
:created_by => folder.created_by,
|
28
|
-
:modified_by => folder.modified_by
|
29
|
-
}
|
30
|
-
)
|
31
|
-
end
|
32
|
-
|
33
|
-
def upload_document(document)
|
34
|
-
@channel.default_exchange.publish(
|
35
|
-
document.data, :routing_key => @queue.name,
|
36
|
-
:headers => {
|
37
|
-
:path => document.path,
|
38
|
-
:document_name => document.name,
|
39
|
-
:document_type => document.type,
|
40
|
-
:created_date => document.created_date,
|
41
|
-
:modified_date => document.modified_date,
|
42
|
-
:created_by => document.created_by,
|
43
|
-
:modified_by => document.modified_by,
|
44
|
-
:content_type => document.mime_type
|
45
|
-
}
|
46
|
-
)
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
def get_folders(folder)
|
51
|
-
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|