Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
weyoss committed Aug 3, 2022
1 parent 208934b commit 51dfd16
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 53 deletions.
34 changes: 18 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,25 +141,27 @@ Before publishing a message do not forget to set the destination queue of the me
'use strict';
const {Message, Producer} = require('redis-smq');

const message = new Message();

message
.setBody({hello: 'world'})
.setTTL(3600000) // in millis
.setQueue('test_queue');

message.getId() // null

const producer = new Producer();
producer.produce(message, (err) => {
if (err) console.log(err);
else {
const msgId = message.getId(); // string
console.log('Successfully produced. Message ID is ', msgId);
}
});
producer.run((err) => {
if (err) throw err;
const message = new Message();
message
.setBody({hello: 'world'})
.setTTL(3600000) // in millis
.setQueue('test_queue');
message.getId() // null
producer.produce(message, (err) => {
if (err) console.log(err);
else {
const msgId = message.getId(); // string
console.log('Successfully produced. Message ID is ', msgId);
}
});
})
```

Starting with v7.0.6, before producing messages you need first to run your producer instance.

See [Producer Reference](/docs/api/producer.md) for more details.

#### Consumer Class
Expand Down
12 changes: 4 additions & 8 deletions docs/api/message.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,21 +287,19 @@ message.getBody(); // 123
### Message.prototype.getId()

```javascript
const { Message, Producer } = require('redis-smq');
const { Message } = require('redis-smq');
const message = new Message();
message.setQueue('test_queue').setBody('some data');
message.getId(); // null
new Producer().produce(message, (err) => {
producer.produce(message, (err) => {
if (err) console.log(err);
else {
const messageId = message.getId(); // c53d1766-0e56-4362-8aab-ef70c4eb03ad
console.log('Message ID is ', messageId);
}
})
````
### Message.prototype.getTTL()
Expand Down Expand Up @@ -364,13 +362,12 @@ message.getCreatedAt(); // 1530613595087, in millis
### Message.prototype.getPublishedAt()
```javascript
const {Message, Producer} = require('redis-smq');
const { Message } = require('redis-smq');

const message = new Message();
message.setQueue('test_queue').setBody('Test message');
message.getPublishedAt(); // null

const producer = new Producer();
producer.produce(message, (err) => {
if (err) console.log(err);
else {
Expand All @@ -382,15 +379,14 @@ producer.produce(message, (err) => {
### Message.prototype.getScheduledAt()

```javascript
const {Message, Producer} = require('redis-smq');
const { Message } = require('redis-smq');
const message = new Message();
message.setScheduledRepeat(6);
message.getScheduledAt(); // null
message.setQueue('test_queue');
message.setBody('Test message');
const producer = new Producer();
producer.produce(message, (err) => {
if (err) console.log(err);
else {
Expand Down
41 changes: 20 additions & 21 deletions docs/api/producer.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,25 @@ const producer = new Producer(config);
- `config` *(object): Optional.* See [Configuration](/docs/configuration.md) for more details.


### Producer.prototype.run()

Start your producer instance. No connection to Redis server is opened until this method is called.

Starting with v7.0.6 producer instances are no longer automatically started upon creation.

You have to run a producer before producing messages.

**Syntax**

```javascript
run(cb);
```

**Parameters**
- `cb(err, status)` *(function): Required.* Callback function.
- `err` *(Error | null | undefined).* Error object.
- `status` *(boolean).* Indicate whether the operation completed successfully.

### Producer.prototype.produce()

**Syntax**
Expand All @@ -33,17 +52,14 @@ producer.produce(message, cb);
- `cb(err)` *(function): Required.* Callback function.

```javascript
const { Message, Producer } = require('redis-smq');
const { Message } = require('redis-smq');

const message = new Message();

message
.setBody({ hello: 'world' })
.setTTL(3600000)
.setScheduledDelay(10000) // in millis
.setQueue('test_queue');

const producer = new Producer();
producer.produce(message, (err) => {
if (err) console.log(err);
else console.log('Successfully produced')
Expand All @@ -58,23 +74,6 @@ Before publishing a message, make sure that:

Otherwise, an error will be returned.

### Producer.prototype.run()

Start your producer instance. No connection to Redis server is opened until this method is called.

Contrary to consumer instances, producer instances are automatically started upon creation.

**Syntax**

```javascript
run(cb);
```

**Parameters**
- `cb(err, status)` *(function): Required.* Callback function.
- `err` *(Error | null | undefined).* Error object.
- `status` *(boolean).* Indicate whether the operation completed successfully.

### Producer.prototype.shutdown()

Gracefully shut down your producer instance and go offline.
Expand Down
8 changes: 3 additions & 5 deletions docs/priority-queues.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,13 @@ See [Message Priority](/docs/api/message.md#messagemessagepriority) for more det
Before producing a message with a priority, make sure that queue of the message is a priority queue. Otherwise, an error will be returned.

```javascript
const {Message, Producer} = require('redis-smq');
const { Message } = require('redis-smq');

const msg1 = new Message();
msg1.setPriority(Message.MessagePriority.HIGH).setQueue('test_queue');

const producer = new Producer();
producer.produce(msg1, (err) => {
if (err) console.log(err);
else console.log('Successfully produced')
if (err) console.log(err);
else console.log('Successfully produced')
});
```

Expand Down
4 changes: 1 addition & 3 deletions docs/scheduling-messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ using the `produce()` method.

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

const producer = new Producer();
const { Message } = require('redis-smq');

const message = new Message();
message
Expand Down

0 comments on commit 51dfd16

Please sign in to comment.