1.0.1 • Published 17 days ago

trpc-mqtt v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
17 days ago

Usage

1. Install trpc-mqtt.

# npm
npm install trpc-mqtt mqtt@5
# yarn
yarn add trpc-mqtt mqtt@5
# pnpm
pnpm add trpc-mqtt mqtt@5

2. Use mqttLink in your client code.

import { createTRPCProxyClient } from '@trpc/client';
import { mqttLink } from 'trpc-mqtt/link';
import mqtt from 'mqtt';

import type { AppRouter } from './appRouter';

const client = mqtt.connect('mqtt://localhost');

export const trpc = createTRPCProxyClient<AppRouter>({
  links: [
    mqttLink({
      client,
      requestTopic: "rpc/request"
    })
  ],
});

Note: don't forget to clean up the MQTT client when you're done, using client.end().

3. Use createMQTTHandler to handle incoming calls via mqtt on the server.

import { createMQTTHandler } from 'trpc-mqtt/adapter';

import { appRouter } from './appRouter';

const client = mqtt.connect('mqtt://localhost');

createMQTTHandler({ 
  client,
  requestTopic: "rpc/request",
  router: appRouter
});

Note: same as with the link, don't forget to clean up the MQTT client when you're done, using client.end().

License

Distributed under the MIT License. See LICENSE for more information.

Special thanks

This project is a fork of trpc-rabbitmq by Alex Brazier

1.0.1

17 days ago

1.0.0

17 days ago

0.1.7

18 days ago

1.0.6

10 months ago

0.1.6

10 months ago

0.1.5

11 months ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

1.2.0

1 year ago

0.1.1

1 year ago