fix(chat): make SimpMessagingTemplate optional in ChatSessionService#19
Merged
fix(chat): make SimpMessagingTemplate optional in ChatSessionService#19
Conversation
ChatSessionService failed startup whenever the broadcasting feature was disabled because the constructor required a SimpMessagingTemplate bean, but WebSocketConfig only provides one when escalated.broadcasting.enabled is true. Spring resolved the missing bean as a fatal startup error rather than degrading gracefully. Switch the field to Optional<SimpMessagingTemplate> so Spring injects an empty Optional when broadcasting is off. All four convertAndSend call sites are routed through a private broadcast() helper that no-ops when the template is absent, so chat persistence (DB writes) keeps working while the STOMP fan-out is simply skipped. Adds a unit test that constructs the service with Optional.empty() and verifies start() succeeds without throwing. Closes #17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
ChatSessionServicedeclaredSimpMessagingTemplateas a required constructor argument.WebSocketConfigonly exposes that bean whenescalated.broadcasting.enabled = true, so the application failed to boot whenever broadcasting was off — the same failure that forced the docker demo (#14) to ship the env var sidestep.The fix is the proper one called out in #17: inject
Optional<SimpMessagingTemplate>, so Spring hands the service an emptyOptionalwhen the bean isn't published. All fourconvertAndSendcall sites are routed through a privatebroadcast()helper that no-ops when the template is absent. Chat persistence (ticketService.create, repository saves, status transitions) keeps working; only the out-of-band STOMP fan-out is skipped.Closes #17
Test plan
Optional.of(messagingTemplate)constructor wiringstart_succeedsWhenMessagingTemplateIsAbsentconstructs the service withOptional.empty()and assertsstart(...)does not throw and still persists the sessionESCALATED_BROADCASTING_ENABLED=trueto boot — that env var sidestep can be removed in a follow-up to feat(demo): Docker dev env scaffold (DRAFT, not end-to-end) #14Compatibility
This is a constructor signature change (
SimpMessagingTemplate→Optional<SimpMessagingTemplate>). Any consumer wiring the service manually (rather than via Spring's@Serviceautoinjection) needs to wrap their argument. No existing@Service-injected consumer in this repo or the demo host needs changes — Spring resolvesOptional<X>automatically.