@@ -140,7 +140,42 @@ def _handle(
140140 return super ()._handle (event_bus , message )
141141
142142
143- class MessageBody (Message , ABC ):
143+ class MessageDict (Message , ABC ):
144+ """Dict message."""
145+
146+ @classmethod
147+ @abstractmethod
148+ def _handle_dict (
149+ cls , event_bus : EventBus , message : dict [str , Any ]
150+ ) -> HandlingResult :
151+ """Handle string message and notify the correct event subscribers.
152+
153+ :return: A message response
154+ """
155+
156+ @classmethod
157+ @_handle_error_or_analyse
158+ @final
159+ def __handle_dict (
160+ cls , event_bus : EventBus , message : dict [str , Any ]
161+ ) -> HandlingResult :
162+ return cls ._handle_dict (event_bus , message )
163+
164+ @classmethod
165+ def _handle (
166+ cls , event_bus : EventBus , message : dict [str , Any ] | str
167+ ) -> HandlingResult :
168+ """Handle message and notify the correct event subscribers.
169+
170+ :return: A message response
171+ """
172+ if isinstance (message , dict ):
173+ return cls .__handle_dict (event_bus , message )
174+
175+ return super ()._handle (event_bus , message )
176+
177+
178+ class MessageBody (MessageDict , ABC ):
144179 """Dict message with body attribute."""
145180
146181 @classmethod
@@ -158,17 +193,17 @@ def __handle_body(cls, event_bus: EventBus, body: dict[str, Any]) -> HandlingRes
158193 return cls ._handle_body (event_bus , body )
159194
160195 @classmethod
161- def _handle (
162- cls , event_bus : EventBus , message : dict [str , Any ] | str
196+ def _handle_dict (
197+ cls , event_bus : EventBus , message : dict [str , Any ]
163198 ) -> HandlingResult :
164199 """Handle message and notify the correct event subscribers.
165200
166201 :return: A message response
167202 """
168- if isinstance ( message , dict ) :
203+ if "body" in message :
169204 return cls .__handle_body (event_bus , message ["body" ])
170205
171- return super ()._handle (event_bus , message )
206+ return super ()._handle_dict (event_bus , message )
172207
173208
174209class MessageBodyData (MessageBody , ABC ):
0 commit comments