Publish RabbitMQ messages as JSON instead of Java serialization#1152
Conversation
The avatar update event (and any other RabbitTemplate publish) was serialized with the default SimpleMessageConverter, producing application/x-java-serialized-object instead of JSON. The JacksonJsonMessageConverter was only wired into the listener container factory (consuming), not the auto-configured RabbitTemplate (publishing). Expose a single JacksonJsonMessageConverter bean so Spring Boot applies it to the auto-configured RabbitTemplate, and reuse it in the listener factory. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Warning Review limit reached
More reviews will be available in 55 minutes and 55 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthrough
RabbitMQ JSON Encoding
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Publishes a player_avatar event through the real auto-configured RabbitTemplate (via PlayerAvatarUpdateHook) against a RabbitMQ Testcontainer and reads the raw message back, asserting the content type is application/json (not application/x-java-serialized-object) and the body is the expected JSON. Covers both an assigned avatar and the cleared (null) case. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/inttest/java/com/faforever/api/config/RabbitMessageEncodingTest.java (1)
37-38: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winUse a unique queue per test run.
Reusing
inttest.player_avatar.updateacross both methods leaves shared broker state behind if runs overlap or cleanup fails, which can make these integration tests flaky.Suggested change
+import java.util.UUID; + -public class RabbitMessageEncodingTest extends AbstractIntegrationTest { - - private static final String TEST_QUEUE = "inttest.player_avatar.update"; +public class RabbitMessageEncodingTest extends AbstractIntegrationTest { + private String testQueue; @@ private void bindTestQueue() { - Queue queue = new Queue(TEST_QUEUE, false, false, true); + testQueue = "inttest.player_avatar.update." + UUID.randomUUID(); + Queue queue = new Queue(testQueue, false, true, true); amqpAdmin.declareQueue(queue); amqpAdmin.declareBinding( BindingBuilder.bind(queue).to(new TopicExchange(EXCHANGE_FAF_LOBBY)).with(ROUTING_KEY_PLAYER_AVATAR_UPDATE)); } @@ public void deleteTestQueue() { - amqpAdmin.deleteQueue(TEST_QUEUE); + if (testQueue != null) { + amqpAdmin.deleteQueue(testQueue); + } } @@ - Message message = rabbitTemplate.receive(TEST_QUEUE, 5000); + Message message = rabbitTemplate.receive(testQueue, 5000); @@ - Message message = rabbitTemplate.receive(TEST_QUEUE, 5000); + Message message = rabbitTemplate.receive(testQueue, 5000);Also applies to: 46-56, 70-70, 90-90
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/inttest/java/com/faforever/api/config/RabbitMessageEncodingTest.java` around lines 37 - 38, The RabbitMessageEncodingTest is reusing a shared fixed queue name, which can leave broker state between overlapping runs; update the test setup to create a unique queue per test run instead of the static TEST_QUEUE constant. Adjust the queue declaration and all send/assert paths in RabbitMessageEncodingTest to reference the per-run queue identifier so each test method uses its own isolated queue.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/inttest/java/com/faforever/api/config/RabbitMessageEncodingTest.java`:
- Around line 37-38: The RabbitMessageEncodingTest is reusing a shared fixed
queue name, which can leave broker state between overlapping runs; update the
test setup to create a unique queue per test run instead of the static
TEST_QUEUE constant. Adjust the queue declaration and all send/assert paths in
RabbitMessageEncodingTest to reference the per-run queue identifier so each test
method uses its own isolated queue.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: f2e365eb-cb2d-402f-b1d4-12c5efb757e6
📒 Files selected for processing (2)
src/inttest/java/com/faforever/api/config/RabbitMessageEncodingTest.javasrc/main/java/com/faforever/api/config/RabbitConfiguration.java
Replaces escaped JSON string literals with multi-line text blocks for readability. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Problem
The
player_avatarupdate event (published byPlayerAvatarUpdateHook) was sent with content typeapplication/x-java-serialized-objectinstead of JSON. Consumers expecting JSON cannot read it.Cause
JacksonJsonMessageConverterwas only wired into the listener container factory (consuming side). The publishing side uses Spring Boot's auto-configuredRabbitTemplate, which had no JSON converter and therefore fell back to the defaultSimpleMessageConverter(Java serialization).Fix
Expose a single
JacksonJsonMessageConverterbean. Spring Boot'sRabbitTemplateConfigurerapplies a uniqueMessageConverterbean to the auto-configuredRabbitTemplate, so outgoing messages are now serialized as JSON. The same bean is reused in the listener container factory.Outgoing avatar events now publish as e.g.
{"player_id":123,"avatar_id":5}with content typeapplication/json.Testing
./gradlew compileJavaclean.🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes