Search code examples
python-2.7google-cloud-messagingxmppxmpppy

how often exactly CCS needs to close down a connection to perform load balancing?


i have a client XMPP and i have never received a CONNECTION_DRAINING message so that i have that question, how often exactly CCS needs to close down a connection to perform load balancing?

this is part of my code where i verify if i receive a CONNECTION_DRAINING message

............................... more code

def message_callback(session, message):  
    global unacked_messages_quota

    gcmData = message.getTags('data:gcm')
    if gcmData:
        print "alert, the connection is being drained and will be closed soon !!!!!!!!!!!!!"                    
    gcm = message.getTags('gcm')
    if gcm:
        gcm_json = gcm[0].getData()
        msg = json.loads(gcm_json)          
    if not msg.has_key('message_type'):     
      # Acknowledge the incoming message immediately.                   
      send({'to': msg['from'],
            'message_type': 'ack',
            'message_id': msg['message_id']})
.......................................................... more code

i have read the docs from https://developers.google.com/cloud-messaging/ccs

specifically this part

Periodically, CCS needs to close down a connection to perform load balancing. Before it closes the connection, CCS sends a CONNECTION_DRAINING message to indicate that the connection is being drained and will be closed soon. "Draining" refers to shutting off the flow of messages coming into a connection, but allowing whatever is already in the pipeline to continue. When you receive a CONNECTION_DRAINING message, you should immediately begin sending messages to another CCS connection, opening a new connection if necessary. You should, however, keep the original connection open and continue receiving messages that may come over the connection (and ACKing them)—CCS handles initiating a connection close when it is ready.

The CONNECTION_DRAINING message looks like this:

<message>
  <data:gcm xmlns:data="google:mobile:data">
  {
    "message_type":"control"
    "control_type":"CONNECTION_DRAINING"
  }
  </data:gcm>
</message>

Solution

  • It is usually at least once a week, but can be much more frequent depending on the load.