0.0.3 • Published 2 years ago

@c0d3x42/vue3-nats v0.0.3

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

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);
})
0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago

0.0.0

2 years ago