<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def subscribe(self, topic, callback, ordered=True):
 """Subscribe to future messages in the given topic The contents of topic should be in the format created by self.publish with a sequence number of message type encoded as a json string. Wildcard topics containing + and # are allowed and Args: topic (string):
 The MQTT topic to subscribe to callback (callable):
 The callback to call when a new mesage is received The signature of callback should be callback(sequence, topic, type, message) ordered (bool):
 Whether messages on this topic have a sequence number that must be checked and queued to ensure that packets are received in order """


        if '+' in topic or '#' in topic:
            regex = re.compile(topic.replace('+', '[^/]+').replace('#', '.*'))
            self.wildcard_queues.append((topic, regex, callback, ordered))
        else:
            self.queues[topic] = PacketQueue(0, callback, ordered)

        try:
            self.client.subscribe(topic, 1, self._on_receive)
        except operationError as exc:
            raise InternalError("Could not subscribe to topic", topic=topic, message=exc.message)