Skip to main content

Backend Integration Guide: Delta Sync via MQTT

Panduan implementasi delta sync di mstore-backend untuk mendukung real-time updates ke mobile app.

๐Ÿ“‹ Prerequisites

  • MQTT Broker (EMQX/Mosquitto) sudah running
  • PostgreSQL database
  • Go 1.21+ atau Node.js 18+ (sesuai stack backend)
  • MQTT client library

๐Ÿ—๏ธ Architecture Overview


๐Ÿ”ง Implementation Steps

Step 1: Setup MQTT Client

Go Example:

Node.js Example:


Step 2: Create Event Publisher Service

Go Example:


Step 3: Integrate dengan Business Logic

Example: Product Stock Update

Example: Transaction Creation


Untuk memastikan semua perubahan stock ter-publish, gunakan database triggers:
Kemudian di aplikasi, listen ke pg_notify:

๐Ÿ” Security & ACL Configuration

EMQX ACL Rules

File: /etc/emqx/acl.conf

๐Ÿ“Š Monitoring & Logging

Log Format

Metrics to Track

  • Publish Success Rate: mqtt_publish_success_total / mqtt_publish_total
  • Publish Latency: Time from DB update to MQTT publish
  • Message Size: Average payload size
  • Subscriber Count: Active mobile devices per branch

๐Ÿงช Testing

Manual Test dengan MQTT Client

Integration Test


๐Ÿš€ Deployment Checklist

Backend:

  • MQTT client library installed
  • EventPublisher service implemented
  • Integrated dengan ProductService, InventoryService, TransactionService
  • Environment variables configured
  • Logging & monitoring setup
  • Unit tests passed

MQTT Broker:

  • EMQX/Mosquitto running
  • ACL rules configured
  • SSL/TLS enabled (production)
  • Monitoring dashboard setup

Database:

  • Triggers created (optional)
  • Indexes optimized
  • Backup strategy in place

๐Ÿ“ž Support

Jika ada pertanyaan atau issue:
  1. Check logs di backend & MQTT broker
  2. Verify ACL rules
  3. Test dengan mosquitto_sub/pub
  4. Contact DevOps team

Last Updated: 2025-10-14
Version: 1.0.0
Author: MStore Development Team