0.1.2 • Published 8 months ago

@raprincis/messaging-handler v0.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

Solace Event Handler

Permit to Pub Sub to Solace Event broker

Use

Use Factory Method

    import { MessagingConnectionOptions, MessagingEventHandlers, MessagingFactory, MessagingOptions, MessagingType } from "../lib/Messaging.js";

    const defaultConnection: MessagingConnectionOptions = {
        clientId: 'raprincis',
        hostname: process.env.SOLACE_HOSTNAME,
        port: parseInt(process.env.SOLACE_AMQP_PORT, 10),
        username: process.env.SOLACE_USERNAME,
        password: process.env.SOLACE_PASSWORD,
    }

    const createHandler  = (messagingType: MessagingType): MessagingEventHandlers => ({
        connected () {
            console.log(`[${messagingType}] - Connected`);
        },
        subscribed({ name, type }) {
            console.log(`[${messagingType}] - Subscribed to ${type} ${name}`)
        },
        message({ subscription, payload }) {
            console.log(`[${messagingType}] - Message happens on ${subscription.name} : ${payload.toString()}`);
        }
    })


    const amqp = await MessagingFactory.create("AMQP", {
        ...defaultConnection,
        subscriptions: [{
            name: 'myQueue', type: 'queue'
        }, {
            name: 'weather', type: 'topic'
        }],
        handlers: createHandler("AMQP")
    })

    const mqtt = await MessagingFactory.create("MQTT", {
        ...defaultConnection,
        port: parseInt(process.env.SOLACE_MQTT_PORT, 10),
        subscriptions: ["try-me"],
        handlers: createHandler("MQTT")
    })
0.1.2

8 months ago

0.1.1

8 months ago

0.1.0

8 months ago