code: def shutdown(self):
          
          try:
              self._sessions = dict()
              self._subscriptions = dict()
              self._retained_messages = dict()
              self.transitions.shutdown()
          except (MachineError, ValueError) as exc:
              # Backwards compat: MachineError is raised by transitions < 0.5.0.
              self.logger.debug("Invalid method call at this moment: %s" % exc)
              raise BrokerException("Broker instance can't be stopped: %s" % exc)
  
          # Fire broker_shutdown event to plugins
          yield from self.plugins_manager.fire_event(EVENT_BROKER_PRE_SHUTDOWN)
  
          # Stop broadcast loop
          if self._broadcast_task:
              self._broadcast_task.cancel()
          if self._broadcast_queue.qsize() > 0:
              self.logger.warning("%d messages not broadcasted" % self._broadcast_queue.qsize())
  
          for listener_name in self._servers:
              server = self._servers[listener_name]
              yield from server.close_instance()
          self.logger.debug("Broker closing")
          self.logger.info("Broker closed")
          yield from self.plugins_manager.fire_event(EVENT_BROKER_POST_SHUTDOWN)
          self.transitions.stopping_success()
docs: Stop broker instance.
  
              Closes all connected session, stop listening on network socket and free resources.