carlosCharz / fcmxmppserverv2

XMPP Connection Server for FCM using the latest version of the Smack library (4.3.4) + Connection Draining Implementation
47 stars 33 forks source link

CONNECTION_DRAINING handling #8

Closed long1eu closed 7 years ago

long1eu commented 7 years ago

How do you handle CONNECTION_DRAINING message?

I'm doing this:

private void handleConnectionDrainingFailure() {
        logger.log(Level.INFO, "FCM Connection is draining! Initiating reconnection ...");

        XMPPTCPConnection oldConnection = connection;
        oldConnection.disconnect();

        try {
            connect();
        } catch (XMPPException | SmackException | IOException | InterruptedException e) {
            e.printStackTrace();
        }
    }
carlosCharz commented 7 years ago

I have modified a little bit the ccsConnection class but it is almost the same because in connection draining I am calling the reconnect method:

public void reconnection() { BackOffStrategy backoff = new BackOffStrategy(); while (backoff.shouldRetry()) { try { initialize(); backoff.doNotRetry(); } catch (XMPPException | SmackException | IOException e) { logger.info("The notifier server could not reconnect after the connection draining message"); backoff.errorOccured(); } } }

@PostConstruct public void initialize() throws XMPPException, SmackException, IOException { // Create the connection connection = new XMPPTCPConnection(connConfiguration);

    // Connect
    connection.connect();

...

// Login to FCM

}

Hope it helps

carlosCharz commented 6 years ago

Hi @long1eu

I just pushed the connection draining logic to the main branch if you want to check it out. Links:

Hope you can find it useful. Greetings!

long1eu commented 6 years ago

Thank you so much! Hope you're well!