@onlineapps/cookbook-router 1.0.12 → 1.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/router.js +29 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onlineapps/cookbook-router",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "description": "Message routing for cookbook workflows - handles service discovery and queue routing",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/router.js CHANGED
@@ -178,6 +178,35 @@ class CookbookRouter {
178
178
  };
179
179
  }
180
180
 
181
+ /**
182
+ * Route message directly to a specific service
183
+ * @param {string} serviceName - Target service name
184
+ * @param {Object} message - Workflow message to send
185
+ * @returns {Promise<void>}
186
+ */
187
+ async routeToService(serviceName, message) {
188
+ const { logger } = this.options;
189
+
190
+ if (!serviceName || typeof serviceName !== 'string') {
191
+ throw new Error('[CookbookRouter] routeToService - serviceName is required and must be a string');
192
+ }
193
+ if (!message || typeof message !== 'object') {
194
+ throw new Error('[CookbookRouter] routeToService - message is required and must be an object');
195
+ }
196
+
197
+ // Verify service is available
198
+ const isAvailable = await this.serviceDiscovery.isServiceAvailable(serviceName);
199
+ if (!isAvailable) {
200
+ throw new Error(`[CookbookRouter] Service not available: ${serviceName}`);
201
+ }
202
+
203
+ // Send to service workflow queue
204
+ const queueName = `${serviceName}.workflow`;
205
+ logger.info(`[CookbookRouter] Routing to service: ${queueName}`);
206
+
207
+ await this.queueManager.publish(queueName, message);
208
+ }
209
+
181
210
  /**
182
211
  * Handle retry logic for steps
183
212
  * @param {Object} step - Step to retry