Skip to content

Commit 69b5006

Browse files
committed
111
1 parent caa534b commit 69b5006

8 files changed

Lines changed: 34 additions & 16 deletions

File tree

OpenFlow/src/WebSocketClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export class WebSocketClient {
130130
}
131131
var AssertQueueOptions: any = new Object(amqpwrapper.Instance().AssertQueueOptions);
132132
AssertQueueOptions.autoDelete = autoDelete;
133-
var queuename = await amqpwrapper.Instance().AddQueueConsumer(queuename, AssertQueueOptions, this.jwt, async (msg: any, options: QueueMessageOptions, ack: any, done: any) => {
133+
var queuename = await amqpwrapper.Instance().AddQueueConsumer(this, queuename, AssertQueueOptions, this.jwt, async (msg: any, options: QueueMessageOptions, ack: any, done: any) => {
134134
var _data = msg;
135135
try {
136136
_data = await this.Queue(msg, queuename, options);

OpenFlow/src/WebSocketServer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export class WebSocketServer {
6262
}
6363
var now = new Date();
6464
var seconds = (now.getTime() - cli.lastheartbeat.getTime()) / 1000;
65-
if (seconds >= 20) {
65+
if (seconds >= 60) {
6666
if (cli.user != null) {
6767
WebSocketServer._logger.info("client " + cli.user.name + "/" + cli.clientagent + " timeout, close down");
6868
} else {

OpenFlow/src/amqpwrapper.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Util } from "./Util";
44
import { Config } from "./Config";
55
import { cli } from "winston/lib/winston/config";
66
import { Crypt } from "./Crypt";
7+
import { WebSocketClient } from "./WebSocketClient";
78

89
type QueueOnMessage = (msg: string, options: QueueMessageOptions, ack: any, done: any) => void;
910
interface IHashTable<T> {
@@ -39,6 +40,7 @@ export class amqpqueue {
3940
public ok: AssertQueue;
4041
public QueueOptions: any;
4142
public consumerTag: string;
43+
public cli: WebSocketClient;
4244
}
4345
export class amqpexchange {
4446
public exchange: string;
@@ -48,6 +50,7 @@ export class amqpexchange {
4850
public callback: QueueOnMessage;
4951
public ok: amqplib.Replies.AssertExchange;
5052
public ExchangeOptions: any;
53+
public cli: WebSocketClient;
5154
}
5255

5356
// tslint:disable-next-line: class-name
@@ -144,7 +147,7 @@ export class amqpwrapper {
144147
if (!Util.IsNullEmpty(this.replyqueue)) {
145148
delete this.queues[this.replyqueue];
146149
}
147-
this.replyqueue = await this.AddQueueConsumer("", null, null, (msg: any, options: QueueMessageOptions, ack: any, done: any) => {
150+
this.replyqueue = await this.AddQueueConsumer(null, "", null, null, (msg: any, options: QueueMessageOptions, ack: any, done: any) => {
148151
if (!Util.IsNullUndefinded(this.activecalls[options.correlationId])) {
149152
this.activecalls[options.correlationId].resolve(msg);
150153
this.activecalls[options.correlationId] = null;
@@ -203,9 +206,10 @@ export class amqpwrapper {
203206
if (this.channel != null) await this.channel.cancel(q.consumerTag);
204207
delete this.queues[q.queue];
205208
}
206-
async AddQueueConsumer(queue: string, QueueOptions: any, jwt: string, callback: QueueOnMessage): Promise<string> {
209+
async AddQueueConsumer(cli: WebSocketClient, queue: string, QueueOptions: any, jwt: string, callback: QueueOnMessage): Promise<string> {
207210
if (this.channel == null || this.conn == null) throw new Error("Cannot Add new Queue Consumer, not connected to rabbitmq");
208211
var q: amqpqueue = null;
212+
q.cli = cli;
209213
if (Config.amqp_force_queue_prefix && !Util.IsNullEmpty(jwt)) {
210214
var tuser = Crypt.verityToken(jwt);
211215
var name = tuser.username.split("@").join("").split(".").join("");
@@ -234,15 +238,16 @@ export class amqpwrapper {
234238
q.queue = q.ok.queue;
235239
this._logger.info("[AMQP] Added queue consumer " + q.queue);
236240
var consumeresult = await this.channel.consume(q.ok.queue, (msg) => {
237-
this.OnMessage(this, msg, q.callback);
241+
this.OnMessage(q, msg, q.callback);
238242
}, { noAck: false });
239243
q.consumerTag = consumeresult.consumerTag;
240244
this.queues[q.queue] = q;
241245
return q.queue;
242246
}
243-
async AddExchangeConsumer(exchange: string, algorithm: string, routingkey: string, ExchangeOptions: any, jwt: string, callback: QueueOnMessage): Promise<void> {
247+
async AddExchangeConsumer(cli: WebSocketClient, exchange: string, algorithm: string, routingkey: string, ExchangeOptions: any, jwt: string, callback: QueueOnMessage): Promise<void> {
244248
if (this.channel == null || this.conn == null) throw new Error("Cannot Add new Exchange Consumer, not connected to rabbitmq");
245249
var q: amqpexchange = null;
250+
q.cli = cli;
246251
if (Config.amqp_force_exchange_prefix && !Util.IsNullEmpty(jwt)) {
247252
var tuser = Crypt.verityToken(jwt);
248253
var name = tuser.username.split("@").join("").split(".").join("");
@@ -266,14 +271,27 @@ export class amqpwrapper {
266271
AssertQueueOptions = Object.create(this.AssertQueueOptions);
267272
delete AssertQueueOptions.arguments;
268273
}
269-
q.queue = await this.AddQueueConsumer("", AssertQueueOptions, jwt, q.callback);
274+
q.queue = await this.AddQueueConsumer(cli, "", AssertQueueOptions, jwt, q.callback);
270275
this.channel.bindQueue(q.queue, q.exchange, q.routingkey);
271276
this._logger.info("[AMQP] Added exchange consumer " + q.exchange);
272277
this.exchanges[exchange] = q;
273278
}
274-
OnMessage(sender: amqpwrapper, msg: amqplib.ConsumeMessage, callback: QueueOnMessage): void {
279+
OnMessage(sender: amqpqueue, msg: amqplib.ConsumeMessage, callback: QueueOnMessage): void {
275280
// sender._logger.info("OnMessage " + msg.content.toString());
276281
try {
282+
var now = new Date();
283+
var seconds = (now.getTime() - sender.cli.lastheartbeat.getTime()) / 1000;
284+
if (seconds >= 20) {
285+
try {
286+
sender.cli._logger.info("amqpwrapper.OnMessage: receive message for inactive client, nack message and try and close");
287+
this.channel.nack(msg);
288+
sender.cli.Close();
289+
} catch (error) {
290+
console.error(error);
291+
}
292+
return;
293+
}
294+
277295
var correlationId: string = msg.properties.correlationId;
278296
var replyTo: string = msg.properties.replyTo;
279297
var consumerTag: string = msg.fields.consumerTag;

OpenFlow/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ async function initamqp() {
3434
await testamqp.connect();
3535

3636
// Must also consume messages in the dead letter queue, to catch messages that have timed out
37-
await amqp.AddExchangeConsumer(Config.amqp_dlx, "fanout", "", null, null, (msg: any, options: QueueMessageOptions, ack: any, done: any) => {
37+
await amqp.AddExchangeConsumer(null, Config.amqp_dlx, "fanout", "", null, null, (msg: any, options: QueueMessageOptions, ack: any, done: any) => {
3838
// This is the function to run when the dead letter (timed out) message is picked up
3939
// var data = JSON.parse(msg.content.toString());
4040
// Change the command and return back to the correct queue (replyTo) to be handled

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.11
1+
1.0.12

docker-compose-toolbox.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ services:
4545
- "traefik.http.routers.web.rule=Host(`toolbox.openrpa.dk`)"
4646
- "traefik.http.routers.web.entrypoints=web"
4747
- "traefik.frontend.passHostHeader=true"
48-
image: "cloudhack/openflow:1.0.10"
48+
image: "cloudhack/openflow:1.0.12"
4949
container_name: "web"
5050
environment:
5151
- update_acl_based_on_groups=true
@@ -82,7 +82,7 @@ services:
8282
- "traefik.http.routers.nodered.rule=Host(`nodered1.toolbox.openrpa.dk`)"
8383
- "traefik.http.routers.nodered.entrypoints=web"
8484
- "traefik.http.services.nodered.loadbalancer.server.port=1880"
85-
image: "cloudhack/openflownodered:1.0.10"
85+
image: "cloudhack/openflownodered:1.0.12"
8686
container_name: "nodered"
8787
environment:
8888
# - nodered_id=1

docker-compose-traefik.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ services:
4545
- "traefik.http.routers.web.rule=Host(`localhost.openrpa.dk`)"
4646
- "traefik.http.routers.web.entrypoints=web"
4747
- "traefik.frontend.passHostHeader=true"
48-
image: "cloudhack/openflow:1.0.10"
48+
image: "cloudhack/openflow:1.0.12"
4949
container_name: "web"
5050
environment:
5151
- update_acl_based_on_groups=true
@@ -82,7 +82,7 @@ services:
8282
- "traefik.http.routers.nodered.rule=Host(`nodered1.localhost.openrpa.dk`)"
8383
- "traefik.http.routers.nodered.entrypoints=web"
8484
- "traefik.http.services.nodered.loadbalancer.server.port=1880"
85-
image: "cloudhack/openflownodered:1.0.10"
85+
image: "cloudhack/openflownodered:1.0.12"
8686
container_name: "nodered"
8787
environment:
8888
# - nodered_id=1

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ services:
1818
- "5672:5672"
1919
- "15672:15672"
2020
web:
21-
image: "cloudhack/openflow:1.0.10"
21+
image: "cloudhack/openflow:1.0.12"
2222
environment:
2323
- update_acl_based_on_groups=true
2424
- multi_tenant=false
@@ -52,7 +52,7 @@ services:
5252
- "80:80"
5353
- "5858:5858"
5454
nodered:
55-
image: "cloudhack/openflownodered:1.0.10"
55+
image: "cloudhack/openflownodered:1.0.12"
5656
environment:
5757
# - nodered_id=1
5858
- nodered_sa=nodered1

0 commit comments

Comments
 (0)