Skip to content

Commit

Permalink
Add Ability to pass data from the individual messages to re-assemble…
Browse files Browse the repository at this point in the history
…d message (#69)

Add Ability to pass data from the individual messages to re-assembled message
  • Loading branch information
Olha Virolainen authored Jul 8, 2021
1 parent 7eadec5 commit c358bfe
Show file tree
Hide file tree
Showing 7 changed files with 4,311 additions and 18 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.2.0 (July 9, 2021)
* Add Ability to pass data from the individual messages to re-assembled message

## 1.1.9 (February 12, 2021)
* Update sailor version to 2.6.24

Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,17 @@ If at any point there is more than a 15 second gap in messages, then the group w
* The group is dropped if there are any unexpected restarts to the container.
* Size of the group must be known by all group members.
* Messages are only emitter when all parts arrive. Emitting a message only when the first part arrives isn't supported.
* The contents of data that are picked up by the sub-messages aren't passed forward to future steps.

#### List of Expected Config fields
```groupSize``` - Number of messages in the group

```groupId``` - Globally unique id for the group to distinguish it from other groups. This value needs to be the same for all messages in a group.

```messageId``` - Id for a message to distinguish it from other messages in the group.
Must be unique per group but does not have to be globally unique. This value needs to be different for all messages in a group.

```messageData``` - object for providing some data derived from the steps between splitting and re-assembling

## Known limitations (common for the component)
No.

Expand Down
7 changes: 7 additions & 0 deletions component.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"title": "Splitter",
"version": "1.2.0",
"description": "Splits a message into multiple messages.",
"buildType":"docker",
"actions": {
Expand Down Expand Up @@ -61,6 +62,12 @@
"type": "string",
"required": true,
"title": "Unique ID to describe this message"
},
"messageData": {
"title": "Message Data",
"required": false,
"type": "object",
"properties": {}
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions lib/actions/reassemble.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ async function processAction(msg) {
groupSize,
groupId,
messageId,
messageData,
} = msg.body;

if (groupSize <= 0) {
Expand All @@ -17,10 +18,12 @@ async function processAction(msg) {
groupsSeen[groupId] = {
groupSize,
messageIdsSeen: new Set(),
incomingData: {},
};
}

groupsSeen[groupId].messageIdsSeen.add(messageId);
groupsSeen[groupId].incomingData[messageId] = messageData;
const numberSeen = groupsSeen[groupId].messageIdsSeen.size;

this.logger.info(
Expand All @@ -31,6 +34,7 @@ async function processAction(msg) {
await this.emit('data', messages.newMessageWithBody({
groupSize,
groupId,
messageData: groupsSeen[groupId].incomingData,
}));
delete groupsSeen[groupId];
}
Expand Down
Loading

0 comments on commit c358bfe

Please sign in to comment.