-
Notifications
You must be signed in to change notification settings - Fork 19
/
simple.ts
38 lines (33 loc) · 963 Bytes
/
simple.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { Schema } from 'avsc';
import { ObjectReadableMock } from 'stream-mock';
import { createCastleStream, StreamKafkaMessage } from '@ovotech/castle-stream';
export interface Event1 {
field1: string;
}
export const Event1Schema: Schema = {
type: 'record',
name: 'Event',
fields: [{ name: 'field1', type: 'string' }],
};
const main = async () => {
const castleStream = createCastleStream({
schemaRegistry: { uri: 'http://localhost:8081' },
kafka: { brokers: ['localhost:29092'] },
consumers: [
{
topic: 'test1',
source: new ObjectReadableMock(['test1', 'test2', 'test3']),
eachMessage: async (message) => {
console.log(message);
},
toKafkaMessage: (message: string): StreamKafkaMessage<Event1> => ({
key: Buffer.from(''),
value: { field1: message },
schema: Event1Schema,
}),
},
],
});
await castleStream.start();
};
main();