Installation
npm install ensync-client-sdk
Basic Connection
const { EnSyncEngine } = require('ensync-client-sdk');
// Initialize engine (gRPC with TLS)
const engine = new EnSyncEngine("grpcs://node.gms.ensync.cloud");
// Alternative Websocket:
// const engine = new EnSyncEngine("wss://node.gms.ensync.cloud");
// Create authenticated client
const client = await engine.createClient(process.env.APP_KEY, {
appSecretKey: process.env.APP_SECRET_KEY
});
from ensync_sdk import EnSyncEngine
# Initialize engine (gRPC with TLS)
engine = EnSyncEngine("node.gms.ensync.cloud")
# Create authenticated client
client = await engine.create_client(os.environ.get("APP_KEY"), {
"app_secret_key": os.environ.get("APP_SECRET_KEY")
})
Authentication vs Event Targeting
App Key authenticates your connection, while Client ID (appId) targets event delivery:
- App Key: Authenticates who you are when connecting to EnSync
- Client ID: Identifies the recipient when publishing events (this is your appId)
When you publish an event, you specify recipient Client IDs. When partners publish to you, they use your Client ID. Everyone publishes and subscribes on the same bidirectional connection.
Events are always published to specific Client IDs. Even if multiple partners subscribe to the same event type, they only receive events explicitly addressed to their Client ID.
Connection Options
const engine = new EnSyncEngine("grpcs://node.gms.ensync.cloud", {
heartbeatInterval: 30000,
reconnectInterval: 5000,
maxReconnectAttempts: 5
});
engine = EnSyncEngine("node.gms.ensync.cloud", {
"reconnect_interval": 5000,
"max_reconnect_attempts": 10
})
Closing Connections
Always close connections when done to free resources:
// Close just this client
await client.close();
// Close client and engine (if you have no other clients)
await client.close(true);
# Close just this client
await client.close()
# Close client and engine (if you have no other clients)
await client.close(close_engine=True)
Best Practices
- Store credentials in environment variables, never hardcode them
- Use secure TLS connections in production (
grpcs:// or wss://)
- Close connections when done to free resources