Skip to content

Commit

Permalink
Intro retry config for client
Browse files Browse the repository at this point in the history
and add the onClose resource for callback services
  • Loading branch information
MaryamZi committed Jul 26, 2020
1 parent 0050018 commit a2729ce
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion subscriber/src/subscriber/subscriber.bal
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,16 @@ public function main (string? username = (), // my username
headers[http:AUTH_HEADER] = string `Basic ${token}`;
}

http:WebSocketClient wsClientEp = new (wsUrl, config = {callbackService: callbackService, customHeaders: headers});
http:WebSocketClient wsClientEp = new (wsUrl, config = {
callbackService: callbackService,
customHeaders: headers,
retryConfig: {
intervalInMillis: 3000,
maxCount: 10,
backOffFactor: 1.5,
maxWaitIntervalInMillis: 20000
}
});

if wsClientEp.isOpen() {
io:println(
Expand All @@ -151,6 +160,10 @@ service resultDataOnlyClientService = @http:WebSocketServiceConfig {} service {
resource function onError(http:WebSocketClient conn, error err) {
log:printError("Error occurred", err);
}

resource function onClose(http:WebSocketClient wsEp, int statusCode, string reason) {
log:printInfo(string `Connection closed: statusCode: ${statusCode}, reason: ${reason}`);
}
};

service awaitAndResultDataClientService = @http:WebSocketServiceConfig {} service {
Expand All @@ -174,6 +187,10 @@ service awaitAndResultDataClientService = @http:WebSocketServiceConfig {} servic
resource function onError(http:WebSocketClient conn, error err) {
log:printError("Error occurred", err);
}

resource function onClose(http:WebSocketClient wsEp, int statusCode, string reason) {
log:printInfo(string `Connection closed: statusCode: ${statusCode}, reason: ${reason}`);
}
};

service imageAndResultDataClientService = @http:WebSocketServiceConfig {} service {
Expand All @@ -199,6 +216,10 @@ service imageAndResultDataClientService = @http:WebSocketServiceConfig {} servic
resource function onError(http:WebSocketClient conn, error err) {
log:printError("Error occurred", err);
}

resource function onClose(http:WebSocketClient wsEp, int statusCode, string reason) {
log:printInfo(string `Connection closed: statusCode: ${statusCode}, reason: ${reason}`);
}
};


Expand Down Expand Up @@ -232,6 +253,10 @@ service allClientService = @http:WebSocketServiceConfig {} service {
resource function onError(http:WebSocketClient conn, error err) {
log:printError("Error occurred", err);
}

resource function onClose(http:WebSocketClient wsEp, int statusCode, string reason) {
log:printInfo(string `Connection closed: statusCode: ${statusCode}, reason: ${reason}`);
}
};

function notifyAwait() {
Expand Down

0 comments on commit a2729ce

Please sign in to comment.