Skip to content

feat(rumqttc): return packet ID from publish methods - #1049

Open
aa51513 wants to merge 1 commit into
bytebeamio:mainfrom
aa51513:main
Open

aa51513 wants to merge 1 commit into
bytebeamio:mainfrom
aa51513:main

Conversation

@aa51513

@aa51513 aa51513 commented Apr 29, 2026

Copy link
Copy Markdown

All publish methods (sync/async, v4/v5) now return Result<u16, ClientError> instead of Result<(), ClientError>. For QoS 0 publishes, 0 is returned. For QoS 1/2, the assigned packet ID is returned immediately.

Implementation uses a shared Arc counter between the client and MqttState. The client pre-assigns packet IDs before sending through the channel, avoiding the need for async oneshot channels (which would deadlock the sync Client).

  • Add pkid_counter field to MqttState, EventLoop, and AsyncClient
  • MqttState: remove Clone derive, implement Debug manually
  • EventLoop: create and expose shared pkid_counter
  • AsyncClient: assign pkid via atomic fetch_add before sending
  • Update from_senders/from_sender signatures to accept pkid_counter
  • Update tests for new API and pkid wrapping behavior

Type of change

Checklist:

  • Formatted with cargo fmt
  • Make an entry to CHANGELOG.md if it's relevant to the users of the library. If it's not relevant mention why.

All publish methods (sync/async, v4/v5) now return Result<u16, ClientError>
instead of Result<(), ClientError>. For QoS 0 publishes, 0 is returned.
For QoS 1/2, the assigned packet ID is returned immediately.

Implementation uses a shared Arc<AtomicU16> counter between the client and
MqttState. The client pre-assigns packet IDs before sending through the
channel, avoiding the need for async oneshot channels (which would deadlock
the sync Client).

- Add pkid_counter field to MqttState, EventLoop, and AsyncClient
- MqttState: remove Clone derive, implement Debug manually
- EventLoop: create and expose shared pkid_counter
- AsyncClient: assign pkid via atomic fetch_add before sending
- Update from_senders/from_sender signatures to accept pkid_counter
- Update tests for new API and pkid wrapping behavior
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.

1 participant