@@ -7,9 +7,9 @@ require('dotenv').config();
7
7
// Initialize Kafka client and producer
8
8
const openseaApiKey = process . env . OPENSEA_API_KEY ;
9
9
const kafka = new Kafka ( {
10
- clientId : 'test-producer' ,
11
- brokers : [ 'localhost:9097' ] ,
12
- } ) ;
10
+ clientId : 'test-producer' ,
11
+ brokers : [ 'localhost:9097' ] ,
12
+ } ) ;
13
13
const producer = kafka . producer ( ) ;
14
14
const admin = kafka . admin ( ) ;
15
15
@@ -34,52 +34,52 @@ async function createTopic() {
34
34
35
35
// Test OpenSea Producer
36
36
async function testOpenSeaProducer ( ) {
37
- const client = new OpenSeaStreamClient ( {
38
- token : openseaApiKey ,
39
- network : Network . MAINNET ,
40
- onError : ( err ) => console . error ( 'OpenSea Stream Error:' , err ) ,
41
- logLevel : 'info' ,
42
- connectOptions : {
43
- transport : WebSocket ,
44
- sessionStorage : LocalStorage
45
- }
46
- } ) ;
37
+ const client = new OpenSeaStreamClient ( {
38
+ token : openseaApiKey ,
39
+ network : Network . MAINNET ,
40
+ onError : ( err ) => console . error ( 'OpenSea Stream Error:' , err ) ,
41
+ logLevel : 'info' ,
42
+ connectOptions : {
43
+ transport : WebSocket ,
44
+ sessionStorage : LocalStorage
45
+ }
46
+ } ) ;
47
47
48
- let eventCount = 0 ;
49
- const maxEvents = 10 ;
48
+ let eventCount = 0 ;
49
+ const maxEvents = 10 ;
50
50
51
- const eventPromise = new Promise ( ( resolve ) => {
52
- producer . connect ( ) ;
53
- client . onItemSold ( '*' , async ( event ) => {
54
- console . log ( 'Received Item Sold Event:' , eventCount , event ) ;
55
- eventCount ++ ;
51
+ const eventPromise = new Promise ( ( resolve ) => {
52
+ producer . connect ( ) ;
53
+ client . onItemSold ( '*' , async ( event ) => {
54
+ console . log ( 'Received Item Sold Event:' , eventCount , event ) ;
55
+ eventCount ++ ;
56
56
57
- // Send event to Kafka
58
- try {
59
- await producer . send ( {
60
- topic : 'test-os_event' ,
61
- messages : [ { value : JSON . stringify ( event ) } ] ,
62
- } ) ;
63
- } catch ( error ) {
64
- console . error ( 'Error sending event to Kafka:' , error ) ;
65
- }
57
+ // Send event to Kafka
58
+ try {
59
+ await producer . send ( {
60
+ topic : 'test-os_event' ,
61
+ messages : [ { value : JSON . stringify ( event ) } ] ,
62
+ } ) ;
63
+ } catch ( error ) {
64
+ console . error ( 'Error sending event to Kafka:' , error ) ;
65
+ }
66
66
67
- if ( eventCount >= maxEvents ) {
68
- console . log ( 'Received 10 events. Disconnecting from OpenSea Stream API and Kafka...' ) ;
69
- resolve ( ) ;
70
- }
67
+ if ( eventCount >= maxEvents ) {
68
+ console . log ( 'Received 10 events. Disconnecting from OpenSea Stream API and Kafka...' ) ;
69
+ resolve ( ) ;
70
+ }
71
+ } ) ;
71
72
} ) ;
72
- } ) ;
73
73
74
- // Simulate connection (if needed)
75
- client . connect ( ) ;
74
+ // Simulate connection (if needed)
75
+ client . connect ( ) ;
76
76
77
- // Wait until 10 events are received
78
- await eventPromise ;
77
+ // Wait until 10 events are received
78
+ await eventPromise ;
79
79
80
- // Disconnect the client
81
- client . disconnect ( ) ;
82
- await producer . disconnect ( ) ;
80
+ // Disconnect the client
81
+ client . disconnect ( ) ;
82
+ await producer . disconnect ( ) ;
83
83
}
84
84
85
85
// Run tests
0 commit comments