File tree Expand file tree Collapse file tree 2 files changed +3
-29
lines changed
src/services/service-mesh Expand file tree Collapse file tree 2 files changed +3
-29
lines changed Original file line number Diff line number Diff line change @@ -4354,3 +4354,5 @@ Error: Command failed: ./watch.sh 80 8888
43544354}
43554355watching ./src
43564356watching ./src
4357+ change services/service-mesh/nats-mesh.js
4358+ change services/service-mesh/nats-mesh.js
Original file line number Diff line number Diff line change 1- const { connect, StringCodec } = require ( 'nats' )
2-
3- const sc = StringCodec
4-
5- exports . subscribe = async function ( eventName , callback ) {
6- // to create a connection to a nats-server:
7- const nc = await connect ( { servers : 'demo.nats.io:4222' } )
8-
9- // create a simple subscriber and iterate over messages
10- // matching the subscription
11- const sub = nc . subscribe ( eventName )
12- ; ( async ( ) => {
13- for await ( const m of sub ) {
14- const message = JSON . parse ( sc . decode ( m . data ) )
15- console . log ( `[${ sub . getProcessed ( ) } ]: ${ message } ` )
16- callback ( eventName , message )
17- }
18- console . log ( 'subscription closed' )
19- } ) ( )
20- }
21-
22- exports . publish = function ( event , broker ) {
23- console . log ( 'calling NATS publish' )
24- nc . publish ( event . eventName , sc . encode ( JSON . stringify ( event ) ) )
25- }
26-
27- exports . attachServer = function ( server ) {
28- console . log ( 'web socket server attached to NATS' , server )
29- }
1+ //
You can’t perform that action at this time.
0 commit comments