CRM-integratieservice
Dit is de microservice in het hart van ons integratieproject. Hij ontvangt de berichten van de andere teams via RabbitMQ, houdt Salesforce en MySQL gelijk en start daarna facturatie en mailing.
- Salesforce REST API met OAuth-refreshtokens
- XML/XSD-schema's controleren elk bericht
- Draait in Docker; GitHub Actions voert de tests en de build uit
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;
}
}


