许多提升,基于AI完成的,不知道有没有坑 #11
Open
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.
fixed #7
fixed #9
Breaking Changes in Producer Message Implementation
Overview
This update introduces significant changes to how messages are serialized and handled in the Pulsar SDK, particularly for producer messages. These changes affect how content types are managed and how consumers process incoming messages.
Key Changes
Previous behavior: Developers had to manually set Content-Type headers for messages.
New behavior: The PulsarSdk::Producer::Message class now automatically sets Content-Type headers based on the message type:
String messages: text/plain; charset=utf-8
Hash/Array messages: application/json; charset=utf-8
Other objects: Automatically converted to JSON if possible, otherwise to string
New constants have been added to PulsarSdk::Producer::Message:
Enhanced Message Serialization
The serialize_message! method now automatically handles serialization based on message type:
String messages are preserved as-is with text Content-Type
Hash and Array messages are automatically converted to JSON with JSON Content-Type
Other objects are converted to JSON if they respond to to_json, otherwise to string
New Helper Method: json_encoded?
Both producer and consumer message classes now include a json_encoded? method to check if a message needs JSON deserialization:
Consumer messages are now automatically processed based on their Content-Type:
JSON messages are automatically identified via json_encoded? method
Applications can use the same method to determine how to process messages
Migration Guide
Before (Old Code):
After (New Code):
Impact Assessment
High Impact
Applications that manually set Content-Type headers may experience conflicts
Consumers that relied on manual Content-Type checking need to update to use json_encoded? method
Medium Impact
Message serialization behavior has changed, which may affect message format expectations
Error handling for JSON parsing may need adjustment
Low Impact
Basic message sending functionality remains the same
API for creating messages is unchanged, only the internal behavior is enhanced
Recommendations
Review existing code that manually sets Content-Type headers
Update consumer message processing to use the new json_encoded? helper method
Test message serialization with different data types to ensure compatibility
Update any documentation or examples that show manual Content-Type management
These changes improve the developer experience by automating content type management while providing better tools for message processing.