Use Cluster Mode for object operations
masterCluster mode allows you to manage multiple OSS clients across different hosts. It currently only supports object operations.
Configuration
Initialize using ClusterClient from ali-oss. You provide an array of client configurations and a schedule strategy.
Scheduling Strategies
roundRobin: The default strategy.masterSlave: Routes requests to a master or slave based on the operation type.
Supported Methods
Get Methods (Uses the schedule to choose an available client):
client.get()client.head()client.getStream()client.list()client.signatureUrl()client.chooseAvailable()client.getACL()
Put Methods (Executes the operation on ALL clients in the cluster):
client.put()client.putStream()client.delete()client.deleteMulti()client.copy()client.putMeta()client.putACL()client.restore()
const Cluster = require('ali-oss').ClusterClient;
const client = Cluster({
cluster: [
{
host: 'host1',
accessKeyId: 'id1',
accessKeySecret: 'secret1'
},
{
host: 'host2',
accessKeyId: 'id2',
accessKeySecret: 'secret2'
}
],
schedule: 'masterSlave' // default is `roundRobin`
});
// listen error event to logging error
client.on('error', function (err) {
console.error(err.stack);
});
// client init ready
client.ready(function () {
console.log('cluster client init ready, go ahead!');
});