CRM integration service
The microservice in the middle of our integration project. It takes messages from the other teams' systems through RabbitMQ, keeps Salesforce and MySQL in sync, and triggers invoicing and mailing.
- Salesforce REST API with OAuth refresh tokens
- Every message validated against XML/XSD schemas
- Runs in Docker, tested and built with GitHub Actions
await this.channel.assertQueue(QUEUE_NAME, { durable: true });
await this.channel.assertQueue(KASSA_QUEUE, { durable: true });
await this.channel.assertQueue(DEAD_LETTER_QUEUE, {
durable: true,
arguments: { 'x-dead-letter-exchange': '' },
});
await this.channel.prefetch(1);
const consume = async (msg) => {
if (msg) {
try {
await this.handleMessage(msg);
} catch (err) {
console.log(`[receiver] Unhandled error in message handler: ${err}`);
}
}
};
this.channel.consume(QUEUE_NAME, consume, { noAck: false });
this.channel.consume(KASSA_QUEUE, consume, { noAck: false });
async _doTokenRefresh() {
const params = new URLSearchParams({
grant_type: 'refresh_token',
client_id: this.clientId,
client_secret: this.clientSecret,
refresh_token: this.refreshToken,
});
const resp = await fetch(SFConnection.TOKEN_URL, {
method: 'POST',
body: params,
});
if (resp.ok) {
return resp.json();
}
const text = await resp.text();
console.log(`[SF Connection] Token refresh failed (${resp.status}): ${text}`);
return null;
}
async apiCall(fn) {
if (!this.connection) return null;
try {
return await fn(this.connection);
} catch (err) {
if (String(err).includes('INVALID_SESSION_ID')) {
console.log('[SF Connection] Session expired, refreshing...');
if (await this.refresh()) {
return await fn(this.connection);
}
}
throw err;
}
}


