示例#1
0
 async def dispatch_event_service(self,
                                  content: Any,
                                  context: Context,
                                  event_type: str = ""):
     """
     dispatch an event on the event bus
     :param content:
     :param context:
     :param event_type:
     :return:
     """
     if context.authorize(BUS, DISPATCH_EVENT):
         event = Event(event_type, content, context)
         self.dispatch(event)
     else:
         raise NotAuthorizedError(
             f"user {context.user} is not allowed to access the bus",
             context, BUS)
示例#2
0
 async def async_publish(
     self,
     payload: Any,
     context: Context,
     topic: str,
     qos: int = 0,
     retain: bool = True,
 ):
     """
     Publish a message over MQTT
     :param payload: msg payload
     :param context: context
     :param topic: topic
     :param qos: qos
     :param retain: retain
     :return:
     """
     if context.authorize(PUBLISH, "*"):
         await self.event.wait()
         self.core.add_job(self.client.publish, topic, payload, qos, retain)