Search…
⌃K
Links

Example: Consumer.ts

For Typescript
import memphis from 'memphis-dev';
import { Memphis, Message } from 'memphis-dev/types';
​
(async function () {
let memphisConnection: Memphis;
​
try {
memphisConnection = await memphis.connect({
host: '<memphis-host>',
username: '<application type username>',
connectionToken: '<broker-token>'
});
​
const consumer = await memphisConnection.consumer({
stationName: '<station-name>',
consumerName: '<consumer-name>',
consumerGroup: ''
});
​
consumer.on('message', (message: Message) => {
console.log(message.getData().toString());
message.ack();
const headers = message.getHeaders()
});
​
consumer.on('error', (error) => {
console.log(error);
});
} catch (ex) {
console.log(ex);
if (memphisConnection) memphisConnection.close();
}
})();