I am trying to use the Google Cloud Pub/Sub Lite service in NodeJS using grpc. However, I am stuck with the following error : {"code":14,"details":"502:Bad Gateway","metadata":{"internalRepr":{},"options":{}}} when I try to publish a message in the queue.
I can't manage to make it works, can anyone help ?
Here is my code:
async function message() {
const protoDir = "node_modules/google-proto-files/google/cloud/pubsublite/v1/publisher.proto";
const packageDefinition = protoLoader.loadSync(protoDir, {
includeDirs: [
protos.getProtoPath('..'),
'node_modules/google-proto-files/google/cloud/pubsublite/v1/'
],
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
});
const packageObject = grpc.loadPackageDefinition(packageDefinition);
const package = packageObject.google.cloud.pubsublite.v1;
const Publisher = package.PublisherService
var ssl_creds = grpc.credentials.createSsl();
const gAuth = new GoogleAuth({
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
});
gAuth.getApplicationDefault(function(err, auth) {
var call_creds = grpc.credentials.createFromGoogleCredential(auth);
var combined_creds = grpc.credentials.combineChannelCredentials(ssl_creds, call_creds);
const client = new Publisher('europe-west1-pubsublite.googleapis.com', combined_creds)
const initial = {
topic:'projects/projectId/locations/europe-west1-b/topics/poc-topic',
}
var pub = {
request_type: initial
}
const pubb = client.Publish(function(err, res) {
console.log("ERROR --> " + err)
});
pubb.on('data', function(data) {
console.log("Data --> " + data);
});
pubb.on('end', function() {
console.log('end ')
});
pubb.on('error', function(e) {
console.log('Error ' + e)
});
pubb.on('status', function(status) {
console.log('Status ' + JSON.stringify(status))
pubb.write(pub);
});
});
}