Using Apache Avro in javascript

Is there a way to use Avro on the client side through javascript and REST or RPC or websocket?

If so, using the js library?

+8
javascript avro
source share
2 answers

avsc is a pure JavaScript implementation of the Avro specification , and this may be the solution you are looking for.

avsc is compatible with all versions of node.js with 0.11 and major browsers via the browser (see the full compatibility table here ). For convenience, you can also find compiled distributions with releases (but please post your own copy).

I made a small lab and shared my experimental coding with avsc in github repo: avro-rest-js , in this demo project there are examples of both client and server-rest-APIs in javascript-exchange of avro-buffers in request / response.

For an example of using avsc for the RPC website, see the https://github.com/mtth/verdon sample Avro Remote Logging service running on the WebSocket server and the corresponding client.

+2
source share

And there is a question about ws connections. I want to establish one connection for each user and make it live before reconnecting. The following code that I saw on the network is something bad, because I think that with each action, creating a client connection and sending a message and then destroying it is not a good practice. Please help. and do not send me official documents.

const actions = { connectWsForUserTracking({state, commit},data){ const protocol = avro.readProtocol(' protocol RemoteLogService { void log(enum { INFO, WARNING } level, bytes message); } '); const logClient = avro.Service.forProtocol(protocol) .createClient({buffering: true,transport: ws('ws://localhost:8026')}); setTimeout(function () { logClient.destroyChannels(); }, 1000); }, trackingMessageContent(context,data){ import('../../avroSchema/v1/schema.js').then(schemaConfig => { console.log(schemaConfig); const exactType = avro.Type.forSchema(schemaConfig.default); //Pretvaranje u binarni tip i dispatch na akciju za slanje if(exactType.isValid(data)){ const buf = exactType.toBuffer(data); context.dispatch('connectWsForUserTracking',buf) } }).catch(e => { console.log(e) }) }, 

}

0
source share

All Articles