Last active
February 11, 2021 19:01
-
-
Save JozefFlakus/6e379a33ff19a40257529dd682e64149 to your computer and use it in GitHub Desktop.
Marble.js 3.0 - microservice example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ๐ publisher - fib.effect.ts | |
const fib$ = r.pipe( | |
r.matchPath('/fib/:number'), | |
r.matchType('GET'), | |
r.useEffect((req$, ctx) => { | |
const client = useContext(ClientToken)(ctx.ask); | |
return req$.pipe( | |
validateRequest, | |
map(req => req.params.number), | |
mergeMap(number => forkJoin( | |
client.send({ type: 'FIB', payload: number + 0 }), | |
client.send({ type: 'FIB', payload: number + 1 }), | |
client.send({ type: 'FIB', payload: number + 2 }), | |
)), | |
map(body => ({ body })), | |
); | |
}), | |
); | |
// ๐ consumer - fib.effect.ts | |
const microservice = createMicroservice({ | |
transport: Transport.AMQP, | |
options: { | |
host: 'amqp://localhost:5672', | |
queue: 'fib_queue', | |
}, | |
listener: messagingListener({ | |
effects: [fib$], | |
}), | |
}); | |
const fib$: MsgEffect = event$ => | |
event$.pipe( | |
matchEvent('FIB'), | |
act(eventValidator$(t.number)), | |
act(event => of(event).pipe( | |
map(event => fib(event.payload)), | |
map(payload => reply(event)({ payload })), | |
)), | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment