Skip to content

Script Development / Connector Object DFF.CONN / NSQ

The NSQ Connector operation object mainly provides methods for operating NSQ.

This Connector accesses NSQ Lookupd via the HTTP protocol and publishes messages via the HTTP protocol

The DFF.CONN(...) parameters are as follows:

Parameter Type Required / Default Description
connector_id str Required Connector ID
timeout int/float 10 Default HTTP request timeout of the current operation object, in seconds

.query(...)

Send HTTP requests to NSQ Lookupd with the following parameters:

Parameter Type Required / Default Description
method str Required Request method, such as GET, POST; can also be written as "GET /nodes"
path str None Lookupd request path starting with /; when omitted, it is split from method
query dict None URL query parameters
body str/bytes/dict None Request body
timeout int/float None Timeout for this request; when omitted, the operation object's default value is used
Example
1
result = nsq.query('GET', '/nodes')

Returns the parsed object when the response is JSON or XML, otherwise returns the raw bytes; throws an exception when the HTTP status code is greater than or equal to 400.

.publish(...)

Publish a message with the following parameters:

Parameter Type Required / Default Description
topic str Required Topic
message str/bytes/dict/list/tuple Required Message content; container types are serialized to JSON first
timeout int/float None Timeout for this request; when omitted, the operation object's default value is used
Example
1
result = nsq.publish(topic='events', message={'status': 'ok'})

The Connector randomly selects a node from the producer nodes returned by Lookupd to publish the message, and returns the parsed HTTP response.