code: def publish(self, topic, message):
          
  
          seq = self.sequencer.next_id(topic)
  
          packet = {
              'sequence': seq,
              'message': message
          }
          # Need to encode bytes types for json.dumps
          if 'key' in packet['message']:
              packet['message']['key'] = packet['message']['key'].decode('utf8')
          if 'payload' in packet['message']:
              packet['message']['payload'] = packet['message']['payload'].decode('utf8')
          if 'script' in packet['message']:
              packet['message']['script'] = packet['message']['script'].decode('utf8')
          if 'trace' in packet['message']:
              packet['message']['trace'] = packet['message']['trace'].decode('utf8')
          if 'report' in packet['message']:
              packet['message']['report'] = packet['message']['report'].decode('utf8')
          if 'received_time' in packet['message']:
              packet['message']['received_time'] = packet['message']['received_time'].decode('utf8')
  
          serialized_packet = json.dumps(packet)
  
          try:
              # Limit how much we log in case the message is very long
              self._logger.debug("Publishing %s on topic %s", serialized_packet[:256], topic)
              self.client.publish(topic, serialized_packet, 1)
          except operationError as exc:
              raise InternalError("Could not publish message", topic=topic, message=exc.message)
docs: Publish a json message to a topic with a type and a sequence number
  
          The actual message will be published as a JSON object:
          {
              "sequence": <incrementing id>,
              "message": message
          }
  
          Args:
              topic (string): The MQTT topic to publish in
              message (string, dict): The message to publish