File tree Expand file tree Collapse file tree 4 files changed +46
-6
lines changed
Expand file tree Collapse file tree 4 files changed +46
-6
lines changed Original file line number Diff line number Diff line change 1+ /* eslint-disable */
12import kafka from "./client" ;
23
34( async ( ) => {
Original file line number Diff line number Diff line change 1+ /* eslint-disable */
12import "dotenv/config" ;
23import { Kafka } from "kafkajs" ;
34
Original file line number Diff line number Diff line change 1+ /* eslint-disable */
2+ import { CloudEvent , Kafka } from "cloudevents" ;
3+ import readline from "readline" ;
4+ import kafka from "./client" ;
5+
6+ const rl = readline . createInterface ( {
7+ input : process . stdin ,
8+ output : process . stdout ,
9+ } ) ;
10+
11+ ( async ( ) => {
12+ const producer = kafka . producer ( ) ;
13+ await producer . connect ( ) ;
14+
15+ rl . setPrompt ( "> " ) ;
16+ rl . prompt ( ) ;
17+ rl . on ( "line" , async ( line ) => {
18+ const event = new CloudEvent ( {
19+ source : "cloudevents-producer" ,
20+ type : "events.cloudevents.test" ,
21+ datacontenttype : "text/plain" ,
22+ partitionkey : "1" ,
23+ data : line ,
24+ } ) ;
25+
26+ const message = Kafka . structured ( event ) ;
27+
28+ console . log ( "Sending CloudEvent:" , message ) ;
29+
30+ await producer . send ( {
31+ topic : "events.cloudevents.test" ,
32+ messages : [ message ] ,
33+ } ) ;
34+ rl . prompt ( ) ;
35+ } ) ;
36+
37+ rl . on ( "close" , async ( ) => {
38+ await producer . disconnect ( ) ;
39+ } ) ;
40+ } ) ( ) ;
Original file line number Diff line number Diff line change 77 "strict" : true ,
88 "noImplicitAny" : true ,
99 "moduleResolution" : " node" ,
10- "esModuleInterop" : true ,
10+ "esModuleInterop" : true
1111 },
1212 "include" : [
1313 " src/**/*.ts" ,
14- " src/**/*.js"
14+ " src/**/*.js" ,
1515 ],
16- "exclude" : [
17- " node_modules"
18- ]
19- }
16+ "exclude" : [" node_modules" ]
17+ }
You can’t perform that action at this time.
0 commit comments