How solacelabs/solace-tryme-cli works
Project type and purpose
• This is a full-feature Node.js/TypeScript CLI tool for messaging and streaming operations on a Solace PubSub+ Broker.
• It supports standard messaging commands (send, receive, request, reply), resource management (queues, profiles via SEMP), and an AsyncAPI-driven event-feed generator that uses Faker.js for mock data.
File structure
• Top-level:
– bin/index.js: CLI bootstrap (shebang to load compiled src/index.js).
– src/: all TypeScript source.
• src/index.ts: entrypoint – sets up Commander.js and loads commands.
• src/common/: low-level client wrappers (publish, receive, queue-client, etc.).
• src/lib/: command implementations (feed-generate, feed-run, manage-*, messaging commands).
• src/utils/: helpers (config loader, logger, AsyncAPI parser, Faker integration, CLI event handlers).
• src/types/: TypeScript definitions.
– public/: static website UI for “Feed Portal” (HTML/JS using MQTTSolaceClient.js, Paho, etc.).
– documentation/: Markdown guides.
– scripts/: install/update helper scripts.
– sample-config/: example JSON configuration.
README for additional insights
• Uses Commander.js for CLI parsing.
• Two external interfaces:
– Messaging API: WebSocket connection to broker for pub/sub.
– Management API: HTTP(S) SEMPv2 REST calls for resource CRUD.
• Feed functionality:
– Input: AsyncAPI document.
– Processing: AsyncAPI parser + Faker.js + user-defined data rules.
– Output: outbound events to broker.
Main components
A. CLI Application
– Commander.js Command Parser
– Config Manager (loads/stores ~/.stm config)
– Command Modules (send, receive, request, reply, config, manage, feed)
B. Core Libraries
– Messaging Client (PubSub+ JavaScript API over WebSocket)
– Management Client (HTTP client to SEMPv2 REST)
– AsyncAPI Parser & Data Generator (Faker.js + feed-datarules)
– Common Clients (queue-client, publish-client, etc.)
C. File System
– AsyncAPI Documents (user-provided)
– Configuration Files (~/.stm JSON)
– Feed definition files (import/export)
D. External Services
– Solace PubSub+ Broker (WebSocket messaging endpoint)
– Solace PubSub+ Broker SEMPv2 API (HTTP REST)
E. Static Feed Portal UI (optional)
– Hosted static files (public/*.html, JS libs)
– In-browser MQTT/WebSocket client (Paho, MQTTSolaceClient.js)
Relationships & interactions
• CLI → Config Manager: read/write command settings
• CLI → Command Module → Core Library
– Messaging commands → Messaging Client → WebSocket → Broker
– Manage commands → Management Client → HTTP REST → Broker SEMP API
– Feed commands:
• preview/generate → AsyncAPI Parser + Faker.js → local files
• run → uses Messaging Client to stream events
• Static UI → In-browser MQTTSolaceClient.js → WebSocket → Broker
Architectural patterns & design principles
• Modular CLI: separate Command Parser, Core Libraries, and low-level clients
• Dependency injection via utils/config → each client gets connection params
• Reusable common clients for messaging & management
• Feed pipeline: parse → transform (Faker rules) → output (publish)
• Clear separation: CLI logic vs. business logic vs. transport layer
• Node.js & TypeScript
• Commander.js (CLI parsing)
• PubSub+ JavaScript API (WebSocket messaging)
• Axios or built-in HTTP client for SEMPv2
• AsyncAPI Parser + Faker.js (data generation)
• Static UI libs: Paho-MQTT.js, Bootstrap, jQuery
Don’t overthink—capture all modules as components
• Bin (CLI bootstrap)
• Config Manager
• Commander.js parser
• Each command group (Messaging, Manage, Feed)
• Common clients sub-components
• Utils (logger, chalk, parse)
• External endpoints