Skip to content

Latest commit

 

History

History
35 lines (26 loc) · 1.29 KB

producing-messages.md

File metadata and controls

35 lines (26 loc) · 1.29 KB

RedisSMQ / Docs / Producing Messages

Producing Messages

A Producer instance allows to publish a message to a queue.

You can use a single Producer instance to produce messages, including messages with priority, to one or multiple queues.

Before publishing a message do not forget to set an exchange for the message using ProducibleMessage.setQueue(), setTopic(), or setFanOut(). Otherwise, an error will be returned.

See Message Exchanges for more details.

'use strict';
const {ProducibleMessage, Producer} = require('redis-smq');

const producer = new Producer();

// Always run the producer before producing a message
producer.run((err) => {
   if (err) console.error(err);
   else {
     const msg = new ProducibleMessage();
     msg.setBody({ hello: 'world' })
       .setTTL(3600000) // message expiration (in millis)
       .setQueue('test_queue'); // setting up a direct exchange 
     producer.produce(msg, (err, reply) => {
       if (err) console.error(err);
       else console.log('Successfully produced');
     });
   }
})

See Producer Class for more details.