Hi Guys,
Is it possible to run a Zeebe client on a JS cliente app ?
I Tried to use the zeebe-node in a Vue3 app, but it does not work.
The zeebe-node just worked on a NodeJs server side app.
There any zeebe client that works on a Client Js APP ?
Thanks!
jwulf
January 27, 2021, 4:55am
2
Hi @MrBorges - the web browser cannot make a gRPC connection, so you need a server-side component to do it. You can use either a Node application using the zeebe-node
client and communication with your front-end via REST or WebSockets, or else using grpc-web , which needs a proxy.
Josh
1 Like
Here is working example:
const { ZBClient, Duration, ZBLogger } = require('zeebe-node');
const express = require('express');
const WebSocket = require('ws');
const { router } = require ('./js/router.js');
const url = process.env.ZeebeUrl || 'gateway:26500';
const timeout = process.env.ResponseTimeout || 60000;
const loglevel = process.env.LogLevel || 'INFO';
const tasktype = process.env.TaskType || 'service-task';
console.log('Zeebe Node worker is starting...')
const app = express();
const port = 3000;
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
const server = app.listen(port, () =>
console.log(`Zeebe REST handler listening on port ${port}!`)
);
// Create websocket server to accept commands and return async api result data
console.log('Zeebe Websocket server listening on port 8080...');
This file has been truncated. show original
Rest+websocket node.js server
// Camunda and Zeebe web client to websocket server
class CamundaClient {
constructor(url) {
this.url = this.transformUrl(url);
this.socket = null;
this.processId = null;
this.callback = null;
};
setUrl (url) {
url = this.transformUrl (url);
if (this.url != url) {
if (this.socket && this.socket.readyState == 1) {
this.socket.close ();
this.socket = new WebSocket(url, ["Camunda"]);
this.socket.camunda = this;
if (this.processId) {
this.socket.send (JSON.stringify({command: 'subscribe', channel: 'Camunda', processId: this.processId}));
}
}
This file has been truncated. show original
Websocket client sending start process and publish message from browser web part and consuming data from external task throght websocket connection.
2 Likes