Skip to content

Enabled greengrass components to receive direct message by opting for RECEIVE_ONLY mode - #1164

Open
tushar-aws wants to merge 1 commit into
mainfrom
dev/iot-core-direct-messaging
Open

Enabled greengrass components to receive direct message by opting for RECEIVE_ONLY mode#1164
tushar-aws wants to merge 1 commit into
mainfrom
dev/iot-core-direct-messaging

Conversation

@tushar-aws

@tushar-aws tushar-aws commented Aug 6, 2026

Copy link
Copy Markdown

Description

Adds an on-device path for AWS IoT Core direct messages. A component can
subscribe over IPC with subscriptionMode=RECEIVE_ONLY; iotcored registers the
topic filter for local routing only and never issues a cloud SUBSCRIBE. Any
message that reaches the device on a matching filter — including direct messages
addressed to the device by client id, which arrive over the existing connection
with no subscription — is delivered to the subscribing component. A message
matching no subscriber is now dropped and logged instead of silently discarded.

Changes by component:

  • ggipcd (SubscribeToIoTCore): new optional subscriptionMode.
    RECEIVE_ONLY maps to a routing-only (virtual) subscription; absent, null,
    and SUBSCRIBE_AND_RECEIVE keep the existing cloud-subscribe path unchanged;
    any other value is rejected with InvalidArgumentsError (fail closed rather
    than silently creating a paid cloud subscription). qos is ignored for
    RECEIVE_ONLY since there is no cloud subscription to configure.

  • iotcored + core bus (aws_iot_mqtt subscribe): new virtual flag.
    A virtual registration sends no cloud SUBSCRIBE, sends no UNSUBSCRIBE on close,
    is not re-subscribed on MQTT reconnect, and does not keep a cloud subscription
    alive for a filter it shares with a cloud subscription. Inbound dispatch
    matches virtual and cloud slots identically (by topic filter), which is what
    lets a virtual slot receive direct messages. A message matching no slot is
    dropped with a warning log.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Performance improvement
  • Code refactoring

Checklist

  • Code passes all the quality test. Can try nix flake check -L locally
  • Documentation updated (if applicable)
  • Tests added/updated in
    aws-greengrass-testing

    (if applicable)

Documentation Updates

  • Updated README.md if needed
  • Updated relevant documentation in docs/ folder
  • Requested to update public documentation if applicable (aws internal only)

Testing

Additional Notes

Any additional information, context, or screenshots that would be helpful for
reviewers.

By submitting this pull request, I confirm that you can use, modify, copy, and
redistribute this contribution, under the terms of your choice.

Comment thread modules/iotcored/src/bus_server.c Outdated
@@ -143,6 +143,10 @@ static GgError rpc_subscribe(void *ctx, GgMap params, uint32_t handle) {

bool virtual = false;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

be careful using virtual here in cpp virtual itself is a keyword, but since this is C, it should be fine?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switched it to virtual <> is_virtual.

size_t count,
uint32_t handle,
uint8_t qos,
bool virtual

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

virtual in header file is more dangerous. nit: switch to is_virtual

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}

if (!matched) {
GG_LOGW(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@archigup would this be an expensive operation for gg lite? do we need to demote this or its fine to keep as is. For a scenario where the core device receives lots of unsolicited messages

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say this is fine. A device should not receive anything it did not subscribe to. If it is, then something is wrong - either we should be subscribed, or the cloud incorrectly thinks that we are.

}

if (!matched) {
GG_LOGW(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say this is fine. A device should not receive anything it did not subscribe to. If it is, then something is wrong - either we should be subscribed, or the cloud incorrectly thinks that we are.

Comment on lines +110 to +111
if ((i == index) || (topic_filter_len[i] == 0) || sub_virtual[i]) {
continue;

@AniruddhaKanhere AniruddhaKanhere Aug 7, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we check for handle[index] == handle[i] here too?

Same handle subscribing to same topic multiple times would be left out and will not be unsubscribed from the cloud in the above check. Or am i overthinking this scenario? :)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this scenario will not exists because two duplicate slots are never both alive at the same moment when the check runs. The loop looks at them one at a time, and erases each before moving on.

@AniruddhaKanhere AniruddhaKanhere left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. Thank you @tushar-aws!

@rawalexe
rawalexe force-pushed the dev/iot-core-direct-messaging branch from 8229f26 to ec4ab07 Compare August 31, 2026 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants