Skip to content

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

Merged
merged 2 commits into from
Jan 14, 2022
Merged

Conversation

lance
Copy link
Member

@lance lance commented Jan 11, 2022

Proposed Changes

Add MQTT as a Message format.

Description

This commit adds MQTT to the supported transport protocols by adding a Binding and the MQTTMessage<T> type, extending the base Message type, adding the MQTT fields for payload, PUBLISH and User Properties. The payload field directly maps to Message#body, while User Properties roughly maps to Message#headers, even though the properties here are not formatted with a ce- prefix like other transport protocols. This is per the spec. See: https://github.com/cloudevents/spec/blob/v1.0.1/mqtt-protocol-binding.md. The PUBLISH property is there primarily to support the "Content type" and perhaps should be typed better. Feedback welcome.

Signed-off-by: Lance Ball <lball@redhat.com>
@lance lance added the type/enhancement New feature or request label Jan 11, 2022
@lance lance requested a review from a team January 11, 2022 21:53
@lance lance mentioned this pull request Jan 11, 2022
Copy link
Member

@grant grant left a 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.

Comment on lines +14 to +36
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);
Copy link
Member

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>
@lance lance merged commit 591d133 into cloudevents:main Jan 14, 2022
@lance lance deleted the lance/add-mqtt branch January 14, 2022 16:41
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
type/enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants