Example #1
0
    def connectionMade(self):
        super().connectionMade()
        logger.info("Connected to redis instance")
        self.subscribe(self.stream_name)
        self.send_command(ReplicateCommand())

        self.handler.new_connection(self)
Example #2
0
 async def _send_subscribe(self):
     # it's important to make sure that we only send the REPLICATE command once we
     # have successfully subscribed to the stream - otherwise we might miss the
     # POSITION response sent back by the other end.
     logger.info("Sending redis SUBSCRIBE for %s", self.stream_name)
     await make_deferred_yieldable(self.subscribe(self.stream_name))
     logger.info(
         "Successfully subscribed to redis stream, sending REPLICATE command"
     )
     await self._async_send_command(ReplicateCommand())
     logger.info("REPLICATE successfully sent")
Example #3
0
    def replicate(self, stream_name, token):
        """Send the subscription request to the server
        """
        if stream_name not in STREAMS_MAP:
            raise Exception("Invalid stream name %r" % (stream_name,))

        logger.info(
            "[%s] Subscribing to replication stream: %r from %r",
            self.id(),
            stream_name,
            token,
        )

        self.streams_connecting.add(stream_name)

        self.send_command(ReplicateCommand(stream_name, token))
Example #4
0
    async def _send_subscribe(self):
        # it's important to make sure that we only send the REPLICATE command once we
        # have successfully subscribed to the stream - otherwise we might miss the
        # POSITION response sent back by the other end.
        logger.info("Sending redis SUBSCRIBE for %s", self.synapse_stream_name)
        await make_deferred_yieldable(self.subscribe(self.synapse_stream_name))
        logger.info(
            "Successfully subscribed to redis stream, sending REPLICATE command"
        )
        self.synapse_handler.new_connection(self)
        await self._async_send_command(ReplicateCommand())
        logger.info("REPLICATE successfully sent")

        # We send out our positions when there is a new connection in case the
        # other side missed updates. We do this for Redis connections as the
        # otherside won't know we've connected and so won't issue a REPLICATE.
        self.synapse_handler.send_positions_to_connection(self)
Example #5
0
    def replicate(self):
        """Send the subscription request to the server"""
        logger.info("[%s] Subscribing to replication streams", self.id())

        self.send_command(ReplicateCommand())
Example #6
0
 def replicate_stream(self, stream, token="NOW"):
     """Make the client end a REPLICATE command to set up a subscription to a stream"""
     self.client.send_command(ReplicateCommand(stream, token))