Table of Contents
List of Examples
lookupd_address
parameterlookupd_port
parameternsqd_address
parameternsqd_port
parameterconsumer_use_nsqd
parameterconsumer_event_key
parameterconsumer_event_subkey
parametermax_in_flight
parameterconsumer_workers
parametertopic_channel
parameterTable of Contents
The module provides an NSQ consumer for Kamailio configuration file. NSQ is a real time distributed messaging platform, more details about it can be found at nsq.io.
From a high-level perspective, the module may be used for:
Provide a real-time integration with you Kamailio configuration file, which can be used as alternative to interact with a database, allowing to overlay additional logic in your preferred language while utilizing a message bus.
Rely on a distributed messaging layer, such that machines processing requests/responses/events can go up/down or share the workload, without impacting Kamailio's activity.
Supported NSQ operations are:
Subscribe to a Topic and Channel
IMPORTANT The `nsq.json` transformation is deprecated in favor of the json module's `json.parse` transformation. The `nsq_pua_publish()` function is deprecated in favor of pua_json module's `pua_json_publish()` function.
The module creates an additional NSQ manager process that does the communication with NSQ for consuming messages. This one defers the message for processing to other NSQ worker process so that it doesn't block itself, nor the SIP worker processes.
The nsqlookupd address.
Usage: nsq related.
Default value is 127.0.0.1
Example 1.1. Set lookupd_address
parameter
... modparam("nsq", "lookupd_address", "nsqlookupd.mydomain.com") ...
The nsqlookupd TCP port.
Usage: nsq related.
Default value is 4161.
The nsqd address. You can specify connecting directly to nsqd instead of using nsqlookupd.
Usage: nsq related.
Default value is 127.0.0.1
Example 1.3. Set nsqd_address
parameter
... modparam("nsq", "nsqd_address", "nsqd.mydomain.com") ...
The nsqd TCP port.
Usage: nsq related.
Default value is 4150.
Set to 1 if you'd like to connect to nsqd instead of nsqlookupd.
Usage: nsq related.
Default value is 0.
The default name of the field in json payload to compose the event name 1st part
Usage: nsq related.
Default value is “Event-Category”.
Example 1.6. Set consumer_event_key
parameter
... modparam("nsq", "consumer_event_key", "My-JSON-Field-Name") ...
The default name of the field in json payload to compose the event name 2nd part
Usage: nsq related.
Default value is “Event-Name”.
Example 1.7. Set consumer_event_subkey
parameter
... modparam("nsq", "consumer_event_subkey", "My-JSON-SubField-Name") ...
The number of messages the consumer can receive before nsqd expects a response.
Usage: nsq related.
Default value is 1.
Number of consumer connections to NSQ per topic_channel.
Usage: nsq related.
Default value is 4.
The NSQ Topic and Channel. Delimiter-separated by “:”. It be set multiple times to subscribe to multiple topics and channels. The value of consumer_workers is allocated per topic_channel.
Usage: nsq related.
Default value is “Kamailio-Topic:Kamailio-Channel”.
Example 1.10. Set topic_channel
parameter
... modparam("nsq", "topic_channel", "My-NSQ-Topic:My-NSQ-Channel") modparam("nsq", "topic_channel", "My-NSQ-Topic-2:My-NSQ-Channel-2") ...
The worker process issues an event-route where we can act on the received payload. The name of the event-route is composed by values extracted from the payload.
NSQ module will try to execute the event route from most significant to less significant. define the event route like event_route[nsq:consumer-event[-payload_key_value[-payload_subkey_value]]]
We can set the key/subkey pair on a subscription base. check the payload on subscribe.
Example 1.12. Define the event routes
... modparam("nsq", "consumer_event_key", "Event-Category") modparam("nsq", "consumer_event_subkey", "Event-Name") ... event_route[nsq:consumer-event-presence-update] { # presence is the value extracted from Event-Category field in json payload # update is the value extracted from Event-Name field in json payload if ($(nsqE{json.parse,Event-Package}) == "dialog") { xlog("L_INFO", "received $(nsqE{json.parse,Event-Package}) update for $(nsqE{json.parse,From})"); pua_json_publish($nsqE); } ... } event_route[nsq:consumer-event-presence] { # presence is the value extracted from Event-Category field in json payload xlog("L_INFO", "received $(nsqE{json.parse,Event-Package}) update for $(nsqE{json.parse,From})"); ... } event_route[nsq:consumer-event-event-category-event-name] { # event-category is the name of the consumer_event_key parameter # event-name is the name of the consumer_event_subkey parameter # this event route is executed if we can't find the previous ... } event_route[nsq:consumer-event-event-category] { # event-category is the name of the consumer_event_key parameter # this event route is executed if we can't find the previous ... } event_route[nsq:consumer-event] { # this event route is executed if we can't find the previous }