diff --git a/src/blueapi/service/interface.py b/src/blueapi/service/interface.py index 69d3da4f3..397ba8f1d 100644 --- a/src/blueapi/service/interface.py +++ b/src/blueapi/service/interface.py @@ -49,7 +49,7 @@ def worker() -> TaskWorker: @lru_cache -def cached_stomp_client() -> StompClient | None: +def messaging_template() -> StompClient | None: stomp_config: StompConfig | None = config().stomp if stomp_config is not None: client = StompClient.for_broker( @@ -85,16 +85,16 @@ def setup(config: ApplicationConfig) -> None: logging.basicConfig(level=config.logging.level) worker() - cached_stomp_client() + messaging_template() def teardown() -> None: worker().stop() - if (template := cached_stomp_client()) is not None: + if (template := messaging_template()) is not None: template.disconnect() context.cache_clear() worker.cache_clear() - cached_stomp_client.cache_clear() + messaging_template.cache_clear() def _publish_event_streams( @@ -106,7 +106,7 @@ def _publish_event_streams( def _publish_event_stream(stream: EventStream, destination: DestinationBase) -> None: def forward_message(event: Any, correlation_id: str | None) -> None: - if (template := cached_stomp_client()) is not None: + if (template := messaging_template()) is not None: template.send(destination, event, None, correlation_id=correlation_id) stream.subscribe(forward_message) diff --git a/tests/unit_tests/service/test_interface.py b/tests/unit_tests/service/test_interface.py index 617a91935..86dd2e5c1 100644 --- a/tests/unit_tests/service/test_interface.py +++ b/tests/unit_tests/service/test_interface.py @@ -288,4 +288,4 @@ def test_stomp_config(template: StompClient): "blueapi.service.interface.StompClient.for_broker", return_value=template ): interface.set_config(ApplicationConfig(stomp=StompConfig())) - assert interface.cached_stomp_client() is not None + assert interface.messaging_template() is not None