From 8605fe3faa6d55817bd3518be59e40d5b1071061 Mon Sep 17 00:00:00 2001 From: maffettone Date: Wed, 6 Nov 2024 08:35:54 -0500 Subject: [PATCH 1/2] fix: configure_kafka_publisher assumed a string --- nslsii/__init__.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/nslsii/__init__.py b/nslsii/__init__.py index 7113984..dd454f2 100644 --- a/nslsii/__init__.py +++ b/nslsii/__init__.py @@ -96,9 +96,10 @@ def configure_base( ipython_logging : boolean, optional True by default. Console output and exception stack traces will be written to IPython log file when IPython logging is enabled. - publish_documents_with_kafka: boolean, optional + publish_documents_with_kafka: Union[boolean, str], optional False by default. If True publish bluesky documents to a Kafka message broker using - configuration parameters read from a file. + configuration parameters read from a file. If bool used, the Kafka topic is auto-configured if the + broker_name is a string. If a string is used, it will override the TLA for the auto-configured topic. tb_minimize : boolean, optional If IPython should print out 'minimal' tracebacks. @@ -223,7 +224,12 @@ def configure_base( configure_ipython_logging(exception_logger=log_exception, ipython=ipython) if publish_documents_with_kafka: - configure_kafka_publisher(RE, beamline_name=broker_name) + if isinstance(publish_documents_with_kafka, str): + configure_kafka_publisher(RE, beamline_name=publish_documents_with_kafka) + elif isinstance(broker_name, str): + configure_kafka_publisher(RE, beamline_name=broker_name) + else: + raise ValueError("broker_name or publish_documents_with_kafka must be a string") if tb_minimize and ipython: # configure %xmode minimal From bbc314cd2eb75a008d6030c141851a5a908bdd36 Mon Sep 17 00:00:00 2001 From: maffettone Date: Thu, 7 Nov 2024 14:18:58 -0500 Subject: [PATCH 2/2] fix: deal with broker name attr --- nslsii/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/nslsii/__init__.py b/nslsii/__init__.py index dd454f2..19a84c0 100644 --- a/nslsii/__init__.py +++ b/nslsii/__init__.py @@ -226,10 +226,13 @@ def configure_base( if publish_documents_with_kafka: if isinstance(publish_documents_with_kafka, str): configure_kafka_publisher(RE, beamline_name=publish_documents_with_kafka) + elif hasattr(broker_name, "name"): + configure_kafka_publisher(RE, beamline_name=broker_name.name) elif isinstance(broker_name, str): configure_kafka_publisher(RE, beamline_name=broker_name) else: - raise ValueError("broker_name or publish_documents_with_kafka must be a string") + raise ValueError("If broker_name is not a string and lacks a name attribute, " + "publish_documents_with_kafka must be a string") if tb_minimize and ipython: # configure %xmode minimal