async def send_to_output(self, message, output_name): """Sends an event/message to the given module output. These are outgoing events and are meant to be "output events" If the connection to the service has not previously been opened by a call to connect, this function will open the connection before sending the event. :param message: message to send to the given output. Anything passed that is not an instance of the Message class will be converted to Message object. :param output_name: Name of the output to send the event to. """ if not isinstance(message, Message): message = Message(message) message.output_name = output_name logger.info("Sending message to output:" + output_name + "...") send_output_event_async = async_adapter.emulate_async( self._pipeline.send_output_event) def sync_callback(): logger.info("Successfully sent message to output: " + output_name) callback = async_adapter.AwaitableCallback(sync_callback) await send_output_event_async(message, callback=callback) await callback.completion()
async def send_message_to_output(self, message, output_name): """Sends an event/message to the given module output. These are outgoing events and are meant to be "output events" If the connection to the service has not previously been opened by a call to connect, this function will open the connection before sending the event. :param message: Message to send to the given output. Anything passed that is not an instance of the Message class will be converted to Message object. :param str output_name: Name of the output to send the event to. :raises: :class:`azure.iot.device.exceptions.CredentialError` if credentials are invalid and a connection cannot be established. :raises: :class:`azure.iot.device.exceptions.ConnectionFailedError` if a establishing a connection results in failure. :raises: :class:`azure.iot.device.exceptions.ConnectionDroppedError` if connection is lost during execution. :raises: :class:`azure.iot.device.exceptions.ClientError` if there is an unexpected failure during execution. """ if not isinstance(message, Message): message = Message(message) message.output_name = output_name logger.info("Sending message to output:" + output_name + "...") send_output_event_async = async_adapter.emulate_async( self._iothub_pipeline.send_output_event) callback = async_adapter.AwaitableCallback() await send_output_event_async(message, callback=callback) await handle_result(callback) logger.info("Successfully sent message to output: " + output_name)
async def send_message_to_output(self, message, output_name): """Sends an event/message to the given module output. These are outgoing events and are meant to be "output events" If the connection to the service has not previously been opened by a call to connect, this function will open the connection before sending the event. :param message: Message to send to the given output. Anything passed that is not an instance of the Message class will be converted to Message object. :type message: :class:`azure.iot.device.Message` or str :param str output_name: Name of the output to send the event to. :raises: :class:`azure.iot.device.exceptions.CredentialError` if credentials are invalid and a connection cannot be established. :raises: :class:`azure.iot.device.exceptions.ConnectionFailedError` if a establishing a connection results in failure. :raises: :class:`azure.iot.device.exceptions.ConnectionDroppedError` if connection is lost during execution. :raises: :class:`azure.iot.device.exceptions.OperationTimeout` if connection attempt times out :raises: :class:`azure.iot.device.exceptions.NoConnectionError` if the client is not connected (and there is no auto-connect enabled) :raises: :class:`azure.iot.device.exceptions.ClientError` if there is an unexpected failure during execution. :raises: ValueError if the message fails size validation. """ if not isinstance(message, Message): message = Message(message) if message.get_size() > device_constant.TELEMETRY_MESSAGE_SIZE_LIMIT: raise ValueError("Size of message can not exceed 256 KB.") message.output_name = output_name logger.info("Sending message to output:" + output_name + "...") send_output_message_async = async_adapter.emulate_async( self._mqtt_pipeline.send_output_message ) callback = async_adapter.AwaitableCallback() await send_output_message_async(message, callback=callback) await handle_result(callback) logger.info("Successfully sent message to output: " + output_name)