CRM integration service
This is the microservice at the centre of our integration project. It receives the other teams' messages through RabbitMQ, keeps Salesforce and MySQL in sync, then triggers invoicing and mailing.
- Salesforce REST API with OAuth refresh tokens
- XML/XSD schemas check every message
- Runs in Docker; GitHub Actions runs the tests and the build
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;
}
}


