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
var avroSchema = { | |
type: 'record', | |
name: 'MyClass', | |
namespace: 'com.test.avro', | |
fields: [ | |
{ | |
name: 'anonymousId', | |
type: 'string' | |
}, | |
{ | |
name: 'channel', | |
type: 'string' | |
}, | |
{ | |
name: 'ip', | |
type: 'string' | |
}, | |
{ | |
name: 'userAgent', | |
type: 'string' | |
}, { | |
name: 'name', | |
type: 'string' | |
}, { | |
name: 'email', | |
type: 'string' | |
}, { | |
name: 'messageId', | |
type: 'string' | |
}, { | |
name: 'receivedAt', | |
type: 'string' | |
}, { | |
name: 'sentAt', | |
type: 'string' | |
}, { | |
name: 'timestamp', | |
type: 'string' | |
}, { | |
name: 'pageName', | |
type: 'string' | |
}, { | |
name: 'title', | |
type: 'string' | |
}, { | |
name: 'event', | |
type: 'string' | |
}, { | |
name: 'userId', | |
type: 'string' | |
}, { | |
name: 'version', | |
type: 'string' | |
}, { | |
name: 'apiKey', | |
type: 'string' | |
}, { | |
name: 'destinationBQ', | |
type: 'string' | |
}] | |
}; | |
var obj = { | |
anonymousId: "507f191e810c19729de860ea", | |
channel: "browser", | |
ip: "8.8.8.8", | |
userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36", | |
name: "Peter Gibbons", | |
email: "peter@initech.com", | |
messageId: "022bb90c-bbac-11e4-8dfc-aa07a5b093db", | |
receivedAt: "2015-02-23T22:28:55.387Z", | |
sentAt: "current time", | |
timestamp: "India", | |
pageName: "Home Page", | |
title: "Analytics Academy", | |
event: "Course Clicked", | |
userId: "97980cfea0067", | |
version: "1.1", | |
apiKey: "jkhdhjasfgyugwqyewytyiuuiegwyhds", | |
destinationBQ: "projectName:dataset.tableName" | |
} | |
pubsubClient | |
.topic(topicName) | |
.publisher() | |
.publish(Buffer.from(JSON.stringify(avroSchema)),obj) | |
.then(results => { | |
console.log(results); | |
return results; | |
}) | |
.catch(err => { | |
console.error('ERROR:', err); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment