@@ -42,18 +42,17 @@ interface ShipmentDelivered {
4242}
4343
4444// ============================================================================
45- // Channel addresses (NATS subjects - using dots as per NATS convention)
46- // Based on AsyncAPI spec addresses converted from slashes to dots
45+ // Channels (keys are AsyncAPI channel IDs, values are NATS subjects)
4746// ============================================================================
4847const CHANNELS = {
4948 // Channels this service PUBLISHES to
50- ORDER_CANCELLED : 'order.cancelled' ,
51- ORDER_COMPLETED : 'order.completed' ,
49+ orderCancelled : 'order.cancelled' ,
50+ orderCompleted : 'order.completed' ,
5251
5352 // Channels this service SUBSCRIBES to
54- ORDER_CREATED : 'order.created' ,
55- PAYMENT_FAILED : 'payment.failed' ,
56- SHIPMENT_DELIVERED : 'shipment.delivered' ,
53+ orderCreated : 'order.created' ,
54+ paymentFailed : 'payment.failed' ,
55+ shipmentDelivered : 'shipment.delivered' ,
5756} as const ;
5857
5958// ============================================================================
@@ -112,8 +111,8 @@ class OrdersService {
112111 sendOrderCancelled ( data : OrderCancelled ) : void {
113112 if ( ! this . nc ) throw new Error ( 'Not connected to NATS' ) ;
114113
115- this . nc . publish ( CHANNELS . ORDER_CANCELLED , this . jc . encode ( data ) ) ;
116- console . log ( `📤 [${ CHANNELS . ORDER_CANCELLED } ] OrderCancelled sent:` , data ) ;
114+ this . nc . publish ( CHANNELS . orderCancelled , this . jc . encode ( data ) ) ;
115+ console . log ( `📤 [${ CHANNELS . orderCancelled } ] OrderCancelled sent:` , data ) ;
117116
118117 // Update internal state
119118 const order = this . orders . get ( data . orderId ) ;
@@ -129,8 +128,8 @@ class OrdersService {
129128 sendOrderCompleted ( data : OrderCompleted ) : void {
130129 if ( ! this . nc ) throw new Error ( 'Not connected to NATS' ) ;
131130
132- this . nc . publish ( CHANNELS . ORDER_COMPLETED , this . jc . encode ( data ) ) ;
133- console . log ( `📤 [ ${ CHANNELS . ORDER_COMPLETED } ] OrderCompleted sent:` , data ) ;
131+ this . nc . publish ( CHANNELS . orderCompleted , this . jc . encode ( data ) ) ;
132+ console . log ( `📤 OrderCompleted sent:` , data ) ;
134133
135134 // Update internal state
136135 const order = this . orders . get ( data . orderId ) ;
@@ -150,7 +149,7 @@ class OrdersService {
150149 * When an order is created (by another service/frontend), track it internally
151150 */
152151 private async handleOrderCreated ( data : OrderCreated ) : Promise < void > {
153- console . log ( `📥 [${ CHANNELS . ORDER_CREATED } ] OrderCreated received:` , {
152+ console . log ( `📥 [${ CHANNELS . orderCreated } ] OrderCreated received:` , {
154153 orderId : data . orderId ,
155154 userId : data . userId ,
156155 totalAmount : data . totalAmount ,
@@ -180,7 +179,7 @@ class OrdersService {
180179 * When payment fails, the order should be cancelled
181180 */
182181 private async handlePaymentFailed ( data : PaymentFailed ) : Promise < void > {
183- console . log ( `📥 [${ CHANNELS . PAYMENT_FAILED } ] PaymentFailed received:` , data ) ;
182+ console . log ( `📥 [${ CHANNELS . paymentFailed } ] PaymentFailed received:` , data ) ;
184183
185184 const order = this . orders . get ( data . orderId ) ;
186185 if ( ! order ) {
@@ -208,7 +207,7 @@ class OrdersService {
208207 * When shipment is delivered, the order should be marked as completed
209208 */
210209 private async handleShipmentDelivered ( data : ShipmentDelivered ) : Promise < void > {
211- console . log ( `📥 [${ CHANNELS . SHIPMENT_DELIVERED } ] ShipmentDelivered received:` , data ) ;
210+ console . log ( `📥 [${ CHANNELS . shipmentDelivered } ] ShipmentDelivered received:` , data ) ;
212211
213212 const order = this . orders . get ( data . orderId ) ;
214213 if ( ! order ) {
@@ -242,7 +241,7 @@ class OrdersService {
242241 if ( ! this . nc ) throw new Error ( 'Not connected to NATS' ) ;
243242
244243 // Subscribe to OrderCreated events
245- const orderCreatedSub = this . nc . subscribe ( CHANNELS . ORDER_CREATED ) ;
244+ const orderCreatedSub = this . nc . subscribe ( CHANNELS . orderCreated ) ;
246245 this . subscriptions . push ( orderCreatedSub ) ;
247246
248247 ( async ( ) => {
@@ -256,10 +255,10 @@ class OrdersService {
256255 }
257256 } ) ( ) ;
258257
259- console . log ( `📬 Subscribed to: ${ CHANNELS . ORDER_CREATED } ` ) ;
258+ console . log ( `📬 Subscribed to: ${ CHANNELS . orderCreated } ` ) ;
260259
261260 // Subscribe to PaymentFailed events
262- const paymentFailedSub = this . nc . subscribe ( CHANNELS . PAYMENT_FAILED ) ;
261+ const paymentFailedSub = this . nc . subscribe ( CHANNELS . paymentFailed ) ;
263262 this . subscriptions . push ( paymentFailedSub ) ;
264263
265264 ( async ( ) => {
@@ -273,10 +272,10 @@ class OrdersService {
273272 }
274273 } ) ( ) ;
275274
276- console . log ( `📬 Subscribed to: ${ CHANNELS . PAYMENT_FAILED } ` ) ;
275+ console . log ( `📬 Subscribed to: ${ CHANNELS . paymentFailed } ` ) ;
277276
278277 // Subscribe to ShipmentDelivered events
279- const shipmentDeliveredSub = this . nc . subscribe ( CHANNELS . SHIPMENT_DELIVERED ) ;
278+ const shipmentDeliveredSub = this . nc . subscribe ( CHANNELS . shipmentDelivered ) ;
280279 this . subscriptions . push ( shipmentDeliveredSub ) ;
281280
282281 ( async ( ) => {
@@ -290,7 +289,7 @@ class OrdersService {
290289 }
291290 } ) ( ) ;
292291
293- console . log ( `📬 Subscribed to: ${ CHANNELS . SHIPMENT_DELIVERED } ` ) ;
292+ console . log ( `📬 Subscribed to: ${ CHANNELS . shipmentDelivered } ` ) ;
294293 }
295294
296295 // =========================================================================
@@ -340,13 +339,13 @@ class OrdersService {
340339 console . log ( '═' . repeat ( 60 ) ) ;
341340
342341 console . log ( '\n📤 Publishing to channels:' ) ;
343- console . log ( ` • ${ CHANNELS . ORDER_CANCELLED } ` ) ;
344- console . log ( ` • ${ CHANNELS . ORDER_COMPLETED } ` ) ;
342+ console . log ( ` • ${ CHANNELS . orderCancelled } ` ) ;
343+ console . log ( ` • ${ CHANNELS . orderCompleted } ` ) ;
345344
346345 console . log ( '\n📥 Subscribing to channels:' ) ;
347- console . log ( ` • ${ CHANNELS . ORDER_CREATED } ` ) ;
348- console . log ( ` • ${ CHANNELS . PAYMENT_FAILED } ` ) ;
349- console . log ( ` • ${ CHANNELS . SHIPMENT_DELIVERED } ` ) ;
346+ console . log ( ` • ${ CHANNELS . orderCreated } ` ) ;
347+ console . log ( ` • ${ CHANNELS . paymentFailed } ` ) ;
348+ console . log ( ` • ${ CHANNELS . shipmentDelivered } ` ) ;
350349
351350 await this . setupSubscriptions ( ) ;
352351
0 commit comments