Nats Endpoint
Nats Endpoint v0.21.0+ is used to create and start a Nats subscription service. It can subscribe to data on different topics and then route it to different rule chains for processing.
TIP
This component is an extension component and requires the inclusion of an additional extension library: rulego-components (opens new window)
# Type
endpoint/nats
# Startup Configuration
This component allows the reuse of shared connection clients through the server
field. See Component Connection Reuse for reference.
Field | Type | Required | Description | Default Value |
---|---|---|---|---|
server | string | Yes | nats server address | None |
username | string | No | Username | None |
password | string | No | Password | None |
# Response
Before responding with exchange.Out.SetBody
, you need to specify the responseTopic
parameter through exchange.Out.Headers()
or exchange.Out.Msg.Metadata
. The component will then respond with data to the specified topic:
exchange.Out.GetMsg().Metadata.PutValue("responseTopic", "device.msg.response")
// or
exchange.Out.Headers().Add("responseTopic", "device.msg.response")
exchange.Out.SetBody([]byte("ok"))
2
3
4
Response parameter configuration:
Field | Type | Required | Description | Default Value |
---|---|---|---|---|
responseTopic | string | Yes | Response Topic | - |
# Example
Below is an example code using the endpoint: