rmq 0.0.6 → 0.0.7

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.
@@ -1,41 +1,41 @@
1
- module RMQ
2
- module MQClient
3
-
4
- class ObjectDescriptor < FFI::Struct
5
- MQOD_STRUC_ID = "OD "
6
- MQOD_VERSION_1 = 1
7
-
8
- # Object Types
9
- MQOT_NONE = 0
10
- MQOT_Q = 1
11
- MQOT_NAMELIST = 2
12
- MQOT_PROCESS = 3
13
- MQOT_STORAGE_CLASS = 4
14
- MQOT_Q_MGR = 5
15
- MQOT_CHANNEL = 6
16
- MQOT_AUTH_INFO = 7
17
- MQOT_TOPIC = 8
18
- MQOT_CF_STRUC = 10
19
- MQOT_LISTENER = 11
20
- MQOT_SERVICE = 12
21
- MQOT_RESERVED_1 = 999
22
-
23
-
24
- layout :StrucId, [:char, 4],
25
- :Version, :long,
26
- :ObjectType, :long,
27
- :ObjectName, [:char, 48],
28
- :ObjectQMgrName, [:char, 48],
29
- :DynamicQName, [:char, 48],
30
- :AlternateUserId, [:char, 12],
31
- :RecsPresent, :long,
32
- :KnownDestCount, :long,
33
- :UnknownDestCount, :long,
34
- :InvalidDestCount, :long,
35
- :ObjectRecOffset, :long,
36
- :ResponseRecOffset, :long,
37
- :ObjectRecPtr, :pointer,
38
- :ResponseRecPtr, :pointer
39
- end
40
- end
41
- end
1
+ module RMQ
2
+ module MQClient
3
+
4
+ class ObjectDescriptor < FFI::Struct
5
+ MQOD_STRUC_ID = "OD "
6
+ MQOD_VERSION_1 = 1
7
+
8
+ # Object Types
9
+ MQOT_NONE = 0
10
+ MQOT_Q = 1
11
+ MQOT_NAMELIST = 2
12
+ MQOT_PROCESS = 3
13
+ MQOT_STORAGE_CLASS = 4
14
+ MQOT_Q_MGR = 5
15
+ MQOT_CHANNEL = 6
16
+ MQOT_AUTH_INFO = 7
17
+ MQOT_TOPIC = 8
18
+ MQOT_CF_STRUC = 10
19
+ MQOT_LISTENER = 11
20
+ MQOT_SERVICE = 12
21
+ MQOT_RESERVED_1 = 999
22
+
23
+
24
+ layout :StrucId, [:char, 4],
25
+ :Version, :long,
26
+ :ObjectType, :long,
27
+ :ObjectName, [:char, 48],
28
+ :ObjectQMgrName, [:char, 48],
29
+ :DynamicQName, [:char, 48],
30
+ :AlternateUserId, [:char, 12],
31
+ :RecsPresent, :long,
32
+ :KnownDestCount, :long,
33
+ :UnknownDestCount, :long,
34
+ :InvalidDestCount, :long,
35
+ :ObjectRecOffset, :long,
36
+ :ResponseRecOffset, :long,
37
+ :ObjectRecPtr, :pointer,
38
+ :ResponseRecPtr, :pointer
39
+ end
40
+ end
41
+ end
@@ -1,31 +1,31 @@
1
- module RMQ
2
- module MQClient
3
-
4
- class PutMessageOptions < FFI::Struct
5
- MQPMO_STRUC_ID = "PMO "
6
- MQPMO_VERSION_1 = 1
7
- MQPMO_SYNCPOINT = 0x00000002
8
-
9
- layout :StrucId, [:char, 4],
10
- :Version, :long,
11
- :Options, :long,
12
- :Timeout, :long,
13
- :Context, :long,
14
- :KnownDestCount, :long,
15
- :UnknownDestCount, :long,
16
- :InvalidDestCount, :long,
17
- :ResolvedQName, [:char, 48],
18
- :ResolvedQMgrName, [:char, 48],
19
- :RecsPresent, :long,
20
- :PutMsgRecFields, :long,
21
- :PutMsgRecOffset, :long,
22
- :ResponseRecOffset, :long,
23
- :PutMsgRecPtr, :pointer,
24
- :ResponseRecPtr, :pointer,
25
- :OriginalMsgHandle, :int64,
26
- :NewMsgHandle, :int64,
27
- :Action, :long,
28
- :PubLevel, :long
29
- end
30
- end
31
- end
1
+ module RMQ
2
+ module MQClient
3
+
4
+ class PutMessageOptions < FFI::Struct
5
+ MQPMO_STRUC_ID = "PMO "
6
+ MQPMO_VERSION_1 = 1
7
+ MQPMO_SYNCPOINT = 0x00000002
8
+
9
+ layout :StrucId, [:char, 4],
10
+ :Version, :long,
11
+ :Options, :long,
12
+ :Timeout, :long,
13
+ :Context, :long,
14
+ :KnownDestCount, :long,
15
+ :UnknownDestCount, :long,
16
+ :InvalidDestCount, :long,
17
+ :ResolvedQName, [:char, 48],
18
+ :ResolvedQMgrName, [:char, 48],
19
+ :RecsPresent, :long,
20
+ :PutMsgRecFields, :long,
21
+ :PutMsgRecOffset, :long,
22
+ :ResponseRecOffset, :long,
23
+ :PutMsgRecPtr, :pointer,
24
+ :ResponseRecPtr, :pointer,
25
+ :OriginalMsgHandle, :int64,
26
+ :NewMsgHandle, :int64,
27
+ :Action, :long,
28
+ :PubLevel, :long
29
+ end
30
+ end
31
+ end
@@ -1,55 +1,55 @@
1
- module RMQ
2
- class Queue
3
- include MQClient
4
-
5
- # TODO add some caching for the queue handle
6
-
7
- def initialize(queue_manager, name)
8
- @queue_manager = queue_manager
9
- @queue_name = name
10
- end
11
-
12
- # Puts a message onto the queue. A reply to queue name can be specified.
13
- def put_message(payload, reply_queue_name = "")
14
- @queue_handle = open_queue(@queue_manager.connection_handle, @queue_name, Constants::MQOO_OUTPUT) if @queue_handle.nil?
15
-
16
- put_message_on_queue(@queue_manager.connection_handle, @queue_handle, payload, reply_queue_name)
17
-
18
- close_queue(@queue_manager.connection_handle, @queue_handle, Constants::MQCO_NONE)
19
- @queue_handle = nil
20
- end
21
-
22
- def depth
23
- queue_depth(@queue_manager.connection_handle, @queue_name)
24
- end
25
-
26
- # Gets a message from the queue. A timeout period can be specified in seconds.
27
- def get_message(timeout = 0)
28
- @queue_handle = open_queue(@queue_manager.connection_handle, @queue_name, Constants::MQOO_INPUT_SHARED) if @queue_handle.nil?
29
-
30
- if (timeout > 0)
31
- begin_time = Time.now.to_i
32
- begin
33
- message = get_message_from_queue(@queue_manager.connection_handle, @queue_handle, timeout)
34
- rescue RMQException
35
- end_time = Time.now.to_i
36
- raise RMQTimeOutError.new if end_time - begin_time >= timeout
37
- end
38
- else
39
- message = get_message_from_queue(@queue_manager.connection_handle, @queue_handle, 0)
40
- end
41
-
42
- close_queue(@queue_manager.connection_handle, @queue_handle, Constants::MQCO_NONE)
43
- @queue_handle = nil
44
-
45
- message
46
- end
47
-
48
- # Gets a message from the queue and returns the payload only. A timeout period can be specified
49
- # in seconds.
50
- def get_message_payload(timeout = 0)
51
- message = get_message(timeout)
52
- message.payload
53
- end
54
- end
1
+ module RMQ
2
+ class Queue
3
+ include MQClient
4
+
5
+ # TODO add some caching for the queue handle
6
+
7
+ def initialize(queue_manager, name)
8
+ @queue_manager = queue_manager
9
+ @queue_name = name
10
+ end
11
+
12
+ # Puts a message onto the queue. A reply to queue name can be specified.
13
+ def put_message(payload, reply_queue_name = "")
14
+ @queue_handle = open_queue(@queue_manager.connection_handle, @queue_name, Constants::MQOO_OUTPUT) if @queue_handle.nil?
15
+
16
+ put_message_on_queue(@queue_manager.connection_handle, @queue_handle, payload, reply_queue_name)
17
+
18
+ close_queue(@queue_manager.connection_handle, @queue_handle, Constants::MQCO_NONE)
19
+ @queue_handle = nil
20
+ end
21
+
22
+ def depth
23
+ queue_depth(@queue_manager.connection_handle, @queue_name)
24
+ end
25
+
26
+ # Gets a message from the queue. A timeout period can be specified in seconds.
27
+ def get_message(timeout = 0)
28
+ @queue_handle = open_queue(@queue_manager.connection_handle, @queue_name, Constants::MQOO_INPUT_SHARED) if @queue_handle.nil?
29
+
30
+ if (timeout > 0)
31
+ begin_time = Time.now.to_i
32
+ begin
33
+ message = get_message_from_queue(@queue_manager.connection_handle, @queue_handle, timeout)
34
+ rescue RMQException
35
+ end_time = Time.now.to_i
36
+ raise RMQTimeOutError.new if end_time - begin_time >= timeout
37
+ end
38
+ else
39
+ message = get_message_from_queue(@queue_manager.connection_handle, @queue_handle, 0)
40
+ end
41
+
42
+ close_queue(@queue_manager.connection_handle, @queue_handle, Constants::MQCO_NONE)
43
+ @queue_handle = nil
44
+
45
+ message
46
+ end
47
+
48
+ # Gets a message from the queue and returns the payload only. A timeout period can be specified
49
+ # in seconds.
50
+ def get_message_payload(timeout = 0)
51
+ message = get_message(timeout)
52
+ message.payload
53
+ end
54
+ end
55
55
  end
@@ -1,107 +1,107 @@
1
- require 'rmq/mqclient'
2
-
3
- module RMQ
4
- class QueueManager
5
- include MQClient
6
- include Constants
7
-
8
- attr_reader :connection_handle
9
-
10
- def self.connect(queue_manager)
11
- qm = QueueManager.new(queue_manager)
12
- qm.connect
13
-
14
- qm
15
- end
16
-
17
- def initialize(queue_manager)
18
- @queue_manager = queue_manager
19
- end
20
-
21
- def connect
22
- raise "Please set MQSERVER environment variable before trying to connect to a queue manager" if ENV['MQSERVER'].empty?
23
-
24
- hconn_ptr = FFI::MemoryPointer.new :long
25
- completion_code_ptr = FFI::MemoryPointer.new :long
26
- reason_code_ptr = FFI::MemoryPointer.new :long
27
-
28
- MQClient.mqconn(@queue_manager, hconn_ptr, completion_code_ptr, reason_code_ptr)
29
-
30
- @connection_handle = hconn_ptr.read_long
31
-
32
- unless completion_code_ptr.read_long == MQCC_OK
33
- raise RMQException.new(completion_code_ptr.read_long, reason_code_ptr.read_long), "Cannot connect to queue manager #{@queue_manager}"
34
- end
35
- end
36
-
37
- def disconnect
38
- completion_code_ptr = FFI::MemoryPointer.new :long
39
- reason_code_ptr = FFI::MemoryPointer.new :long
40
- hconn_ptr = FFI::MemoryPointer.new :long
41
-
42
- hconn_ptr.write_long @connection_handle
43
- MQClient.mqdisc(hconn_ptr, completion_code_ptr, reason_code_ptr)
44
-
45
- unless completion_code_ptr.read_long == MQCC_OK
46
- raise RMQException.new(completion_code_ptr.read_long, reason_code_ptr.read_long), "Cannot disconnect from queue manager #{@queue_manager}"
47
- end
48
- end
49
-
50
- def find_queue(queue_name)
51
- queue_names = []
52
-
53
- adminbag_handle = create_admin_bag
54
- responsebag_handle = create_response_bag
55
- add_string_to_bag(adminbag_handle, MQCA_Q_NAME, "*")
56
- add_integer_to_bag(adminbag_handle, MQIA_Q_TYPE, MQQT_LOCAL)
57
- add_inquiry(adminbag_handle, MQIA_CURRENT_Q_DEPTH)
58
-
59
- execute(@connection_handle, MQCMD_INQUIRE_Q, MQHB_NONE, adminbag_handle, responsebag_handle, MQHO_NONE, MQHO_NONE)
60
-
61
- number_of_bags = count_items(responsebag_handle, MQHA_BAG_HANDLE)
62
-
63
- for bag_number in (0..number_of_bags - 1)
64
- attributes_bag_handle = inquire_bag(responsebag_handle, MQHA_BAG_HANDLE, bag_number)
65
- queue_names.push inquire_string(attributes_bag_handle, MQCA_Q_NAME, 0)
66
- end
67
-
68
- delete_bag(adminbag_handle)
69
- delete_bag(responsebag_handle)
70
-
71
- if queue_names.include?(queue_name)
72
- RMQ::Queue.new(self, queue_name)
73
- else
74
- nil
75
- end
76
- end
77
-
78
- def create_queue(queue_name)
79
- adminbag_handle = create_admin_bag
80
- responsebag_handle = create_response_bag
81
- add_string_to_bag(adminbag_handle, MQCA_Q_NAME, queue_name)
82
- add_integer_to_bag(adminbag_handle, MQIA_Q_TYPE, MQQT_LOCAL)
83
- execute(@connection_handle, MQCMD_CREATE_Q, MQHB_NONE, adminbag_handle, responsebag_handle, MQHO_NONE, MQHO_NONE)
84
-
85
- delete_bag(adminbag_handle)
86
- delete_bag(responsebag_handle)
87
-
88
- RMQ::Queue.new(self, queue_name)
89
- end
90
-
91
- def delete_queue(queue_name, purge = true)
92
- adminbag_handle = create_admin_bag
93
- responsebag_handle = create_response_bag
94
- add_string_to_bag(adminbag_handle, MQCA_Q_NAME, queue_name)
95
-
96
- if purge # delete queue regardless of messages in it
97
- add_integer_to_bag(adminbag_handle, MQIACF_PURGE, MQPO_YES)
98
- end
99
-
100
- execute(@connection_handle, MQCMD_DELETE_Q, MQHB_NONE, adminbag_handle, responsebag_handle, MQHO_NONE, MQHO_NONE)
101
-
102
- delete_bag(adminbag_handle)
103
- delete_bag(responsebag_handle)
104
- end
105
-
106
- end
107
- end
1
+ require 'rmq/mqclient'
2
+
3
+ module RMQ
4
+ class QueueManager
5
+ include MQClient
6
+ include Constants
7
+
8
+ attr_reader :connection_handle
9
+
10
+ def self.connect(queue_manager)
11
+ qm = QueueManager.new(queue_manager)
12
+ qm.connect
13
+
14
+ qm
15
+ end
16
+
17
+ def initialize(queue_manager)
18
+ @queue_manager = queue_manager
19
+ end
20
+
21
+ def connect
22
+ raise "Please set MQSERVER environment variable before trying to connect to a queue manager" if ENV['MQSERVER'].empty?
23
+
24
+ hconn_ptr = FFI::MemoryPointer.new :long
25
+ completion_code_ptr = FFI::MemoryPointer.new :long
26
+ reason_code_ptr = FFI::MemoryPointer.new :long
27
+
28
+ MQClient.mqconn(@queue_manager, hconn_ptr, completion_code_ptr, reason_code_ptr)
29
+
30
+ @connection_handle = hconn_ptr.read_long
31
+
32
+ unless completion_code_ptr.read_long == MQCC_OK
33
+ raise RMQException.new(completion_code_ptr.read_long, reason_code_ptr.read_long), "Cannot connect to queue manager #{@queue_manager}"
34
+ end
35
+ end
36
+
37
+ def disconnect
38
+ completion_code_ptr = FFI::MemoryPointer.new :long
39
+ reason_code_ptr = FFI::MemoryPointer.new :long
40
+ hconn_ptr = FFI::MemoryPointer.new :long
41
+
42
+ hconn_ptr.write_long @connection_handle
43
+ MQClient.mqdisc(hconn_ptr, completion_code_ptr, reason_code_ptr)
44
+
45
+ unless completion_code_ptr.read_long == MQCC_OK
46
+ raise RMQException.new(completion_code_ptr.read_long, reason_code_ptr.read_long), "Cannot disconnect from queue manager #{@queue_manager}"
47
+ end
48
+ end
49
+
50
+ def find_queue(queue_name)
51
+ queue_names = []
52
+
53
+ adminbag_handle = create_admin_bag
54
+ responsebag_handle = create_response_bag
55
+ add_string_to_bag(adminbag_handle, MQCA_Q_NAME, "*")
56
+ add_integer_to_bag(adminbag_handle, MQIA_Q_TYPE, MQQT_LOCAL)
57
+ add_inquiry(adminbag_handle, MQIA_CURRENT_Q_DEPTH)
58
+
59
+ execute(@connection_handle, MQCMD_INQUIRE_Q, MQHB_NONE, adminbag_handle, responsebag_handle, MQHO_NONE, MQHO_NONE)
60
+
61
+ number_of_bags = count_items(responsebag_handle, MQHA_BAG_HANDLE)
62
+
63
+ for bag_number in (0..number_of_bags - 1)
64
+ attributes_bag_handle = inquire_bag(responsebag_handle, MQHA_BAG_HANDLE, bag_number)
65
+ queue_names.push inquire_string(attributes_bag_handle, MQCA_Q_NAME, 0)
66
+ end
67
+
68
+ delete_bag(adminbag_handle)
69
+ delete_bag(responsebag_handle)
70
+
71
+ if queue_names.include?(queue_name)
72
+ RMQ::Queue.new(self, queue_name)
73
+ else
74
+ nil
75
+ end
76
+ end
77
+
78
+ def create_queue(queue_name)
79
+ adminbag_handle = create_admin_bag
80
+ responsebag_handle = create_response_bag
81
+ add_string_to_bag(adminbag_handle, MQCA_Q_NAME, queue_name)
82
+ add_integer_to_bag(adminbag_handle, MQIA_Q_TYPE, MQQT_LOCAL)
83
+ execute(@connection_handle, MQCMD_CREATE_Q, MQHB_NONE, adminbag_handle, responsebag_handle, MQHO_NONE, MQHO_NONE)
84
+
85
+ delete_bag(adminbag_handle)
86
+ delete_bag(responsebag_handle)
87
+
88
+ RMQ::Queue.new(self, queue_name)
89
+ end
90
+
91
+ def delete_queue(queue_name, purge = true)
92
+ adminbag_handle = create_admin_bag
93
+ responsebag_handle = create_response_bag
94
+ add_string_to_bag(adminbag_handle, MQCA_Q_NAME, queue_name)
95
+
96
+ if purge # delete queue regardless of messages in it
97
+ add_integer_to_bag(adminbag_handle, MQIACF_PURGE, MQPO_YES)
98
+ end
99
+
100
+ execute(@connection_handle, MQCMD_DELETE_Q, MQHB_NONE, adminbag_handle, responsebag_handle, MQHO_NONE, MQHO_NONE)
101
+
102
+ delete_bag(adminbag_handle)
103
+ delete_bag(responsebag_handle)
104
+ end
105
+
106
+ end
107
+ end