@@ -43,6 +43,7 @@ import { DatabaseConnection } from "../DatabaseConnection";
4343import { CreateWorkflowInstanceMessage } from "./CreateWorkflowInstanceMessage" ;
4444import { StripeMessage , EnsureStripeCustomerMessage , Billing , stripe_customer , stripe_base , stripe_list , StripeAddPlanMessage , StripeCancelPlanMessage , stripe_subscription , stripe_subscription_item , stripe_plan , stripe_coupon } from "./StripeMessage" ;
4545import { V1ResourceRequirements } from "@kubernetes/client-node" ;
46+ import { amqpwrapper } from "../amqpwrapper" ;
4647var request = require ( "request" ) ;
4748var got = require ( "got" ) ;
4849
@@ -213,7 +214,7 @@ export class Message {
213214 var msg : RegisterQueueMessage < Base >
214215 try {
215216 msg = RegisterQueueMessage . assign ( this . data ) ;
216- await cli . CreateConsumer ( msg . queuename ) ;
217+ msg . queuename = await cli . CreateConsumer ( msg . queuename ) ;
217218 } catch ( error ) {
218219 cli . _logger . error ( error ) ;
219220 if ( Util . IsNullUndefinded ( msg ) ) { ( msg as any ) = { } ; }
@@ -238,25 +239,35 @@ export class Message {
238239 if ( typeof msg . data == 'string' ) {
239240 try {
240241 var obj = JSON . parse ( msg . data ) ;
241- if ( Util . IsNullUndefinded ( obj . jwt ) ) {
242- obj . jwt = msg . jwt ;
243- msg . data = JSON . stringify ( obj ) ;
244- }
242+ // if (Util.IsNullUndefinded(obj.jwt)) {
243+ // obj.jwt = msg.jwt;
244+ // msg.data = JSON.stringify(obj);
245+ // }
245246 } catch ( error ) {
246247 }
247248 } else {
248249 msg . data . jwt = msg . jwt ;
249250 }
250251 }
252+ var expiration : number = Config . amqp_default_expiration ;
253+ if ( typeof msg . expiration == 'number' ) expiration = msg . expiration ;
251254 if ( Util . IsNullEmpty ( msg . replyto ) ) {
252- await cli . sendToQueue ( msg ) ;
255+ // var sendthis = { data: msg.data, jwt: cli.jwt, user: cli.user };
256+ var sendthis = msg . data ;
257+ await amqpwrapper . Instance ( ) . send ( "" , msg . queuename , sendthis , expiration , msg . correlationId ) ;
253258 } else {
254259 if ( msg . queuename === msg . replyto ) {
255- cli . _logger . warn ( "Ignore reply to self queuename:" + msg . queuename + " correlationId:" + msg . correlationId ) ;
256- return
260+ throw new Error ( "Cannot send reply to self queuename:" + msg . queuename + " correlationId:" + msg . correlationId ) ;
261+ // cli._logger.warn("Ignore reply to self queuename:" + msg.queuename + " correlationId:" + msg.correlationId);
262+ // return
257263 }
258- this . replyto = msg . correlationId ;
259- await cli . sendQueueReply ( msg ) ;
264+ //var sendthis = { data: msg.data, jwt: cli.jwt, user: cli.user };
265+ var sendthis = msg . data ;
266+ var result = await amqpwrapper . Instance ( ) . sendWithReplyTo ( "" , msg . queuename , msg . replyto , sendthis , expiration , msg . correlationId ) ;
267+ // var result = await amqpwrapper.Instance().sendWithReply("", msg.queuename, sendthis, expiration, msg.correlationId);
268+
269+ // this.replyto = msg.correlationId;
270+ // await cli.sendQueueReply(msg, expiration);
260271 }
261272 } catch ( error ) {
262273 cli . _logger . error ( error ) ;
@@ -802,9 +813,9 @@ export class Message {
802813 var tuser : TokenUser = new TokenUser ( nodereduser ) ;
803814 var nodered_jwt : string = Crypt . createToken ( tuser , Config . personalnoderedtoken_expires_in ) ;
804815
805- if ( Config . force_queue_prefix ) {
806- user . nodered . queue_prefix = nodereduser . username ;
807- }
816+ // if (Config.force_queue_prefix) {
817+ // user.nodered.queue_prefix = nodereduser.username;
818+ // }
808819
809820 cli . _logger . debug ( "[" + cli . user . username + "] ensure nodered role " + name + "noderedadmins" ) ;
810821 var noderedadmins = await User . ensureRole ( cli . jwt , name + "noderedadmins" , null ) ;
@@ -1144,14 +1155,13 @@ export class Message {
11441155 cli . _logger . debug ( "[" + cli . user . username + "] Remove un billed nodered instance " + itemname + " that has been running for " + diffhours + " hours" ) ;
11451156 await this . _DeleteNoderedInstance ( userid , cli . user . _id , cli . user . username , rootjwt ) ;
11461157 }
1147- // console.log(itemname + " " + diffminutes + " min / " + diffhours + " hours");
11481158 } catch ( error ) {
11491159 }
11501160 } else if ( image . indexOf ( "openflownodered" ) > 0 ) {
11511161 if ( billed != "true" && diffhours > 24 ) {
1152- console . log ( "unbilled " + itemname + " with no userid, should be removed, it has been running for " + diffhours + " hours" ) ;
1162+ console . debug ( "unbilled " + itemname + " with no userid, should be removed, it has been running for " + diffhours + " hours" ) ;
11531163 } else {
1154- console . log ( "unbilled " + itemname + " with no userid, has been running for " + diffhours + " hours" ) ;
1164+ console . debug ( "unbilled " + itemname + " with no userid, has been running for " + diffhours + " hours" ) ;
11551165 }
11561166 }
11571167 }
@@ -1475,10 +1485,10 @@ export class Message {
14751485 var tuser = Crypt . verityToken ( msg . jwt ) ;
14761486 msg . jwt = Crypt . createToken ( tuser , Config . longtoken_expires_in ) ;
14771487
1478- if ( cli . consumers . length == 0 ) {
1479- await cli . CreateConsumer ( "nodered." + Math . random ( ) . toString ( 36 ) . substr ( 2 , 9 ) ) ;
1480- // throw new Error("Client not connected to any message queues");
1481- }
1488+ // if (cli.consumers.length == 0) {
1489+ // await cli.CreateConsumer("nodered." + Math.random().toString(36).substr(2, 9));
1490+ // // throw new Error("Client not connected to any message queues");
1491+ // }
14821492 if ( Util . IsNullEmpty ( msg . queue ) ) {
14831493 var workflow : any = null ;
14841494 var user : any = null ;
@@ -1515,7 +1525,8 @@ export class Message {
15151525
15161526 if ( msg . initialrun ) {
15171527 var message = { _id : res2 . _id } ;
1518- cli . consumers [ 0 ] . sendToQueueWithReply ( msg . queue , msg . resultqueue , msg . correlationId , message ) ;
1528+ amqpwrapper . Instance ( ) . sendWithReplyTo ( "" , msg . queue , msg . resultqueue , message , Config . amqp_default_expiration , msg . correlationId ) ;
1529+ // cli.consumers[0].sendToQueueWithReply(msg.queue, msg.resultqueue, msg.correlationId, message, (60 * (60 * 1000))); // 1 hour
15191530 }
15201531 } catch ( error ) {
15211532 cli . _logger . error ( error ) ;
0 commit comments