arobson / rabbot

Deprecated: Please see https://github.com/Foo-Foo-MQ/foo-foo-mq
MIT License
277 stars 129 forks source link

Handling of broken JSON objects causes absent body #104

Closed ptusch closed 6 years ago

ptusch commented 7 years ago

Hi everyone,

seems like this library has an issue when you publish a broken object (application/json) using any rabbit client and the consume it with rabbot.

The handle method seems to be called nicely and I can access most of the messages' properties - except for the body. I didn't expect an absent body as I didn't find anything in the documentation so I assume it's a bug for now.

Of course, there might be broken messages in the queue but if that happens and such a message is of Content Type application/json I expect either an error or an empty object body which I can validate neatly. Today I have to check the body's existence (yes, easy but unexpected) which might be undesirable.

Anyhow what do you guys think of it? Should I PR you a fix?

I'd say we could either throw an error in the error mechanic or return an empty body.

Used Versions

Sample Data

Here's some correct json:

{
"name": "samwell"
}

And some broken json (note the missing"):

{
"name:"samwell"
}
arobson commented 6 years ago

@ptusch - I've added some new behaviors to make this easier to handle. The high level explanation is here.

The behavior now is that messages that can't be deserialized will be rejected. To process these, you'll need a DLX bound to a DLQ marked as poison so that you can manage it all.

When it re-publishes the message, it will set a quarantined flag on the message and append .quarantined to the end of the topic. This will allow you to handle topics like #.quarantined to get all quarantined topics, my.topic.quarantined to get only bad messages for a specific topic or even my.topic.# to get the regular and quarantined messages and then use the flag to detect the bad messages.

ptusch commented 6 years ago

Awesome, thank you!