code: def _handle_event_query(self):
          
          assert self.query_socket.getsockopt(zmq.RCVMORE)
          fro = self.query_socket.recv().decode()
          assert self.query_socket.getsockopt(zmq.RCVMORE)
          to = self.query_socket.recv().decode()
          assert not self.query_socket.getsockopt(zmq.RCVMORE)
  
          _logger.debug("Incoming query: (from, to)=(%s, %s)", fro, to)
  
          try:
              events = self.eventstore.get_events(fro if fro else None,
                                                  to if to else None)
          except eventstores.EventStore.EventKeyDoesNotExistError:
              _logger.exception("A client requested a key that does not"
                                " exist:")
              self.query_socket.send(b"ERROR Key did not exist")
              return
  
          # Since we are using ZeroMQ enveloping we want to cap the
          # maximum number of messages that are send for each request.
          # Otherwise we might run out of memory for a lot of events.
          MAX_ELMNTS_PER_REQ = 100
  
          events = itertools.islice(events, 0, MAX_ELMNTS_PER_REQ)
          events = list(events)
          if len(events) == MAX_ELMNTS_PER_REQ:
              # There are more elements, but we are capping the result
              for eventid, eventdata in events[:-1]:
                  self.query_socket.send(eventid.encode(), zmq.SNDMORE)
                  self.query_socket.send(eventdata, zmq.SNDMORE)
              lasteventid, lasteventdata = events[-1]
              self.query_socket.send(lasteventid.encode(), zmq.SNDMORE)
              self.query_socket.send(lasteventdata)
          else:
              # Sending all events. Ie., we are not capping
              for eventid, eventdata in events:
                  self.query_socket.send(eventid.encode(), zmq.SNDMORE)
                  self.query_socket.send(eventdata, zmq.SNDMORE)
              self.query_socket.send(b"END")
docs: Handle an incoming event query.