-
Notifications
You must be signed in to change notification settings - Fork 69
feat: add MQTT transport messaging #459
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
Signed-off-by: Lance Ball <lball@redhat.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine with me :)
Might want to add some more comments for readability and better IDE devX.
const type = "org.cncf.cloudevents.example"; | ||
const source = "urn:event:from:myapi/resource/123"; | ||
const time = new Date().toISOString(); | ||
const subject = "subject.ext"; | ||
const dataschema = "http://cloudevents.io/schema.json"; | ||
const datacontenttype = "application/json"; | ||
const id = "b46cf653-d48a-4b90-8dfa-355c01061361"; | ||
|
||
interface Idata { | ||
foo: string | ||
} | ||
const data: Idata = { | ||
foo: "bar", | ||
}; | ||
|
||
const ext1Name = "extension1"; | ||
const ext1Value = "foobar"; | ||
const ext2Name = "extension2"; | ||
const ext2Value = "acme"; | ||
|
||
// Binary data as base64 | ||
const dataBinary = Uint32Array.from(JSON.stringify(data), (c) => c.codePointAt(0) as number); | ||
const data_base64 = asBase64(dataBinary); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: it may be better to keep/group related constants in an object rather than having a bunch of individual consts.
Signed-off-by: Lance Ball <lball@redhat.com>
Proposed Changes
Add MQTT as a
Message
format.Description
This commit adds
MQTT
to the supported transport protocols by adding aBinding
and theMQTTMessage<T>
type, extending the baseMessage
type, adding the MQTT fields forpayload
,PUBLISH
andUser Properties
. Thepayload
field directly maps toMessage#body
, whileUser Properties
roughly maps toMessage#headers
, even though the properties here are not formatted with ace-
prefix like other transport protocols. This is per the spec. See: https://github.com/cloudevents/spec/blob/v1.0.1/mqtt-protocol-binding.md. ThePUBLISH
property is there primarily to support the"Content type"
and perhaps should be typed better. Feedback welcome.