Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Added try/except to Publisher to handle case where EventPages are too large, and dynamically re-chunk them.
Motivation
When flyscanning, we can produce quite large EventPages of data that cause the Kafka producer to choke. Fortunately, an EventPage can be re-chunked quite easily (once bluesky/event-model#297 is merged), so we should take advantage of this to produce documents that Kafka can handle.
Details
I have added a try/except to the Publisher to catch the KafkaException indicating that a message is too large. If the message is too large, and the document was an EventPage, we should try re-chunking the document to half its size, and re-sending.
I have made this process recursive, so that the page size will be halved until the messages are small enough. Hopefully this only needs to happen once or twice, but with fly-scans, quite large EventPages can be generated.
Testing
I have tested this by publishing quite large test pages, which successfully publish. All existing tests pass. Possibly more tests could be implemented.