Skip to content

Publish RabbitMQ messages as JSON instead of Java serialization#1152

Merged
Brutus5000 merged 3 commits into
developfrom
fix/rabbit-json-message-converter
Jun 27, 2026
Merged

Publish RabbitMQ messages as JSON instead of Java serialization#1152
Brutus5000 merged 3 commits into
developfrom
fix/rabbit-json-message-converter

Conversation

@Brutus5000

@Brutus5000 Brutus5000 commented Jun 27, 2026

Copy link
Copy Markdown
Member

Problem

The player_avatar update event (published by PlayerAvatarUpdateHook) was sent with content type application/x-java-serialized-object instead of JSON. Consumers expecting JSON cannot read it.

Cause

JacksonJsonMessageConverter was only wired into the listener container factory (consuming side). The publishing side uses Spring Boot's auto-configured RabbitTemplate, which had no JSON converter and therefore fell back to the default SimpleMessageConverter (Java serialization).

Fix

Expose a single JacksonJsonMessageConverter bean. Spring Boot's RabbitTemplateConfigurer applies a unique MessageConverter bean to the auto-configured RabbitTemplate, 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 type application/json.

Testing

  • ./gradlew compileJava clean.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Rabbit messaging now uses JSON payloads instead of Java serialization for published and consumed messages.
    • Added coverage to verify message content type and payload format for player avatar updates, including cleared values.
  • Bug Fixes

    • Ensured messages are encoded consistently as JSON, improving compatibility with message consumers and tooling.

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>
@coderabbitai

coderabbitai Bot commented Jun 27, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@Brutus5000, we couldn't start this review because you've reached your PR review rate limit.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 98ab95e9-af1d-4fdd-be8c-4513e50686e5

📥 Commits

Reviewing files that changed from the base of the PR and between 80e07c6 and 9bc852f.

📒 Files selected for processing (1)
  • src/inttest/java/com/faforever/api/config/RabbitMessageEncodingTest.java
📝 Walkthrough

Walkthrough

RabbitConfiguration extracts JacksonJsonMessageConverter as a dedicated Spring bean shared by both the RabbitTemplate (publishing) and rabbitListenerContainerFactory (consuming). A new integration test class verifies that avatar update hook messages are published with application/json content type and correct JSON payloads for both non-null and null avatar states.

RabbitMQ JSON Encoding

Layer / File(s) Summary
Shared JacksonJsonMessageConverter bean
src/main/java/com/faforever/api/config/RabbitConfiguration.java
Adds a jacksonJsonMessageConverter() bean and updates rabbitListenerContainerFactory to accept and use it instead of creating the converter inline.
Integration tests for JSON message encoding
src/inttest/java/com/faforever/api/config/RabbitMessageEncodingTest.java
Declares a test queue bound to the avatar update routing key, triggers PlayerAvatarUpdateHook, receives the message, and asserts JSON content type and exact payload for both non-null and cleared avatar cases.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 A converter shared, no more made anew,
JSON flows through the queue, crisp and true.
The avatar hops in, the avatar hops out,
The test queue confirms what it's all about.
Null or not null — the rabbit knows the route! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: RabbitMQ messages now use JSON instead of Java serialization.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/rabbit-json-message-converter

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/inttest/java/com/faforever/api/config/RabbitMessageEncodingTest.java (1)

37-38: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Use a unique queue per test run.

Reusing inttest.player_avatar.update across 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

📥 Commits

Reviewing files that changed from the base of the PR and between 43234e2 and 80e07c6.

📒 Files selected for processing (2)
  • src/inttest/java/com/faforever/api/config/RabbitMessageEncodingTest.java
  • src/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>
@Brutus5000 Brutus5000 merged commit 1885bcc into develop Jun 27, 2026
4 checks passed
@Brutus5000 Brutus5000 deleted the fix/rabbit-json-message-converter branch June 27, 2026 18:04
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.

1 participant