1.6.2 • Published 3 years ago

mq-wrapper v1.6.2

Weekly downloads
-
License
-
Repository
-
Last release
3 years ago

MQ-wrapper

Cox2m MQ-wrapper is a wrapper that can run in NodeJS and can be used with TypeScript and JavaScript. Its goal is to always support the latest JavaScript features and provide additional features that help you to develop any kind of application that uses messages queues (In this first phase only RabbitMQ and Google's Pubsub).

Pubsub example

const topicName = 'test-topic';
const subscriptionName = 'test-subscription';

async function mainPubsub() {
  // 🎛 connection configuration
  const connectionOptions: ConnectionOptions = {
    type: 'pubsub',
    port: 8085,
  };
  const messageQueueService = new MessageQueueService(connectionOptions);
  const pubsubInstance = messageQueueService.createConnection();
  await pubsubInstance.connect();
  // 🏃🏻‍♂️ emit messages
  await pubsubInstance.emit({ message: 'Hello from topic' }, topicName);
  // 🎧 listen for messages
  await pubsubInstance.listen(subscriptionName, topicName, {
    // 📨 custom on message function
    onMessage(msg: any): void {
      const response = msg.payload;
      console.log('------------>', response);
    },
    // 🔧 custom options
    options: {
      autoAck: true,
    },
  });
}

mainPubsub();
1.6.2

3 years ago