You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Added peeking for messages without removing them untill explicitly done.
This is great for situations where you want to be absolutely sure that
the message was parsed and dealt with properly removing being removed
from the queue.
Copy file name to clipboardExpand all lines: readme.md
+51-2Lines changed: 51 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ NPM package is published as updated-node-msmq. https://www.npmjs.com/package/upd
9
9
## Differences from `node-msmq`
10
10
11
11
* Support for Node.Js 6.x, 7.x, 8.x, 9.x, 10.x
12
-
* Support to push objects to the queue instead of just strings.
12
+
* Support to push objects to the queue instead of just strings.
13
13
* Support to send/receive messages to/from a queue on a **remote** machine.
14
14
15
15
## Install
@@ -51,6 +51,55 @@ queue.on('receive', (msg) => {
51
51
queue.startReceiving();
52
52
```
53
53
54
+
### Peek messages
55
+
56
+
Start listeng for messages without removing them until you are ready to do so. Callbacks for the 'peek' event receive an object containing two properties:
57
+
58
+
*`msg` The MSMQ Message.
59
+
*`next()` Pops the message from the queue and start peeking for the next one.
60
+
61
+
```js
62
+
queue.on('peek', (event) => {
63
+
console.log(event.msg.body);
64
+
65
+
// Do some logic that might fail.
66
+
if (Math.random() >0.5) {
67
+
throwError('number is too high!');
68
+
}
69
+
70
+
// Remove the message from the queue and peek for next message.
71
+
event.next();
72
+
})
73
+
74
+
queue.startPeeking();
75
+
```
76
+
77
+
### Peek
78
+
79
+
Promised based method to peek for a message in the queue without removing it. Resolves to a MSMQMessage.
80
+
81
+
```js
82
+
queue.peek().then(msg=>console.log(msg.body));
83
+
84
+
//or
85
+
86
+
let msg =awaitqueue.peek();
87
+
```
88
+
89
+
### Remove
90
+
91
+
Promise based method to remove a message with given id from the queue. Resolves to `true` if message was removed and `false` if message didn't exist in the queue.
92
+
93
+
```js
94
+
queue.remove('12345')
95
+
.then(status=>console.log(status ?'Message was removed'
96
+
:'Message was not in queue'));
97
+
98
+
//or
99
+
100
+
let status =awaitqueue.remove('12345');
101
+
```
102
+
54
103
### Get all messages
55
104
56
105
Gets all messages without removing them from queue.
@@ -124,7 +173,7 @@ var queue = msmq.connectToRemoteQueue('.\\Private$\\MyAwesomeQueue');
124
173
var messages =queue.getAllMessages();
125
174
```
126
175
127
-
#### Note:
176
+
#### Note:
128
177
* Creating a queue / Checking if a queue exists on a remote machine is currently not supported by MSMQ.
129
178
* To communicate with a remote queue, MSMQ should be enabled in the sender's machine too. Also, in the _Security_ tab of the queue on the remote machine should have the appropriate permissions set for _Everyone_ and _ANONYMOUS LOGON_.
130
179
* The queue should already be created on the remote machine.
0 commit comments