Skip to content

CAMEL-24377: Add JSON support to CamelEvent - #25495

Open
atiaomar1978-hub wants to merge 2 commits into
apache:mainfrom
atiaomar1978-hub:feature/CAMEL-24377-camel-event-json
Open

CAMEL-24377: Add JSON support to CamelEvent#25495
atiaomar1978-hub wants to merge 2 commits into
apache:mainfrom
atiaomar1978-hub:feature/CAMEL-24377-camel-event-json

Conversation

@atiaomar1978-hub

Copy link
Copy Markdown
Contributor

Description

Implements CAMEL-24377: structured JSON serialization for CamelEvent, similar to the existing BacklogEventMessage API used by Error Registry and Backlog Tracer.

API

Added to org.apache.camel.spi.CamelEvent:

  • Map<String, Object> asJSon() — structured event metadata as a JSON-compatible map
  • String toJSon(int indent) — pretty-printed JSON string

Implementation

  • CamelEventJsonSupport in camel-base builds JSON for all standard event types (context, route, exchange, step, service, failure)
  • Abstract event base classes and service failure events delegate to the support class
  • EventConsole now uses event.asJSon() instead of ad hoc toString() fields

JSON fields (examples)

Event category Fields
All events type, eventClass, timestamp, message
Context contextName
Route routeId, routeGroup, fromEndpointUri
Exchange exchangeId, fromRouteId, routeId
Sent/Sending endpointUri, timeTaken (sent)
Failure exception (type, message, stackTrace)
Redelivery attempt, exception
Step stepId
Service failure service, contextName

Tests

CamelEventJsonTest covers context, exchange failed/sent/failure-handling/redelivery, route reloaded/restarting failure, step failed, and service startup failure events.

./mvnw -pl core/camel-core -am test -Dtest=CamelEventJsonTest -Dsurefire.failIfNoSpecifiedTests=false

Documentation

Updated docs/user-manual/modules/ROOT/pages/event-notifier.adoc with JSON serialization section.

Tracking

AI-assisted contributions

AI-generated PR on behalf of atiaomar1978-hub (Cursor Agent)

cursoragent and others added 2 commits August 13, 2026 18:41
- Add asJSon() and toJSon(int) to CamelEvent SPI
- Implement structured JSON serialization in CamelEventJsonSupport
- Wire JSON methods through abstract event base classes and service events
- Use structured JSON in EventConsole instead of ad hoc toString fields
- Add CamelEventJsonTest with coverage for context, exchange, route, step,
  service, and failure event types
- Document JSON serialization in event-notifier.adoc

Co-authored-by: Cursor Agent <noreply@cursor.com>
- Include exception details on ExchangeRedeliveryEvent JSON
- Guard exception JSON serialization with defensive fallback
- Add redelivery event JSON test coverage

Co-authored-by: Cursor Agent <noreply@cursor.com>
@atiaomar1978-hub

Copy link
Copy Markdown
Contributor Author

Bugbot / Grok self-review — findings addressed

AI-generated comment on behalf of atiaomar1978-hub (Cursor Agent)

Review summary

Severity Finding Status
Medium ExchangeRedeliveryEvent omitted exception in JSON Fixed in c916abe — includes exchange exception
Low appendException lacked defensive try/catch Fixed in c916abe — fallback to exceptionMessage
Medium Empty docs/yarn.lock in repo Not in this PR — file is untracked locally, not committed
High Unrelated scripts/post-pr-25433-inline-replies.sh Not in this PR — untracked locally, not committed

Test coverage (CamelEventJsonTest)

  • Context started event (asJSon + toJSon)
  • Exchange failed (via EventNotifier, exception fields)
  • Exchange sent (endpointUri, timeTaken)
  • Exchange failure handling (DLQ metadata)
  • Exchange redelivery (attempt + exception)
  • Route reloaded / restarting failure
  • Step failed
  • Service startup failure
  • JsonObject compatibility

Tests

./mvnw -pl core/camel-core -am test -Dtest=CamelEventJsonTest -Dsurefire.failIfNoSpecifiedTests=false

All 10 tests passing locally. Ready for human review.

@atiaomar1978-hub
atiaomar1978-hub marked this pull request as ready for review August 14, 2026 15:55
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.

2 participants