Skip to content

fix: add body_json and content_type to queue messages - #1048

Open
SameerVers3 wants to merge 1 commit into
cloudflare:mainfrom
SameerVers3:fix/queue-body-json
Open

fix: add body_json and content_type to queue messages#1048
SameerVers3 wants to merge 1 commit into
cloudflare:mainfrom
SameerVers3:fix/queue-body-json

Conversation

@SameerVers3

Copy link
Copy Markdown

Closes #1013

serde_wasm_bindgen::from_value is unreliable for types like serde_json::Value and tuples. This adds an escape hatch:

for msg in batch.raw_iter() {
    let body: MyPayload = msg.body_json()?;
}

Also exposes content_type() on Message and RawMessage so consumers can inspect the producer's format.

@SameerVers3

Copy link
Copy Markdown
Author

@guybedford Can you review this?

Comment thread worker/src/queue.rs Outdated
.content_type()
.unwrap()
.map(|s| match s.as_string().unwrap().as_str() {
"json" => QueueContentType::Json,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could use strum::EnumString here much like it’s done here. But I suppose this repetitive pattern is already spread across the module, so it’s a matter of taste.

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.

yes you are correct, I missed it. updating it now

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.

[BUG] Queue: typed MessageBatch<T> deserialize via serde_wasm_bindgen::from_value mangles payloads — offer a JSON-based path

2 participants