@c0d3x42/vue3-nats
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

vue3 composable for NATS

  • connects to NATS using a websocket
  • publish/subscribe to subjects
  • reactive

Setup App.vue

import { createNats } from '@c0d3x42/vue3-nats'
import { createApp } from 'vue';
import App from 'App.vue';

createApp(App).use(createNats({servers: ['ws://localhost:8443']}));

Components

Publishing

import { publish } from '@c0d3x42/vue3-nats';
import { StringCodec } from 'nats.ws';
const sc = StringCodec();
publish("some.subject", sc.encode("hello from vue3"));

Subscribing

import { subscribe } from '@c0d3x42/vue3-nats';

const { msg } = subscribe("some.subject");
watch(msg, (m) => {
  console.log("msg received", m.data)
})

Request/Response

import { request } from '@c0d3x42/vue3-nats';
import { StringCodec } from 'nats.ws';
const sc = StringCodec();

request("req.res.subject", sc.encode("some payload"))
.then(msg => {
  console.log("response was", msg.data);
})

Readme

Keywords

none

Package Sidebar

Install

npm i @c0d3x42/vue3-nats

Weekly Downloads

4

Version

0.0.3

License

MIT

Unpacked Size

51.7 kB

Total Files

8

Last publish

Collaborators

  • c0d3x42