Skip to content

Nodejs retrylogic #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ This example demonstrates how to add custom headers to your email message.
### [Basic send with a web proxy](https://github.com/socketlabs/socketlabs-nodejs/blob/master/examples/basic/basicSendWithProxy.js)
This example demonstrates how to use a proxy with your HTTP client.

### [Basic send with retry enabled](https://github.com/socketlabs/socketlabs-nodejs/blob/master/examples/basic/basicSendWithRetry.js)
This example demonstrates how to use the retry logic with your HTTP client.

### [Basic send complex example](https://github.com/socketlabs/socketlabs-nodejs/blob/master/examples/basic/basicSendComplexExample.js)
This example demonstrates many features of the Basic Send, including adding multiple recipients, adding message and mailing id's, and adding an embedded image.

Expand Down Expand Up @@ -211,6 +214,7 @@ For more information about AMP please see [AMP Project](https://amp.dev/document

<a name="version"></a>
# Version
* 1.2.1 - Adding optional retry logic for Http requests. If configured, the request will retry when certain 500 errors occur (500, 502, 503, 504)
* 1.1.1 - Adding request timeout value on the client for Http requests
* 1.1.0 - Adds Amp Html Support
* 1.0.0 - Initial Release
Expand Down
40 changes: 40 additions & 0 deletions examples/basic/basicSendWithRetry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const { SocketLabsClient, EmailAddress, BasicMessage } = require('../../src/socketlabsClient');
const exampleConfig = require('../exampleConfig');

/**
* Build the message
*/
var message = new BasicMessage();

message.subject = "Sending An Email Through A Proxy";
message.htmlBody = "<html><body><h1>Sending An Email Through A Proxy</h1><p>This is the Html Body of my message.</p></body></html>";
message.textBody = "This is the Plain Text Body of my message.";

message.from = new EmailAddress("from@example.com");

message.to.push("recipient@example.com");

/**
* Create the client
*/
var client = new SocketLabsClient(exampleConfig.ServerId, exampleConfig.ApiKey,
{
optionalProxy: "http://localhost:4433"
});

client.numberOfRetries = 3;

/**
* Send the message
*/
client.requestTimeout = 20;
client.send(message).then(
(res) => {
console.log("Promise resolved: ")
console.log(res)
},
(err) => {
console.log("Promise rejected: ")
console.log(err)
}
);
5 changes: 4 additions & 1 deletion examples/exampleConfig.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
'use strict';

const { endpointUrl } = require("../src/core/retryHandler");

module.exports = {
ServerId: parseInt(process.env.SOCKETLABS_SERVER_ID),
ApiKey: process.env.SOCKETLABS_INJECTION_API_KEY
};
};

Loading