Created
December 14, 2017 13:41
-
-
Save icebob/ec8385da7c9cea2ae9ebc72df2292d1c to your computer and use it in GitHub Desktop.
Simple event storing service for Moleculer
This file contains 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
"use strict"; | |
let ServiceBroker = require("../src/service-broker"); | |
let broker = new ServiceBroker({ | |
logger: true, | |
logLevel: "debug", | |
}); | |
broker.createService({ | |
name: "event-store", | |
events: { | |
"ES.**"(payload, sender, event) { | |
this.store({ | |
event, | |
payload | |
}).then(() => { | |
this.broker.emit(event.slice(3), payload); | |
}); | |
} | |
}, | |
methods: { | |
store(event) { | |
this.logger.info(`STORE '${event.event}' event.`); | |
// Do something... | |
return Promise.resolve(event); | |
} | |
} | |
}); | |
broker.createService({ | |
name: "target", | |
events: { | |
"user.created"(payload) { | |
this.logger.info("User created event RECEIVED!", payload); | |
} | |
} | |
}); | |
broker.start() | |
.then(() => broker.emit("ES.user.created", { name: "John" })); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment