Skip to content

Commit a9e4a08

Browse files
committed
Save msg object when calling robot
1 parent fe16c61 commit a9e4a08

4 files changed

Lines changed: 19 additions & 6 deletions

File tree

OpenFlowNodeRED/src/amqp_publisher.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ export class amqp_publisher {
4747
if (this.channel != null && this.channel != undefined) { await this.channel.close(); this.channel = null; }
4848
if (this.conn != null && this.conn != undefined) { await this.conn.close(); this.conn = null; }
4949
}
50-
SendMessage(msg: string, queue: string): void {
51-
var corr: string = this.generateUuid();
50+
SendMessage(msg: string, queue: string, correlationId: string): void {
51+
if (correlationId == null || correlationId == "") { correlationId = this.generateUuid(); }
5252
this._logger.info("SendMessage " + msg);
53-
this.channel.sendToQueue(queue, Buffer.from(msg), { correlationId: corr, replyTo: this._ok.queue });
53+
this.channel.sendToQueue(queue, Buffer.from(msg), { correlationId: correlationId, replyTo: this._ok.queue });
5454
}
5555
private _OnMessage(sender: amqp_publisher, msg: amqplib.ConsumeMessage): void {
5656
try {

OpenFlowNodeRED/src/nodered/nodes/amqp_nodes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ export class amqp_publisher_node {
203203
data.payload = msg.payload;
204204
data.jwt = msg.jwt;
205205
data._id = msg._id;
206-
this.con.SendMessage(JSON.stringify(data), this.config.queue);
206+
this.con.SendMessage(JSON.stringify(data), this.config.queue, null);
207207
this.node.status({});
208208
} catch (error) {
209209
NoderedUtil.HandleError(this, error);

OpenFlowNodeRED/src/nodered/nodes/rpa_nodes.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ export class rpa_workflow_node {
113113
var json: string = msg.content.toString();
114114
var data = JSON.parse(json);
115115
result.jwt = data.jwt;
116+
var correlationId = msg.properties.correlationId;
117+
if (correlationId != null && this.messages[correlationId] != null) {
118+
result = this.messages[correlationId];
119+
if (data.payload.command == "invokecompleted" || data.payload.command == "invokefailed" || data.payload.command == "invokeaborted" || data.payload.command == "error") {
120+
delete this.messages[correlationId];
121+
}
122+
}
116123

117124
if (data.payload.command == "invokecompleted") {
118125
result.payload = data.payload.data;
@@ -131,9 +138,15 @@ export class rpa_workflow_node {
131138
NoderedUtil.HandleError(this, error);
132139
}
133140
}
141+
messages: any[] = [];
134142
async oninput(msg: any) {
135143
try {
136144
this.node.status({});
145+
var correlationId = Math.random().toString(36).substr(2, 9);
146+
this.messages[correlationId] = msg;
147+
if (msg.payload == null || typeof msg.payload == "string" || typeof msg.payload == "number") {
148+
msg.payload = { "data": msg.payload };
149+
}
137150
var rpacommand = {
138151
command: "invoke",
139152
workflowid: this.config.workflow,
@@ -143,7 +156,7 @@ export class rpa_workflow_node {
143156
jwt: msg.jwt,
144157
payload: rpacommand
145158
}
146-
this.con.SendMessage(JSON.stringify(data), this.config.queue);
159+
this.con.SendMessage(JSON.stringify(data), this.config.queue, correlationId);
147160
// var data: any = {};
148161
// data.payload = msg.payload;
149162
// data.jwt = msg.jwt;

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.321
1+
0.0.322

0 commit comments

Comments
 (0)