Part 6: Test and Demo - Ktor Native Worker Tutorial
This final part shows how to set up, run, and test the complete Ktor Native worker application across JVM and native platforms.
重點摘要
Run in JVM for development and build native executables for production
Integrates RabbitMQ for queuing and Firebase Cloud Messaging for notifications
Test with curl/HTTPie/Postman, monitor RabbitMQ, and compare JVM vs native performance
This final chapter explains how to run, test, and deploy the Ktor Native worker application. It covers prerequisites (RabbitMQ, Firebase service account, FCM device token), running in JVM for development and building native executables for macOS, Linux, and Windows for production, and configuring via environment variables. The tutorial details the request-to-delivery flow: HTTP POST to /api/notifications, publishing a SendNotificationEvent to RabbitMQ, consuming messages in a worker, and sending notifications via FCM. It shows testing methods using curl, HTTPie, Postman, simple load tests and Apache Bench, and how to monitor RabbitMQ through the management UI. Finally, it compares startup time, memory usage, and throughput between JVM and native builds, and discusses Docker/Kubernetes deployment, scaling workers, and common troubleshooting steps.
第六部分:测试与演示 — Ktor Native Worker 教程
本节展示如何在 JVM 与原生平台上配置、运行并测试完整的 Ktor Native worker 应用。
重點摘要
开发使用 JVM,生产构建原生可执行档以缩短启动时间并降低内存占用
整合 RabbitMQ 消息队列与 Firebase Cloud Messaging 发送通知
提供 curl/HTTPie/Postman 测试、性能比较与部署(Docker、Kubernetes)指引
本部分介绍如何设置、运行和验证 Ktor Native worker 应用。包含先决条件(RabbitMQ、Firebase 服务帐号、FCM 设备 token),以及在 JVM 环境开发与为 macOS、Linux、Windows 构建原生可执行文件的流程。说明通过环境变量配置,API 测试示例(curl、HTTPie、Postman)、请求流程(POST /api/notifications → 发布至 RabbitMQ → worker 消费 → 调用 FCM 发送推送)和使用 RabbitMQ 管理界面监控连接、交换器与队列。还涵盖错误情境检测、简单负载测试与 Apache Bench、JVM 与原生在启动时间和内存使用上的比较,以及 Docker/Kubernetes 部署、水平扩展与常见故障排除建议。
第六部分:測試與示範 — Ktor Native Worker 教學
本章示範如何在 JVM 與原生平台上設定、執行並測試完整的 Ktor Native worker 應用程式。
重點摘要
開發時以 JVM 執行,生產環境建置 macOS/Linux/Windows 原生執行檔
使用 RabbitMQ 作為佇列,透過 Firebase Cloud Messaging 送出推播
可用 curl/HTTPie/Postman 測試,並比較 JVM 與原生的效能與資源使用
本篇說明如何啟動、測試與部署 Ktor Native worker。列出執行前需準備的 RabbitMQ、Firebase 服務帳戶與 FCM 裝置 token,並示範在 JVM(開發)與各平台原生可執行檔(macOS、Linux、Windows)上執行及建置流程。介紹環境變數設定、API 測試方式(curl、HTTPie、Postman)、訊息流:由 /api/notifications 發出 POST、將 SendNotificationEvent 發佈至 RabbitMQ、由 consumer 處理並呼叫 FCM 發送推播。也涵蓋 RabbitMQ 監控、簡易負載測試與 Apache Bench、JVM 與原生的啟動時間與記憶體差異、Docker/Kubernetes 部署、水平擴充與常見除錯步驟。