Debian Codegraph @

src/modules/dmq/README

raw
1 Distributed Message Queue Module
2
3 Marius Ovidiu Bucur
4
5 Charles Chance
6
7 Sipcentric Ltd.
8
9 Olle E. Johansson
10
11 Edvina AB
12
13 Edited by
14
15 Marius Ovidiu Bucur
16
17 Charles Chance
18
19 Copyright © 2011 Marius Bucur
20
21 Copyright © 2013 Charles Chance, Sipcentric Ltd.
22
23 Copyright © 2015 Olle E. Johansson, Edvina AB
24 __________________________________________________________________
25
26 Table of Contents
27
28 1. Admin Guide
29
30 1. Overview
31
32 1.1. KDMQ Request
33
34 2. Dependencies
35
36 2.1. Kamailio Modules
37 2.2. External Libraries or Applications
38
39 3. Parameters
40
41 3.1. server_address(str)
42 3.2. server_socket(str)
43 3.3. notification_address(str)
44 3.4. notification_channel(str)
45 3.5. multi_notify(int)
46 3.6. num_workers(int)
47 3.7. worker_usleep(int)
48 3.8. ping_interval(int)
49 3.9. remove_inactive(int)
50 3.10. fail_count_enabled(int)
51 3.11. fail_count_threshold_not_active(int)
52 3.12. fail_count_threshold_disabled(int)
53
54 4. Functions
55
56 4.1. dmq_handle_message([continue])
57 4.2. dmq_process_message([continue])
58 4.3. dmq_send_message(channel, node, body, content_type)
59 4.4. dmq_bcast_message(channel, body, content_type)
60 4.5. dmq_t_replicate([skip_loop_test])
61 4.6. dmq_is_from_node()
62
63 5. RPC Commands
64
65 5.1. dmq.list_nodes
66 5.2. dmq.remove
67
68 2. Developer Guide
69
70 1. dmq_load_api(dmq_api_t* api)
71 2. register_dmq_peer(dmq_peer_t* peer)
72 3. bcast_message(dmq_peer_t* peer, str* body, dmq_node_t* except,
73 dmq_resp_cback_t* resp_cback, int max_forwards, str*
74 content_type)
75
76 4. send_message(dmq_peer_t* peer, str* body, dmq_node_t* node,
77 dmq_resp_cback_t* resp_cback, int max_forwards, str*
78 content_type)
79
80 List of Examples
81
82 1.1. KDMQ Request Example
83 1.2. Set server_address parameter
84 1.3. Set server_socket parameter
85 1.4. Set notification_address parameter
86 1.5. Set notification_channel parameter
87 1.6. Set multi_notify parameter
88 1.7. Set num_workers parameter
89 1.8. Set worker_usleep parameter
90 1.9. Set ping_interval parameter
91 1.10. Set remove_inactive parameter
92 1.11. Set fail_count_enabled parameter
93 1.12. Set fail_count_threshold_not_active parameter
94 1.13. Set fail_count_threshold_disabled parameter
95 1.14. dmq_handle_message usage
96 1.15. dmq_process_message usage
97 1.16. dmq_send_message usage
98 1.17. dmq_bcast_message usage
99 1.18. dmq_t_replicate usage
100 1.19. dmq_is_from_node usage
101 1.20. dmq.list_nodes usage
102 1.21. dmq.remove usage
103 2.1. dmq_api_t structure
104 2.2. register_dmq_peer usage
105 2.3. bcast_message usage
106 2.4. send_message usage
107
108 Chapter 1. Admin Guide
109
110 Table of Contents
111
112 1. Overview
113
114 1.1. KDMQ Request
115
116 2. Dependencies
117
118 2.1. Kamailio Modules
119 2.2. External Libraries or Applications
120
121 3. Parameters
122
123 3.1. server_address(str)
124 3.2. server_socket(str)
125 3.3. notification_address(str)
126 3.4. notification_channel(str)
127 3.5. multi_notify(int)
128 3.6. num_workers(int)
129 3.7. worker_usleep(int)
130 3.8. ping_interval(int)
131 3.9. remove_inactive(int)
132 3.10. fail_count_enabled(int)
133 3.11. fail_count_threshold_not_active(int)
134 3.12. fail_count_threshold_disabled(int)
135
136 4. Functions
137
138 4.1. dmq_handle_message([continue])
139 4.2. dmq_process_message([continue])
140 4.3. dmq_send_message(channel, node, body, content_type)
141 4.4. dmq_bcast_message(channel, body, content_type)
142 4.5. dmq_t_replicate([skip_loop_test])
143 4.6. dmq_is_from_node()
144
145 5. RPC Commands
146
147 5.1. dmq.list_nodes
148 5.2. dmq.remove
149
150 1. Overview
151
152 1.1. KDMQ Request
153
154 The DMQ module implements a distributed message queue on top of
155 Kamailio in order to facilitate data propagation and replication
156 between multiple instances, referred as "nodes" (or "peers").
157
158 The DMQ data flow between nodes is grouped in a logical entity referred
159 as "channel" (or "bus"), many flows (channels) can be active at the
160 same time.
161
162 The communication between the nodes is done using SIP messages, after
163 all Kamailio's best ability is routing SIP traffic, therefore reusing
164 the same protocol empowers DMQ cluster with flexible routing policies,
165 advanced authorization and security policies, a.s.o. DMQ sends SIP
166 requests using the KDMQ request method (a custom method type specific
167 to Kamailio, compliant with SIP specifications RFC3261). Data can be
168 sent to all the other active nodes (aka "broadcast") or to a specific
169 single node (aka "unicast").
170
171 The nodes can utilize the DMQ channels to pass messages between them to
172 distribute data for various services (e.g., cached items, location
173 records, active calls, ...). This grouping of messages on channels (per
174 service) is similar to the topic concept in a typical pub/sub system.
175 The channel name appears in the R-URI username part of KDMQ requests.
176
177 The DMQ cluster transparently deals with node discovery, availability,
178 consistency, retransmissions, etc. A new node can join the DMQ cluster
179 by sending an availability notification to an existing node in the
180 clusters. Nodes that are not responding to KDMQ reguests are removed
181 the from local list of active nodes, no longer being considered to be
182 part of the KDMQ cluster.
183
184 IMPORTANT: DMQ must be used only between Kamailio instances having same
185 major version. Internal structures can be incompatible between
186 different major versions and can lead to crashes or unexpected
187 behaviour.
188
189 Possible DMQ node statuses:
190 * DMQ_NODE_ACTIVE "active" = node is in dmq node list and responded
191 with response code 200 OK, to KDMQ message. At startup, all nodes
192 are considered active, regardless of their actual state.
193 * DMQ_NODE_NOT_ACTIVE "not_active" = node is in dmq node list and did
194 not respond to KDMQ message (408 timeout).
195 * DMQ_NODE_DISABLED "disabled" = node will be deleted from dmq node
196 list.
197
198 1.1. KDMQ Request
199
200 KDMQ messages can have different format and content for R-URI username,
201 headers and body, being specific to each component that leverages DMQ
202 to replicate data, such as htable, dialog or usrloc modules.
203
204 Next request is generated by DMQ module for peers availability
205 notifications.
206
207 Example 1.1. KDMQ Request Example
208 ...
209
210 KDMQ sip:[email protected]:5090 SIP/2.0
211 Via: SIP/2.0/UDP 192.168.40.15;branch=z9hG4bK55e5.423d95110000
212 To: <sip:[email protected]:5090>
213 From: <sip:[email protected]:5060>;tag=2cdb7a33a7f21abb98fd3a44968
214 e3ffd-5b01
215 CSeq: 10 KDMQ
216 Call-ID: [email protected]
217 Content-Length: 116
218 User-Agent: kamailio (4.3.0 (x86_64/linneaus))
219 Max-Forwards: 1
220 Content-Type: text/plain
221
222 sip:192.168.40.16:5060;status=active
223 sip:192.168.40.15:5060;status=disabled
224 sip:192.168.40.17:5060;status=not_active
225
226 ...
227
228 2. Dependencies
229
230 2.1. Kamailio Modules
231 2.2. External Libraries or Applications
232
233 2.1. Kamailio Modules
234
235 The following modules must be loaded before this module:
236 * sl.
237 * tm.
238
239 2.2. External Libraries or Applications
240
241 * The DMQ module itself has no external dependencies. However, each
242 peer may need to use its own (de)serialization mechanism, like JSON
243 (via jannson module), XML (via xmlops) or string operations with
244 transformations. .
245
246 3. Parameters
247
248 3.1. server_address(str)
249 3.2. server_socket(str)
250 3.3. notification_address(str)
251 3.4. notification_channel(str)
252 3.5. multi_notify(int)
253 3.6. num_workers(int)
254 3.7. worker_usleep(int)
255 3.8. ping_interval(int)
256 3.9. remove_inactive(int)
257 3.10. fail_count_enabled(int)
258 3.11. fail_count_threshold_not_active(int)
259 3.12. fail_count_threshold_disabled(int)
260
261 3.1. server_address(str)
262
263 The local server address. This is the address with which the local DMQ
264 node joins the servers group to send/receive messages.
265
266 Note: if server_socket is not set, then this address has to match a
267 local socket, which will be used to send/receive messages.
268
269 Default value is “NULL”.
270
271 Example 1.2. Set server_address parameter
272 ...
273 modparam("dmq", "server_address", "sip:10.0.0.20:5060")
274 ...
275 modparam("dmq", "server_address", "sip:10.0.0.20:5061;transport=tls")
276 ...
277
278 3.2. server_socket(str)
279
280 The local listen address. This is the interface over which the DMQ
281 engine will send/receive messages.
282
283 Note: if this parameter is not set, the socket to send/receive messages
284 is built from server_address parameter.
285
286 Default value is “NULL”.
287
288 Example 1.3. Set server_socket parameter
289 ...
290 modparam("dmq", "server_socket", "udp:10.0.0.20:5060")
291 ...
292
293 3.3. notification_address(str)
294
295 The address of another DMQ node from which the local node should
296 retrieve initial information about all other nodes. This parameter can
297 be specified multiple times in the configuration, to configure multiple
298 notification servers. If you configure multiple notification servers,
299 the multi_notify parameter needs to be disabled.
300
301 Default value is “NULL”.
302
303 Example 1.4. Set notification_address parameter
304 ...
305 modparam("dmq", "notification_address", "sip:10.0.0.21:5060")
306 ...
307 modparam("dmq", "notification_address", "sip:10.0.0.21:5061;transport=tls")
308 ...
309
310 3.4. notification_channel(str)
311
312 The name of the channel for notifications about peers availability.
313
314 Default value is “notification_peer”.
315
316 Example 1.5. Set notification_channel parameter
317 ...
318 modparam("dmq", "notification_channel", "peers")
319 ...
320
321 3.5. multi_notify(int)
322
323 Enables the ability to resolve multiple IPv4/IPv6 addresses for a
324 single notification address. Please note that this mode is not
325 supported if you specify multiple notification address parameter.
326
327 A value of zero resolves to the first IP address found. A non-zero
328 value resolves to all IP addresses associated with the host. This
329 includes addresses from DNS SRV records, A and AAAA records.
330
331 Default value is “0”.
332
333 Example 1.6. Set multi_notify parameter
334 ...
335 modparam("dmq", "multi_notify", 1)
336 ...
337
338 3.6. num_workers(int)
339
340 The number of worker threads for sending/receiving messages.
341
342 Default value is “2”.
343
344 Example 1.7. Set num_workers parameter
345 ...
346 modparam("dmq", "num_workers", 4)
347 ...
348
349 3.7. worker_usleep(int)
350
351 The default locking/synchronisation mechanism between producer/consumer
352 threads is the optimum for most environments. On some systems (e.g.
353 FreeBSD) it can cause high CPU load and in such cases, it can be useful
354 to disable locking and switch to polling for tasks at set intervals
355 instead - putting the thread to sleep in-between and taking it out of
356 process during that time.
357
358 A value >0 will disable the default locking and set the polling
359 interval (in microseconds), which can be tuned to suit the specific
360 environment.
361
362 Default value is 0 (recommended for most systems).
363
364 Example 1.8. Set worker_usleep parameter
365 ...
366 modparam("dmq", "worker_usleep", 1000)
367 ...
368
369 3.8. ping_interval(int)
370
371 The number of seconds between node pings (for checking status of other
372 nodes).
373
374 Minimum value is “60” (default).
375
376 Example 1.9. Set ping_interval parameter
377 ...
378 modparam("dmq", "ping_interval", 90)
379 ...
380
381 3.9. remove_inactive(int)
382
383 A value of zero disable removing dmq nodes. Node status will be changed
384 to not_active. A non-zero value (default is 1) enable removing nodes.
385 For node that is defined as notification address status will be changed
386 to not_active. Otherwise it will be marked as disabled and then will be
387 removed.
388
389 Default value is “1”.
390
391 Example 1.10. Set remove_inactive parameter
392 ...
393 modparam("dmq", "remove_inactive", 0)
394 ...
395
396 3.10. fail_count_enabled(int)
397
398 Enable per node counting of failed responses.
399
400 Default value is “0” (disabled).
401
402 Example 1.11. Set fail_count_enabled parameter
403 ...
404 modparam("dmq", "fail_count_enabled", 1)
405 ...
406
407 3.11. fail_count_threshold_not_active(int)
408
409 DMQ node status change from "active" to "not_active" if 408 fail counts
410 are greater than this threshold value: This threshold can be reached
411 both via internal DMQ notification ping mechanism, and other modules
412 that use dmq to broadcast messages:
413 * Fail counts reset every time a node responds with response code 200
414 OK, on response callback of notification ping.
415 * Fail counts increase every time a node responds with response code
416 408, on response callback of notification ping.
417 * Fail counts increase every time a node responds with response code
418 408, on response callback of other modules that use dmq, only if
419 node is in "active" state.
420
421 Default value is “0”. Move node to "not_active" state on first fail.
422
423 Example 1.12. Set fail_count_threshold_not_active parameter
424 ...
425 modparam("dmq", "fail_count_threshold_not_active", 100)
426 ...
427
428 3.12. fail_count_threshold_disabled(int)
429
430 DMQ node status change from "not_active" to "disabled" if 408 fail
431 counts are greater than this threshold value. This threshold can be
432 reached only via internal DMQ notification ping mechanism:
433 * Fail counts reset every time a node responds with response code 200
434 OK, on response callback of notification ping.
435 * Fail counts increase every time a node responds with response code
436 408, on response callback of notification ping.
437
438 Default value is “1”. Move node to "disabled" state on second fail.
439
440 Example 1.13. Set fail_count_threshold_disabled parameter
441 ...
442 modparam("dmq", "fail_count_threshold_disabled", 105)
443 ...
444
445 4. Functions
446
447 4.1. dmq_handle_message([continue])
448 4.2. dmq_process_message([continue])
449 4.3. dmq_send_message(channel, node, body, content_type)
450 4.4. dmq_bcast_message(channel, body, content_type)
451 4.5. dmq_t_replicate([skip_loop_test])
452 4.6. dmq_is_from_node()
453
454 4.1. dmq_handle_message([continue])
455
456 Handles a DMQ message by passing it to the appropriate local peer
457 (module). The peer is identified by the user part of the To header.
458
459 Meaning of parameters:
460 * continue - by default, dmq_handle_message() will end execution of
461 routing script. If this optional parameter is set to "1",
462 dmq_handle_message() will continue executing the routing script
463 after it's been called.
464
465 This function can be used from REQUEST_ROUTE.
466
467 Example 1.14. dmq_handle_message usage
468 ...
469 if(is_method("KDMQ")) {
470 dmq_handle_message();
471 }
472 ...
473
474 4.2. dmq_process_message([continue])
475
476 Similar to dmq_handle_message, but the processing is happening
477 immediately, no longer cloning the request in shared memory to be
478 passed to a DMQ worker process.
479
480 Meaning of parameters:
481 * continue - by default, dmq_process_message() will end execution of
482 routing script by returning 0. If this optional parameter is set to
483 "1", dmq_process_message() will continue executing the routing
484 script after it is been executed, returning 1.
485
486 This function can be used from REQUEST_ROUTE.
487
488 Example 1.15. dmq_process_message usage
489 ...
490 if(is_method("KDMQ")) {
491 dmq_process_message();
492 }
493 ...
494
495 4.3. dmq_send_message(channel, node, body, content_type)
496
497 Sends a DMQ message directly from config file to a single node.
498
499 Meaning of parameters:
500 * channel - name of the channel that should handle the message.
501 * node - the SIP address of the node to which the message should be
502 sent.
503 * body - the message body.
504 * content_type - the MIME type of the message body.
505
506 This function can be used from any route.
507
508 Example 1.16. dmq_send_message usage
509 ...
510 dmq_send_message("channel1", "sip:10.0.0.21:5060", "Message body...", "t
511 ext/plain");
512 ...
513
514 4.4. dmq_bcast_message(channel, body, content_type)
515
516 Broadcasts a DMQ message from config file to all active nodes (except
517 self) on the specific channel.
518
519 Meaning of parameters:
520 * channel - name of the channel that should handle the message.
521 * body - the message body.
522 * content_type - the MIME type of the message body.
523
524 This function can be used from any route.
525
526 Example 1.17. dmq_bcast_message usage
527 ...
528 dmq_bcast_message("channel1", "Message body...", "text/plain");
529 ...
530
531 4.5. dmq_t_replicate([skip_loop_test])
532
533 Replicates the current SIP message to all active nodes (except self).
534 Useful for replicating REGISTER, PUBLISH etc. in a clustered
535 environment.
536
537 Meaning of parameters:
538 * skip_loop_test - by default, DMQ checks the source IP of the
539 message prior to replication, to ensure it has not been sent by
540 another DMQ node (to avoid infinite loops). If this optional
541 parameter is set to "1", the loop test is not performed. This makes
542 sense, from a performance perspective, if you have already
543 performed the necessary checks in the config script (see
544 dmq_is_from_node()).
545
546 This function can be used from REQUEST_ROUTE only.
547
548 Example 1.18. dmq_t_replicate usage
549 ...
550 dmq_t_replicate();
551 ...
552
553 4.6. dmq_is_from_node()
554
555 Checks whether the current message has been sent by another active DMQ
556 node in the cluster.
557
558 This function can be used from REQUEST_ROUTE only.
559
560 Example 1.19. dmq_is_from_node usage
561 ...
562 # basic example for REGISTER replication
563 if(is_method("REGISTER")) {
564 if (dmq_is_from_node()) {
565 # coming from a DMQ node - already authenticated there
566 # now just save contact, etc...
567 } else {
568 # coming from end point - authenticate, save contact, etc...
569 dmq_t_replicate("1"); # source address checked, skip the loop test
570 }
571 }
572 ...
573
574 5. RPC Commands
575
576 5.1. dmq.list_nodes
577 5.2. dmq.remove
578
579 5.1. dmq.list_nodes
580
581 List the DMQ nodes. It has no parameters.
582
583 Example 1.20. dmq.list_nodes usage
584 ...
585 kamctl rpc dmq.list_nodes
586 ...
587
588 5.2. dmq.remove
589
590 Remove a DMQ node by address.
591
592 Parameters:
593 * address - the SIP address of the DMQ node to remove.
594
595 Example 1.21. dmq.remove usage
596 ...
597 kamctl rpc dmq.remove sip:1.2.3.4:5060
598 ...
599
600 Chapter 2. Developer Guide
601
602 Table of Contents
603
604 1. dmq_load_api(dmq_api_t* api)
605 2. register_dmq_peer(dmq_peer_t* peer)
606 3. bcast_message(dmq_peer_t* peer, str* body, dmq_node_t* except,
607 dmq_resp_cback_t* resp_cback, int max_forwards, str*
608 content_type)
609
610 4. send_message(dmq_peer_t* peer, str* body, dmq_node_t* node,
611 dmq_resp_cback_t* resp_cback, int max_forwards, str*
612 content_type)
613
614 The module provides the following functions that can be used in other
615 Kamailio modules.
616
617 1. dmq_load_api(dmq_api_t* api)
618
619 This function binds the DMQ module and fills the structure with the
620 exported functions below.
621
622 Example 2.1. dmq_api_t structure
623 ...
624 typedef struct dmq_api {
625 register_dmq_peer_t register_dmq_peer;
626 bcast_message_t bcast_message;
627 send_message_t send_message;
628 } dmq_api_t;
629 ...
630
631 2. register_dmq_peer(dmq_peer_t* peer)
632
633 Registers an entity as a DMQ peer which permits receiving/sending
634 messages between nodes which support the same peer.
635
636 Example 2.2. register_dmq_peer usage
637 ...
638 Example to follow.
639 ...
640
641 3. bcast_message(dmq_peer_t* peer, str* body, dmq_node_t* except,
642 dmq_resp_cback_t* resp_cback, int max_forwards, str* content_type)
643
644 Broadcast a DMQ message to all nodes in the DMQ bus excluding self,
645 inactive nodes and "except" if specified.
646
647 Example 2.3. bcast_message usage
648 ...
649 Example to follow.
650 ...
651
652 4. send_message(dmq_peer_t* peer, str* body, dmq_node_t* node,
653 dmq_resp_cback_t* resp_cback, int max_forwards, str* content_type)
654
655 Send a DMQ message to a single node.
656
657 Example 2.4. send_message usage
658 ...
659 Example to follow.
660 ...