forked from redpanda-data/connect
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add MQTT configuration for retained, keepalive and last will (redpand…
…a-data#850) * MQTT output can set retained flag. * Support last will and keepalive on MQTT output. * Support last will and keepalive on MQTT input. * fixup! Support last will and keepalive on MQTT output. * fixup! Support last will and keepalive on MQTT input. * Address lint warnings on support for MQTT last will. * Meeting simongottschlag comments on PR redpanda-data#850.
- Loading branch information
Showing
9 changed files
with
234 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Package mqtt contains supporting utils shared between MQTT reader and writer. | ||
package mqttconf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package mqttconf | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/Jeffail/benthos/v3/internal/docs" | ||
) | ||
|
||
// Will holds configuration for the last will message that the broker emits, | ||
// should benthos exit abnormally. | ||
type Will struct { | ||
QoS uint8 `json:"qos" yaml:"qos"` | ||
Retained bool `json:"retained" yaml:"retained"` | ||
Topic string `json:"topic" yaml:"topic"` | ||
Payload string `json:"payload" yaml:"payload"` | ||
} | ||
|
||
// EmptyWill returns an empty will, meaning last will message should not be registered. | ||
func EmptyWill() Will { | ||
return Will{} | ||
} | ||
|
||
// Validate the Will configuration and return nil or error accordingly. | ||
func (w *Will) Validate() error { | ||
if w.Topic == "" { | ||
if w.Payload != "" || w.QoS > 0 || w.Retained { | ||
return errors.New("include topic to register a last will") | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// WillFieldSpec defines a last will message registration. | ||
func WillFieldSpec() docs.FieldSpec { | ||
return docs.FieldAdvanced( | ||
"will", "Set last will message in case of Benthos failure", | ||
).WithChildren( | ||
docs.FieldCommon("qos", "Set QoS for last will message.").HasOptions("0", "1", "2"), | ||
docs.FieldCommon("retained", "Set retained for last will message."), | ||
docs.FieldCommon("topic", "Set topic for last will message."), | ||
docs.FieldCommon("payload", "Set payload for last will message."), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.