@natlibfi/melinda-rest-api-commons 2.3.2-alpha.7 → 2.3.2-alpha.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/amqp.js CHANGED
@@ -8,10 +8,11 @@ var _amqplib = _interopRequireDefault(require("amqplib"));
8
8
  var _marcRecord = require("@natlibfi/marc-record");
9
9
  var _melindaCommons = require("@natlibfi/melinda-commons");
10
10
  var _melindaBackendCommons = require("@natlibfi/melinda-backend-commons");
11
+ var _debug = _interopRequireDefault(require("debug"));
11
12
  var _constants = require("./constants");
12
- var _utils = require("./utils");
13
13
  var _util = require("util");
14
14
  var _httpStatus = _interopRequireDefault(require("http-status"));
15
+ var _utils = require("./utils");
15
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
17
  /**
17
18
  *
@@ -19,7 +20,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
19
20
  *
20
21
  * Shared modules for microservices of Melinda rest api batch import system
21
22
  *
22
- * Copyright (C) 2020-2021 University Of Helsinki (The National Library Of Finland)
23
+ * Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
23
24
  *
24
25
  * This file is part of melinda-rest-api-commons
25
26
  *
@@ -41,10 +42,19 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
41
42
  *
42
43
  */
43
44
 
44
- async function _default(AMQP_URL) {
45
+ //import {logError} from './utils';
46
+
47
+ async function _default(AMQP_URL, runHealthCheck = false) {
48
+ const logger = (0, _melindaBackendCommons.createLogger)();
49
+ const debug = (0, _debug.default)('@natlibfi/melinda-rest-api-commons:amqp');
50
+ const debugHC = debug.extend('HC');
51
+ debug(`Creating an AMQP operator to ${AMQP_URL}`);
45
52
  const connection = await _amqplib.default.connect(AMQP_URL);
46
53
  const channel = await connection.createChannel();
47
- const logger = (0, _melindaBackendCommons.createLogger)();
54
+ const healthCheckLoop = runHealthCheck ? healthCheck() : 'Not running health check';
55
+ debug(`Connection: ${connection}`);
56
+ debug(`Channel: ${channel}`);
57
+ debug(`HealthCheckLoop ${healthCheckLoop}`);
48
58
  return {
49
59
  checkQueue,
50
60
  consumeChunk,
@@ -53,8 +63,39 @@ async function _default(AMQP_URL) {
53
63
  nackMessages,
54
64
  sendToQueue,
55
65
  removeQueue,
56
- messagesToRecords
66
+ messagesToRecords,
67
+ closeChannel,
68
+ closeConnection
57
69
  };
70
+ async function closeChannel() {
71
+ debug(`Closing channel`);
72
+ await channel.close();
73
+ debug(`Channel: ${channel}`);
74
+ }
75
+ async function closeConnection() {
76
+ debug(`Closing connection`);
77
+ await connection.close();
78
+ debug(`Connection: ${connection}`);
79
+ }
80
+ async function healthCheck(wait = false) {
81
+ const setTimeoutPromise = (0, _util.promisify)(setTimeout);
82
+ if (wait) {
83
+ await setTimeoutPromise(wait);
84
+ return healthCheck(false);
85
+ }
86
+ try {
87
+ debugHC(`Health checking amqp by asserting a queue`);
88
+ await channel.assertQueue('HEALTHCHECK', {
89
+ durable: false
90
+ });
91
+ debugHC(`Waiting 200ms before running healthCheck next`);
92
+ return healthCheck('200');
93
+ } catch (error) {
94
+ const errorToThrow = error;
95
+ debugHC(`HealthCheck error ${JSON.stringify(error)}`);
96
+ handleAmqpErrors(errorToThrow);
97
+ }
98
+ }
58
99
 
59
100
  // eslint-disable-next-line max-statements
60
101
  async function checkQueue({
@@ -63,7 +104,7 @@ async function _default(AMQP_URL) {
63
104
  toRecord = true,
64
105
  purge = false
65
106
  }) {
66
- logger.silly(`checkQueue: ${queue}, Style: ${style}: toRecord: ${toRecord}, Purge: ${purge}`);
107
+ debug(`checkQueue: ${queue}, Style: ${style}, toRecord: ${toRecord}, Purge: ${purge}`);
67
108
  try {
68
109
  errorUndefinedQueue(queue);
69
110
  const channelInfo = await channel.assertQueue(queue, {
@@ -72,19 +113,20 @@ async function _default(AMQP_URL) {
72
113
  if (purge) {
73
114
  await purgeQueue(purge);
74
115
  logger.verbose(`Queue ${queue} has purged ${channelInfo.messageCount} messages`);
116
+ debug(`Queue ${queue} has purged ${channelInfo.messageCount} messages`);
75
117
  return checkQueue({
76
118
  queue,
77
119
  style
78
120
  });
79
121
  }
80
- if (channelInfo.messageCount < 1) {
81
- logger.silly(`checkQueue: ${channelInfo.messageCount} - ${queue} is empty`);
82
- return false;
83
- }
84
- logger.silly(`Queue ${queue} has ${channelInfo.messageCount} messages`);
85
122
  if (style === 'messages') {
86
123
  return channelInfo.messageCount;
87
124
  }
125
+ if (channelInfo.messageCount < 1) {
126
+ debug(`checkQueue: ${channelInfo.messageCount} - ${queue} is empty`);
127
+ return false;
128
+ }
129
+ debug(`Queue ${queue} has ${channelInfo.messageCount} messages`);
88
130
 
89
131
  // Note: returns one message (+ record, of toRecord: true)
90
132
  // note: if toRecord is false returns just plain message / false
@@ -103,16 +145,17 @@ async function _default(AMQP_URL) {
103
145
  // Defaults:
104
146
  throw new _melindaCommons.Error(_httpStatus.default.UNPROCESSABLE_ENTITY);
105
147
  } catch (error) {
106
- (0, _utils.logError)(error);
148
+ handleAmqpErrors(error);
107
149
  }
108
150
  function purgeQueue(purge) {
151
+ debug(`Purging queue: ${queue}, purge: ${purge}`);
109
152
  if (purge) {
110
153
  return channel.purgeQueue(queue);
111
154
  }
112
155
  }
113
156
  }
114
157
  async function consumeChunk(queue, toRecord) {
115
- logger.silly(`Prepared to consumeChunk from queue: ${queue}`);
158
+ debug(`Prepared to consumeChunk from queue: ${queue}`);
116
159
  try {
117
160
  await channel.assertQueue(queue, {
118
161
  durable: true
@@ -121,7 +164,7 @@ async function _default(AMQP_URL) {
121
164
  // getData: next chunk (100) messages
122
165
  const messages = await getData(queue);
123
166
  const headers = getHeaderInfo(messages[0]);
124
- logger.debug(`consumeChunk (${messages ? messages.length : '0'} from queue ${queue}) ${toRecord ? 'to records' : 'just messages'}`);
167
+ debug(`consumeChunk (${messages ? messages.length : '0'} from queue ${queue}) ${toRecord ? 'to records' : 'just messages'}`);
125
168
  if (toRecord) {
126
169
  const records = await messagesToRecords(messages);
127
170
  return {
@@ -135,11 +178,11 @@ async function _default(AMQP_URL) {
135
178
  messages
136
179
  };
137
180
  } catch (error) {
138
- (0, _utils.logError)(error);
181
+ handleAmqpErrors(error);
139
182
  }
140
183
  }
141
184
  async function consumeOne(queue, toRecord) {
142
- logger.silly(`Prepared to consumeOne from queue: ${queue}`);
185
+ debug(`Prepared to consumeOne from queue: ${queue}`);
143
186
  try {
144
187
  await channel.assertQueue(queue, {
145
188
  durable: true
@@ -147,13 +190,13 @@ async function _default(AMQP_URL) {
147
190
 
148
191
  // Returns false if 0 items in queue
149
192
  const message = await channel.get(queue);
150
- logger.silly(`Message: ${(0, _util.inspect)(message, {
193
+ debug(`Message: ${(0, _util.inspect)(message, {
151
194
  colors: true,
152
195
  maxArrayLength: 3,
153
196
  depth: 3
154
197
  })}`);
155
198
  // Do not spam the logs
156
- logger.debug(`consumeOne from queue: ${queue} ${toRecord ? 'to records' : 'just the message'}`);
199
+ debug(`consumeOne from queue: ${queue} ${toRecord ? 'to records' : 'just the message'}`);
157
200
  if (message) {
158
201
  if (toRecord) {
159
202
  const headers = getHeaderInfo(message);
@@ -168,18 +211,18 @@ async function _default(AMQP_URL) {
168
211
  }
169
212
  return false;
170
213
  } catch (error) {
171
- (0, _utils.logError)(error);
214
+ handleAmqpErrors(error);
172
215
  }
173
216
  }
174
217
  function ackMessages(messages) {
175
218
  messages.forEach(message => {
176
- logger.silly(`Ack message ${message.properties.correlationId}`);
219
+ debug(`Ack message ${message.properties.correlationId}`);
177
220
  channel.ack(message);
178
221
  });
179
222
  }
180
223
  function nackMessages(messages) {
181
224
  messages.forEach(message => {
182
- logger.silly(`Nack message ${message.properties.correlationId}`);
225
+ debug(`Nack message ${message.properties.correlationId}`);
183
226
  channel.nack(message);
184
227
  });
185
228
  }
@@ -189,25 +232,34 @@ async function _default(AMQP_URL) {
189
232
  headers,
190
233
  data
191
234
  }) {
235
+ debug(`sendToQueue`);
236
+ // eslint-disable-next-line no-useless-catch
192
237
  try {
193
- logger.silly(`Queue ${queue}`);
194
- logger.silly(`CorrelationId ${correlationId}`);
195
- logger.silly(`Data ${JSON.stringify(data)}`);
196
- logger.silly(`Headers ${JSON.stringify(headers)}`);
238
+ debug(`Queue ${queue}`);
239
+ debug(`CorrelationId ${correlationId}`);
240
+ debug(`Data ${JSON.stringify(data)}`);
241
+ debug(`Headers ${JSON.stringify(headers)}`);
197
242
  errorUndefinedQueue(queue);
243
+ debug(`Asserting queue: ${queue}`);
198
244
  await channel.assertQueue(queue, {
199
245
  durable: true
200
246
  });
201
- channel.sendToQueue(queue, Buffer.from(JSON.stringify({
247
+ debug(`Actually sendToQueue: ${queue}`);
248
+ await channel.sendToQueue(queue, Buffer.from(JSON.stringify({
202
249
  data
203
250
  })), {
204
251
  correlationId,
205
252
  persistent: true,
206
253
  headers
207
254
  });
208
- logger.silly(`Send message for ${correlationId} to queue: ${queue}`);
255
+ debug(`Send message for ${correlationId} to queue: ${queue}`);
209
256
  } catch (error) {
210
- (0, _utils.logError)(error);
257
+ const errorToThrow = error;
258
+ //if (error instanceof ApiError) {
259
+ // throw error;
260
+ //}
261
+ debug(`SendToQueue errored: ${JSON.stringify(error)}`);
262
+ handleAmqpErrors(errorToThrow);
211
263
  }
212
264
  }
213
265
  async function removeQueue(queue) {
@@ -216,11 +268,13 @@ async function _default(AMQP_URL) {
216
268
  // this might be doable also with assertQueue before deleteQueue
217
269
  const tempChannel = await connection.createChannel();
218
270
  logger.verbose(`Removing queue ${queue}.`);
271
+ debug(`Removing queue ${queue}.`);
219
272
  await tempChannel.deleteQueue(queue);
220
273
  if (tempChannel) {
221
- // eslint-disable-line functional/no-conditional-statement
222
274
  await tempChannel.close();
275
+ return;
223
276
  }
277
+ return;
224
278
  }
225
279
 
226
280
  // ----------------
@@ -228,26 +282,26 @@ async function _default(AMQP_URL) {
228
282
  // ----------------
229
283
 
230
284
  function messagesToRecords(messages) {
231
- logger.debug(`Parsing messages (${messages.length}) to records`);
285
+ debug(`Parsing messages (${messages.length}) to records`);
232
286
  return messages.map(message => {
233
287
  const content = JSON.parse(message.content.toString());
234
288
  return new _marcRecord.MarcRecord(content.data);
235
289
  });
236
290
  }
237
291
  async function getData(queue) {
238
- logger.debug(`Getting queue data from ${queue}`);
292
+ debug(`Getting queue data from ${queue}`);
239
293
  try {
240
294
  const {
241
295
  messageCount
242
296
  } = await channel.checkQueue(queue);
243
- logger.silly(`There is ${messageCount} messages in queue ${queue}`);
297
+ debug(`There is ${messageCount} messages in queue ${queue}`);
244
298
  const messagesToGet = messageCount >= _constants.CHUNK_SIZE ? _constants.CHUNK_SIZE : messageCount;
245
- logger.silly(`Getting ${messagesToGet} messages from queue ${queue}`);
299
+ debug(`Getting ${messagesToGet} messages from queue ${queue}`);
246
300
  const messages = await pump(messagesToGet);
247
- logger.debug(`Returning ${messages.length} unique messages`);
301
+ debug(`Returning ${messages.length} unique messages`);
248
302
  return messages;
249
303
  } catch (error) {
250
- (0, _utils.logError)(error);
304
+ handleAmqpErrors(error);
251
305
  }
252
306
  async function pump(count, results = [], identifiers = []) {
253
307
  if (count === 0) {
@@ -273,5 +327,14 @@ async function _default(AMQP_URL) {
273
327
  throw new _melindaCommons.Error(_httpStatus.default.INTERNAL_SERVER_ERROR, `Undefined queue!`);
274
328
  }
275
329
  }
330
+ function handleAmqpErrors(error) {
331
+ const newError = error;
332
+ //debug(`HandleAmqpErrors got an error: ${JSON.stringify(error)}`);
333
+ if (error instanceof _melindaCommons.Error) {
334
+ throw new _melindaCommons.Error(newError.status, newError.payload);
335
+ }
336
+ (0, _utils.logError)(error);
337
+ throw newError;
338
+ }
276
339
  }
277
340
  //# sourceMappingURL=amqp.js.map
package/dist/amqp.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"amqp.js","names":["AMQP_URL","connection","amqplib","connect","channel","createChannel","logger","createLogger","checkQueue","consumeChunk","consumeOne","ackMessages","nackMessages","sendToQueue","removeQueue","messagesToRecords","queue","style","toRecord","purge","silly","errorUndefinedQueue","channelInfo","assertQueue","durable","purgeQueue","verbose","messageCount","ApiError","httpStatus","UNPROCESSABLE_ENTITY","error","logError","messages","getData","headers","getHeaderInfo","debug","length","records","message","get","inspect","colors","maxArrayLength","depth","forEach","properties","correlationId","ack","nack","data","JSON","stringify","Buffer","from","persistent","tempChannel","deleteQueue","close","map","content","parse","toString","MarcRecord","messagesToGet","CHUNK_SIZE","pump","count","results","identifiers","identifier","deliveryTag","fields","includes","concat","undefined","INTERNAL_SERVER_ERROR"],"sources":["../src/amqp.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Shared modules for microservices of Melinda rest api batch import system\n*\n* Copyright (C) 2020-2021 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-rest-api-commons\n*\n* melinda-rest-api-commons program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Affero General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-rest-api-commons is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Affero General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport amqplib from 'amqplib';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport {Error as ApiError} from '@natlibfi/melinda-commons';\nimport {createLogger} from '@natlibfi/melinda-backend-commons';\nimport {CHUNK_SIZE} from './constants';\nimport {logError} from './utils';\nimport {inspect} from 'util';\nimport httpStatus from 'http-status';\n\nexport default async function (AMQP_URL) {\n const connection = await amqplib.connect(AMQP_URL);\n const channel = await connection.createChannel();\n const logger = createLogger();\n\n return {checkQueue, consumeChunk, consumeOne, ackMessages, nackMessages, sendToQueue, removeQueue, messagesToRecords};\n\n // eslint-disable-next-line max-statements\n async function checkQueue({queue, style = 'basic', toRecord = true, purge = false}) {\n logger.silly(`checkQueue: ${queue}, Style: ${style}: toRecord: ${toRecord}, Purge: ${purge}`);\n\n try {\n\n errorUndefinedQueue(queue);\n const channelInfo = await channel.assertQueue(queue, {durable: true});\n\n if (purge) {\n await purgeQueue(purge);\n logger.verbose(`Queue ${queue} has purged ${channelInfo.messageCount} messages`);\n return checkQueue({queue, style});\n }\n\n if (channelInfo.messageCount < 1) {\n logger.silly(`checkQueue: ${channelInfo.messageCount} - ${queue} is empty`);\n return false;\n }\n logger.silly(`Queue ${queue} has ${channelInfo.messageCount} messages`);\n\n if (style === 'messages') {\n return channelInfo.messageCount;\n }\n\n // Note: returns one message (+ record, of toRecord: true)\n // note: if toRecord is false returns just plain message / false\n // note: if toRecord is true returns {headers, records, messages} -object / false\n // should this be more consistent?\n if (style === 'one') {\n return consumeOne(queue, toRecord);\n }\n\n // Note: returns a chunk of (100) messages (+ records, if toRecord: true)\n // returns {headers, records, messages} object or {headers, messages} object depending on toRecord\n if (style === 'basic') {\n return consumeChunk(queue, toRecord);\n }\n\n // Defaults:\n throw new ApiError(httpStatus.UNPROCESSABLE_ENTITY);\n } catch (error) {\n logError(error);\n }\n\n function purgeQueue(purge) {\n if (purge) {\n return channel.purgeQueue(queue);\n }\n }\n }\n\n async function consumeChunk(queue, toRecord) {\n logger.silly(`Prepared to consumeChunk from queue: ${queue}`);\n try {\n await channel.assertQueue(queue, {durable: true});\n\n // getData: next chunk (100) messages\n const messages = await getData(queue);\n const headers = getHeaderInfo(messages[0]);\n logger.debug(`consumeChunk (${messages ? messages.length : '0'} from queue ${queue}) ${toRecord ? 'to records' : 'just messages'}`);\n\n if (toRecord) {\n const records = await messagesToRecords(messages);\n return {headers, records, messages};\n }\n\n return {headers, messages};\n } catch (error) {\n logError(error);\n }\n }\n\n async function consumeOne(queue, toRecord) {\n logger.silly(`Prepared to consumeOne from queue: ${queue}`);\n try {\n await channel.assertQueue(queue, {durable: true});\n\n // Returns false if 0 items in queue\n const message = await channel.get(queue);\n\n logger.silly(`Message: ${inspect(message, {colors: true, maxArrayLength: 3, depth: 3})}`);\n // Do not spam the logs\n logger.debug(`consumeOne from queue: ${queue} ${toRecord ? 'to records' : 'just the message'}`);\n\n if (message) {\n if (toRecord) {\n const headers = getHeaderInfo(message);\n const records = messagesToRecords([message]);\n return {headers, records, messages: [message]};\n }\n\n return message;\n }\n\n return false;\n } catch (error) {\n logError(error);\n }\n }\n\n function ackMessages(messages) {\n messages.forEach(message => {\n logger.silly(`Ack message ${message.properties.correlationId}`);\n channel.ack(message);\n });\n }\n\n function nackMessages(messages) {\n messages.forEach(message => {\n logger.silly(`Nack message ${message.properties.correlationId}`);\n channel.nack(message);\n });\n }\n\n async function sendToQueue({queue, correlationId, headers, data}) {\n try {\n logger.silly(`Queue ${queue}`);\n logger.silly(`CorrelationId ${correlationId}`);\n logger.silly(`Data ${JSON.stringify(data)}`);\n logger.silly(`Headers ${JSON.stringify(headers)}`);\n\n errorUndefinedQueue(queue);\n await channel.assertQueue(queue, {durable: true});\n\n channel.sendToQueue(\n queue,\n Buffer.from(JSON.stringify({data})),\n {\n correlationId,\n persistent: true,\n headers\n }\n );\n logger.silly(`Send message for ${correlationId} to queue: ${queue}`);\n } catch (error) {\n logError(error);\n }\n }\n\n async function removeQueue(queue) {\n // deleteQueue borks the channel if the queue does not exist\n // -> use throwaway tempChannel to avoid killing actual channel in use\n // this might be doable also with assertQueue before deleteQueue\n const tempChannel = await connection.createChannel();\n logger.verbose(`Removing queue ${queue}.`);\n await tempChannel.deleteQueue(queue);\n if (tempChannel) { // eslint-disable-line functional/no-conditional-statement\n await tempChannel.close();\n }\n }\n\n // ----------------\n // Helper functions\n // ----------------\n\n function messagesToRecords(messages) {\n logger.debug(`Parsing messages (${messages.length}) to records`);\n\n return messages.map(message => {\n const content = JSON.parse(message.content.toString());\n return new MarcRecord(content.data);\n });\n }\n\n async function getData(queue) {\n logger.debug(`Getting queue data from ${queue}`);\n try {\n const {messageCount} = await channel.checkQueue(queue);\n logger.silly(`There is ${messageCount} messages in queue ${queue}`);\n const messagesToGet = messageCount >= CHUNK_SIZE ? CHUNK_SIZE : messageCount;\n logger.silly(`Getting ${messagesToGet} messages from queue ${queue}`);\n\n const messages = await pump(messagesToGet);\n\n logger.debug(`Returning ${messages.length} unique messages`);\n\n return messages;\n } catch (error) {\n logError(error);\n }\n\n async function pump(count, results = [], identifiers = []) {\n if (count === 0) {\n return results;\n }\n\n const message = await channel.get(queue);\n const identifier = {\n correlationId: message.properties.correlationId,\n deliveryTag: message.fields.deliveryTag\n };\n // Filter not unique messages\n if (identifiers.includes(identifier)) {\n return pump(count - 1, results, identifiers);\n }\n\n return pump(count - 1, results.concat(message), identifiers.concat(identifier));\n }\n }\n\n function getHeaderInfo(data) {\n return data.properties.headers;\n }\n\n function errorUndefinedQueue(queue) {\n if (queue === undefined || queue === '' || queue === null) {\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `Undefined queue!`);\n }\n }\n}\n\n\n"],"mappings":";;;;;;AA4BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAqC;AAnCrC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAWe,wBAAgBA,QAAQ,EAAE;EACvC,MAAMC,UAAU,GAAG,MAAMC,gBAAO,CAACC,OAAO,CAACH,QAAQ,CAAC;EAClD,MAAMI,OAAO,GAAG,MAAMH,UAAU,CAACI,aAAa,EAAE;EAChD,MAAMC,MAAM,GAAG,IAAAC,mCAAY,GAAE;EAE7B,OAAO;IAACC,UAAU;IAAEC,YAAY;IAAEC,UAAU;IAAEC,WAAW;IAAEC,YAAY;IAAEC,WAAW;IAAEC,WAAW;IAAEC;EAAiB,CAAC;;EAErH;EACA,eAAeP,UAAU,CAAC;IAACQ,KAAK;IAAEC,KAAK,GAAG,OAAO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MAC9B,CAAC;MACD;MACA,IAAIF,WAAW,CAACI,QAAQ,CAACH,UAAU,CAAC,EAAE;QACpC,OAAOJ,IAAI,CAACC,KAAK,GAAG,CAAC,EAAEC,OAAO,EAAEC,WAAW,CAAC;MAC9C;MAEA,OAAOH,IAAI,CAACC,KAAK,GAAG,CAAC,EAAEC,OAAO,CAACM,MAAM,CAACnC,OAAO,CAAC,EAAE8B,WAAW,CAACK,MAAM,CAACJ,UAAU,CAAC,CAAC;IACjF;EACF;EAEA,SAASnC,aAAa,CAACe,IAAI,EAAE;IAC3B,OAAOA,IAAI,CAACJ,UAAU,CAACZ,OAAO;EAChC;EAEA,SAASd,mBAAmB,CAACL,KAAK,EAAE;IAClC,IAAIA,KAAK,KAAK4D,SAAS,IAAI5D,KAAK,KAAK,EAAE,IAAIA,KAAK,KAAK,IAAI,EAAE;MACzD,MAAM,IAAIY,qBAAQ,CAACC,mBAAU,CAACgD,qBAAqB,EAAG,kBAAiB,CAAC;IAC1E;EACF;AACF"}
1
+ {"version":3,"file":"amqp.js","names":["AMQP_URL","runHealthCheck","logger","createLogger","debug","createDebugLogger","debugHC","extend","connection","amqplib","connect","channel","createChannel","healthCheckLoop","healthCheck","checkQueue","consumeChunk","consumeOne","ackMessages","nackMessages","sendToQueue","removeQueue","messagesToRecords","closeChannel","closeConnection","close","wait","setTimeoutPromise","promisify","setTimeout","assertQueue","durable","error","errorToThrow","JSON","stringify","handleAmqpErrors","queue","style","toRecord","purge","errorUndefinedQueue","channelInfo","purgeQueue","verbose","messageCount","ApiError","httpStatus","UNPROCESSABLE_ENTITY","messages","getData","headers","getHeaderInfo","length","records","message","get","inspect","colors","maxArrayLength","depth","forEach","properties","correlationId","ack","nack","data","Buffer","from","persistent","tempChannel","deleteQueue","map","content","parse","toString","MarcRecord","messagesToGet","CHUNK_SIZE","pump","count","results","identifiers","identifier","deliveryTag","fields","includes","concat","undefined","INTERNAL_SERVER_ERROR","newError","status","payload","logError"],"sources":["../src/amqp.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Shared modules for microservices of Melinda rest api batch import system\n*\n* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-rest-api-commons\n*\n* melinda-rest-api-commons program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Affero General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-rest-api-commons is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Affero General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport amqplib from 'amqplib';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport {Error as ApiError} from '@natlibfi/melinda-commons';\nimport {createLogger} from '@natlibfi/melinda-backend-commons';\nimport createDebugLogger from 'debug';\nimport {CHUNK_SIZE} from './constants';\n//import {logError} from './utils';\nimport {promisify, inspect} from 'util';\nimport httpStatus from 'http-status';\nimport {logError} from './utils';\n\nexport default async function (AMQP_URL, runHealthCheck = false) {\n const logger = createLogger();\n const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons:amqp');\n const debugHC = debug.extend('HC');\n\n debug(`Creating an AMQP operator to ${AMQP_URL}`);\n const connection = await amqplib.connect(AMQP_URL);\n const channel = await connection.createChannel();\n\n const healthCheckLoop = runHealthCheck ? healthCheck() : 'Not running health check';\n\n debug(`Connection: ${connection}`);\n debug(`Channel: ${channel}`);\n debug(`HealthCheckLoop ${healthCheckLoop}`);\n\n return {checkQueue, consumeChunk, consumeOne, ackMessages, nackMessages, sendToQueue, removeQueue, messagesToRecords, closeChannel, closeConnection};\n\n async function closeChannel() {\n debug(`Closing channel`);\n await channel.close();\n debug(`Channel: ${channel}`);\n }\n\n async function closeConnection() {\n debug(`Closing connection`);\n await connection.close();\n debug(`Connection: ${connection}`);\n }\n\n async function healthCheck(wait = false) {\n const setTimeoutPromise = promisify(setTimeout);\n if (wait) {\n await setTimeoutPromise(wait);\n return healthCheck(false);\n }\n\n try {\n debugHC(`Health checking amqp by asserting a queue`);\n await channel.assertQueue('HEALTHCHECK', {durable: false});\n debugHC(`Waiting 200ms before running healthCheck next`);\n return healthCheck('200');\n } catch (error) {\n const errorToThrow = error;\n debugHC(`HealthCheck error ${JSON.stringify(error)}`);\n handleAmqpErrors(errorToThrow);\n }\n }\n\n // eslint-disable-next-line max-statements\n async function checkQueue({queue, style = 'basic', toRecord = true, purge = false}) {\n debug(`checkQueue: ${queue}, Style: ${style}, toRecord: ${toRecord}, Purge: ${purge}`);\n\n try {\n\n errorUndefinedQueue(queue);\n const channelInfo = await channel.assertQueue(queue, {durable: true});\n\n if (purge) {\n await purgeQueue(purge);\n logger.verbose(`Queue ${queue} has purged ${channelInfo.messageCount} messages`);\n debug(`Queue ${queue} has purged ${channelInfo.messageCount} messages`);\n return checkQueue({queue, style});\n }\n\n if (style === 'messages') {\n return channelInfo.messageCount;\n }\n\n if (channelInfo.messageCount < 1) {\n debug(`checkQueue: ${channelInfo.messageCount} - ${queue} is empty`);\n return false;\n }\n debug(`Queue ${queue} has ${channelInfo.messageCount} messages`);\n\n // Note: returns one message (+ record, of toRecord: true)\n // note: if toRecord is false returns just plain message / false\n // note: if toRecord is true returns {headers, records, messages} -object / false\n // should this be more consistent?\n if (style === 'one') {\n return consumeOne(queue, toRecord);\n }\n\n // Note: returns a chunk of (100) messages (+ records, if toRecord: true)\n // returns {headers, records, messages} object or {headers, messages} object depending on toRecord\n if (style === 'basic') {\n return consumeChunk(queue, toRecord);\n }\n\n // Defaults:\n throw new ApiError(httpStatus.UNPROCESSABLE_ENTITY);\n } catch (error) {\n handleAmqpErrors(error);\n }\n\n function purgeQueue(purge) {\n debug(`Purging queue: ${queue}, purge: ${purge}`);\n if (purge) {\n return channel.purgeQueue(queue);\n }\n }\n }\n\n async function consumeChunk(queue, toRecord) {\n debug(`Prepared to consumeChunk from queue: ${queue}`);\n try {\n await channel.assertQueue(queue, {durable: true});\n\n // getData: next chunk (100) messages\n const messages = await getData(queue);\n const headers = getHeaderInfo(messages[0]);\n debug(`consumeChunk (${messages ? messages.length : '0'} from queue ${queue}) ${toRecord ? 'to records' : 'just messages'}`);\n\n if (toRecord) {\n const records = await messagesToRecords(messages);\n return {headers, records, messages};\n }\n\n return {headers, messages};\n } catch (error) {\n handleAmqpErrors(error);\n }\n }\n\n async function consumeOne(queue, toRecord) {\n debug(`Prepared to consumeOne from queue: ${queue}`);\n try {\n await channel.assertQueue(queue, {durable: true});\n\n // Returns false if 0 items in queue\n const message = await channel.get(queue);\n\n debug(`Message: ${inspect(message, {colors: true, maxArrayLength: 3, depth: 3})}`);\n // Do not spam the logs\n debug(`consumeOne from queue: ${queue} ${toRecord ? 'to records' : 'just the message'}`);\n\n if (message) {\n if (toRecord) {\n const headers = getHeaderInfo(message);\n const records = messagesToRecords([message]);\n return {headers, records, messages: [message]};\n }\n\n return message;\n }\n\n return false;\n } catch (error) {\n handleAmqpErrors(error);\n }\n }\n\n function ackMessages(messages) {\n messages.forEach(message => {\n debug(`Ack message ${message.properties.correlationId}`);\n channel.ack(message);\n });\n }\n\n function nackMessages(messages) {\n messages.forEach(message => {\n debug(`Nack message ${message.properties.correlationId}`);\n channel.nack(message);\n });\n }\n\n async function sendToQueue({queue, correlationId, headers, data}) {\n debug(`sendToQueue`);\n // eslint-disable-next-line no-useless-catch\n try {\n debug(`Queue ${queue}`);\n debug(`CorrelationId ${correlationId}`);\n debug(`Data ${JSON.stringify(data)}`);\n debug(`Headers ${JSON.stringify(headers)}`);\n\n errorUndefinedQueue(queue);\n\n debug(`Asserting queue: ${queue}`);\n await channel.assertQueue(queue, {durable: true});\n\n debug(`Actually sendToQueue: ${queue}`);\n await channel.sendToQueue(\n queue,\n Buffer.from(JSON.stringify({data})),\n {\n correlationId,\n persistent: true,\n headers\n }\n );\n debug(`Send message for ${correlationId} to queue: ${queue}`);\n\n\n } catch (error) {\n const errorToThrow = error;\n //if (error instanceof ApiError) {\n // throw error;\n //}\n debug(`SendToQueue errored: ${JSON.stringify(error)}`);\n handleAmqpErrors(errorToThrow);\n }\n }\n\n async function removeQueue(queue) {\n // deleteQueue borks the channel if the queue does not exist\n // -> use throwaway tempChannel to avoid killing actual channel in use\n // this might be doable also with assertQueue before deleteQueue\n const tempChannel = await connection.createChannel();\n logger.verbose(`Removing queue ${queue}.`);\n debug(`Removing queue ${queue}.`);\n await tempChannel.deleteQueue(queue);\n\n if (tempChannel) {\n await tempChannel.close();\n return;\n }\n\n return;\n }\n\n // ----------------\n // Helper functions\n // ----------------\n\n function messagesToRecords(messages) {\n debug(`Parsing messages (${messages.length}) to records`);\n\n return messages.map(message => {\n const content = JSON.parse(message.content.toString());\n return new MarcRecord(content.data);\n });\n }\n\n async function getData(queue) {\n debug(`Getting queue data from ${queue}`);\n try {\n const {messageCount} = await channel.checkQueue(queue);\n debug(`There is ${messageCount} messages in queue ${queue}`);\n const messagesToGet = messageCount >= CHUNK_SIZE ? CHUNK_SIZE : messageCount;\n debug(`Getting ${messagesToGet} messages from queue ${queue}`);\n\n const messages = await pump(messagesToGet);\n\n debug(`Returning ${messages.length} unique messages`);\n\n return messages;\n } catch (error) {\n handleAmqpErrors(error);\n }\n\n async function pump(count, results = [], identifiers = []) {\n if (count === 0) {\n return results;\n }\n\n const message = await channel.get(queue);\n const identifier = {\n correlationId: message.properties.correlationId,\n deliveryTag: message.fields.deliveryTag\n };\n // Filter not unique messages\n if (identifiers.includes(identifier)) {\n return pump(count - 1, results, identifiers);\n }\n\n return pump(count - 1, results.concat(message), identifiers.concat(identifier));\n }\n }\n\n function getHeaderInfo(data) {\n return data.properties.headers;\n }\n\n function errorUndefinedQueue(queue) {\n if (queue === undefined || queue === '' || queue === null) {\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `Undefined queue!`);\n }\n }\n\n function handleAmqpErrors(error) {\n const newError = error;\n //debug(`HandleAmqpErrors got an error: ${JSON.stringify(error)}`);\n if (error instanceof ApiError) {\n throw new ApiError(newError.status, newError.payload);\n }\n logError(error);\n throw newError;\n }\n}\n\n\n"],"mappings":";;;;;;AA4BA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AAAiC;AArCjC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAQA;;AAKe,wBAAgBA,QAAQ,EAAEC,cAAc,GAAG,KAAK,EAAE;EAC/D,MAAMC,MAAM,GAAG,IAAAC,mCAAY,GAAE;EAC7B,MAAMC,KAAK,GAAG,IAAAC,cAAiB,EAAC,yCAAyC,CAAC;EAC1E,MAAMC,OAAO,GAAGF,KAAK,CAACG,MAAM,CAAC,IAAI,CAAC;EAElCH,KAAK,CAAE,gCAA+BJ,QAAS,EAAC,CAAC;EACjD,MAAMQ,UAAU,GAAG,MAAMC,gBAAO,CAACC,OAAO,CAACV,QAAQ,CAAC;EAClD,MAAMW,OAAO,GAAG,MAAMH,UAAU,CAACI,aAAa,EAAE;EAEhD,MAAMC,eAAe,GAAGZ,cAAc,GAAGa,WAAW,EAAE,GAAG,0BAA0B;EAEnFV,KAAK,CAAE,eAAcI,UAAW,EAAC,CAAC;EAClCJ,KAAK,CAAE,YAAWO,OAAQ,EAAC,CAAC;EAC5BP,KAAK,CAAE,mBAAkBS,eAAgB,EAAC,CAAC;EAE3C,OAAO;IAACE,UAAU;IAAEC,YAAY;IAAEC,UAAU;IAAEC,WAAW;IAAEC,YAAY;IAAEC,WAAW;IAAEC,WAAW;IAAEC,iBAAiB;IAAEC,YAAY;IAAEC;EAAe,CAAC;EAEpJ,eAAeD,YAAY,GAAG;IAC5BnB,KAAK,CAAE,iBAAgB,CAAC;IACxB,MAAMO,OA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AAK,GAAG,CAAC,EAAEC,OAAO,EAAEC,WAAW,CAAC;MAC9C;MAEA,OAAOH,IAAI,CAACC,KAAK,GAAG,CAAC,EAAEC,OAAO,CAACM,MAAM,CAAChC,OAAO,CAAC,EAAE2B,WAAW,CAACK,MAAM,CAACJ,UAAU,CAAC,CAAC;IACjF;EACF;EAEA,SAAS/B,aAAa,CAACc,IAAI,EAAE;IAC3B,OAAOA,IAAI,CAACJ,UAAU,CAACX,OAAO;EAChC;EAEA,SAASV,mBAAmB,CAACJ,KAAK,EAAE;IAClC,IAAIA,KAAK,KAAKmD,SAAS,IAAInD,KAAK,KAAK,EAAE,IAAIA,KAAK,KAAK,IAAI,EAAE;MACzD,MAAM,IAAIS,qBAAQ,CAACC,mBAAU,CAAC0C,qBAAqB,EAAG,kBAAiB,CAAC;IAC1E;EACF;EAEA,SAASrD,gBAAgB,CAACJ,KAAK,EAAE;IAC/B,MAAM0D,QAAQ,GAAG1D,KAAK;IACtB;IACA,IAAIA,KAAK,YAAYc,qBAAQ,EAAE;MAC7B,MAAM,IAAIA,qBAAQ,CAAC4C,QAAQ,CAACC,MAAM,EAAED,QAAQ,CAACE,OAAO,CAAC;IACvD;IACA,IAAAC,eAAQ,EAAC7D,KAAK,CAAC;IACf,MAAM0D,QAAQ;EAChB;AACF"}
@@ -0,0 +1,252 @@
1
+ "use strict";
2
+
3
+ var _chai = require("chai");
4
+ var _fixura = require("@natlibfi/fixura");
5
+ var _fixugen = _interopRequireDefault(require("@natlibfi/fixugen"));
6
+ var _debug = _interopRequireDefault(require("debug"));
7
+ var _index = require("./index");
8
+ var _melindaCommons = require("@natlibfi/melinda-commons");
9
+ var _util = require("util");
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+ /**
12
+ *
13
+ * @licstart The following is the entire license notice for the JavaScript code in this file.
14
+ *
15
+ * Shared modules for microservices of Melinda rest api batch import system
16
+ *
17
+ * Copyright (C) 2022 University Of Helsinki (The National Library Of Finland)
18
+ *
19
+ * This file is part of melinda-rest-api-commons
20
+ *
21
+ * melinda-rest-api-commons program is free software: you can redistribute it and/or modify
22
+ * it under the terms of the GNU Affero General Public License as
23
+ * published by the Free Software Foundation, either version 3 of the
24
+ * License, or (at your option) any later version.
25
+ *
26
+ * melinda-rest-api-commons is distributed in the hope that it will be useful,
27
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
28
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29
+ * GNU Affero General Public License for more details.
30
+ *
31
+ * You should have received a copy of the GNU Affero General Public License
32
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
33
+ *
34
+ * @licend The above is the entire license notice
35
+ * for the JavaScript code in this file.
36
+ *
37
+ */
38
+
39
+ //import inspect from 'util';
40
+
41
+ const debug = (0, _debug.default)('@natlibfi/melinda-rest-api-commons:amqp:test');
42
+ //const debugData = debug.extend('data');
43
+
44
+ const setTimeoutPromise = (0, _util.promisify)(setTimeout);
45
+ (0, _fixugen.default)({
46
+ callback,
47
+ path: [__dirname, '..', 'test-fixtures', 'amqp'],
48
+ recurse: false,
49
+ useMetadataFile: true,
50
+ fixura: {
51
+ failWhenNotFound: false,
52
+ reader: _fixura.READERS.JSON
53
+ }
54
+ });
55
+
56
+ // eslint-disable-next-line max-statements
57
+ async function callback() {
58
+ const testData = {
59
+ queue: 'TESTQUEUE',
60
+ correlationId: '5b7be681-0d4d-47ca-b5d7-1531173ec6bf',
61
+ data: {
62
+ 'leader': '02518cam a2200745zi 4500',
63
+ 'fields': [{
64
+ 'tag': '001',
65
+ 'value': '000019640'
66
+ }]
67
+ }
68
+ };
69
+ debug(`Testing amqp against a local AMQP instance - we'll need some kind of mockup for this`);
70
+ const amqpUrl = 'amqp://127.0.0.1:5672/';
71
+ debug(`Connecting to ${amqpUrl}, with healthCheck running`);
72
+ const amqpOperator = await (0, _index.amqpFactory)(amqpUrl, true);
73
+ debug(`**********`);
74
+ await testHealthCheckLoopWorking(amqpOperator);
75
+ debug(`**********`);
76
+ await testHealthCheckLoopErroring(amqpOperator);
77
+ await amqpOperator.closeConnection();
78
+ debug(`--- Create a new amqpOperator2 ----`);
79
+ debug(`Connecting to ${amqpUrl}, without healthCheck running`);
80
+ const amqpOperator2 = await (0, _index.amqpFactory)(amqpUrl);
81
+ debug(`**********`);
82
+ debug(`*** Test purging the queue: ${testData.queue} *******`);
83
+ const purgeMessage = await amqpOperator2.checkQueue({
84
+ queue: testData.queue,
85
+ toRecord: false,
86
+ purge: true
87
+ });
88
+ (0, _chai.expect)(purgeMessage).to.eql(false);
89
+ await testSendToQueue(amqpOperator2, testData);
90
+ debug(`* wait, otherwise queue is not ready *`);
91
+ await setTimeoutPromise('100');
92
+ debug(`*** Test getting messageCount from theQueue: ${testData.queue} *******`);
93
+ const messageCount = await amqpOperator2.checkQueue({
94
+ queue: testData.queue,
95
+ style: 'messages'
96
+ });
97
+ debug(messageCount);
98
+ (0, _chai.expect)(messageCount).to.eql(1);
99
+ debug(`*** Test checking theQueue: ${testData.queue} *******`);
100
+ const message = await amqpOperator2.checkQueue({
101
+ queue: testData.queue,
102
+ style: 'one',
103
+ toRecord: false,
104
+ purge: false
105
+ });
106
+ (0, _chai.expect)(message).to.not.equal('goo');
107
+ debug(message);
108
+ debug(`*** Test nacking the message: ${testData.queue} *******`);
109
+ await amqpOperator2.nackMessages([message]);
110
+ debug(`* wait, otherwise queue is not ready *`);
111
+ await setTimeoutPromise('100');
112
+ const messageCountAfterNack = await amqpOperator2.checkQueue({
113
+ queue: testData.queue,
114
+ style: 'messages'
115
+ });
116
+ debug(`After nack: ${messageCountAfterNack}`);
117
+ (0, _chai.expect)(messageCountAfterNack).to.eql(1);
118
+ const message2 = await amqpOperator2.checkQueue({
119
+ queue: testData.queue,
120
+ style: 'one',
121
+ toRecord: false,
122
+ purge: false
123
+ });
124
+ debug(`*** Test acking the message: ${testData.queue} *******`);
125
+ await amqpOperator2.ackMessages([message2]);
126
+ debug(`* wait, otherwise queue is not ready *`);
127
+ await setTimeoutPromise('100');
128
+ const messageCountAfterAck = await amqpOperator2.checkQueue({
129
+ queue: testData.queue,
130
+ style: 'messages'
131
+ });
132
+ debug(`After ack: ${messageCountAfterAck}`);
133
+ (0, _chai.expect)(messageCountAfterAck).to.eql(0);
134
+ debug(`*** Test removing the the queue: ${testData.queue} *******`);
135
+ const removeResult = await amqpOperator2.removeQueue(testData.queue);
136
+ debug(removeResult);
137
+ debug(`**********`);
138
+ try {
139
+ await testUndefinedQueue(amqpOperator2, testData);
140
+ } catch (error) {
141
+ //expect(error()).to.be.an('apierror');
142
+ const errorAsString = JSON.stringify(error);
143
+ (0, _chai.expect)(error).to.be.an.instanceof(_melindaCommons.Error);
144
+ (0, _chai.expect)(errorAsString).to.eql(`{"status":500,"payload":"Undefined queue!"}`);
145
+ }
146
+ debug(`**********`);
147
+ debug(`--- Closing amqpOperator2 ----`);
148
+ await amqpOperator2.closeChannel();
149
+ await amqpOperator2.closeConnection();
150
+ debug(`**********`);
151
+ try {
152
+ await testSendToQueue(amqpOperator2, testData);
153
+ } catch (error) {
154
+ (0, _chai.expect)(error.message).to.eql(`Channel closed`);
155
+ debug(`We got an error: ${JSON.stringify(error)}`);
156
+ }
157
+ debug(`**********`);
158
+ debug(`Done`);
159
+ //}
160
+
161
+ async function testHealthCheckLoopWorking(amqpOperator) {
162
+ debug(`Testing healthCheckLoop for ${amqpOperator}`);
163
+ debug(`Waiting 0.5s and expecting healthCheckLoop to work`);
164
+ await setTimeoutPromise('500');
165
+ debug(`Amqp Operator should have been alive.`);
166
+ }
167
+ async function testHealthCheckLoopErroring(amqpOperator) {
168
+ debug(`Testing healthCheckLoop with closed channel`);
169
+ amqpOperator.closeChannel();
170
+ debug(`Waiting 0.5s and expecting healthCheckLoop to throw error`);
171
+ await setTimeoutPromise('500');
172
+ debug(`amqpOperator should have errored`);
173
+ }
174
+ async function testSendToQueue(amqpOperator, testData) {
175
+ // Test sendToQueue
176
+ debug(`*** Testing sendToQueue ***`);
177
+ const {
178
+ queue,
179
+ correlationId,
180
+ data
181
+ } = testData;
182
+ const headers = {
183
+ correlationId
184
+ };
185
+ await amqpOperator.sendToQueue({
186
+ queue,
187
+ correlationId,
188
+ headers,
189
+ data
190
+ });
191
+ return;
192
+ }
193
+
194
+ /*
195
+ async function testCheckQueue(amqpOperator, testData) {
196
+ debug(`Testing checkQueue`);
197
+ const {queue} = testData;
198
+ const message = await amqpOperator.checkQueue({queue, style: 'one', toRecord: false, purge: false});
199
+ debug(message);
200
+ return message;
201
+ //expect(message).to.be.defined;
202
+ }
203
+ */
204
+
205
+ async function testUndefinedQueue(amqpOperator, testData) {
206
+ // Test sendToQueue
207
+ debug(`Testing sendToQueue with undefined queue`);
208
+ const {
209
+ correlationId,
210
+ data
211
+ } = testData;
212
+ const headers = {
213
+ correlationId
214
+ };
215
+ const queue = undefined;
216
+ (0, _chai.expect)(await amqpOperator.sendToQueue({
217
+ queue,
218
+ correlationId,
219
+ headers,
220
+ data
221
+ })).to.throw();
222
+ }
223
+
224
+ /*
225
+ await amqpOperator.sendToQueue({queue, correlationId, headers, data});
226
+ await amqpOperator.ackMessages([message]);
227
+ const message2 = await amqpOperator.checkQueue({queue, style: 'one', toRecord: false, purge: false});
228
+ await amqpOperator.ackMessages([message2]);
229
+ expect(message2).to.be(true);
230
+ //debug(`FOO: ${JSON.stringify(message)}`);
231
+ // http:
232
+ // await amqpOperator.sendToQueue({queue: 'REQUESTS', correlationId, headers, data});
233
+ // validator:
234
+ // const message = await amqpOperator.checkQueue({queue: 'REQUESTS', style: 'one', toRecord: false, purge: false});
235
+ // await amqpOperator.ackMessages([message]);
236
+ // const message = await amqpOperator.checkQueue({queue: validatorQueue, style: 'one', toRecord: false, purge: false});
237
+ // amqpOperator.removeQueue(validatorQueue);
238
+ //await amqpOperator.checkQueue({queue: operationQueue, style: 'messages', purge: true});
239
+ // await amqpOperator.checkQueue({queue: `${headers.operation}.${correlationId}`, style: 'messages', purge: true});
240
+ // importer
241
+ /*
242
+ const {headers, records, messages} = await amqpOperator.checkQueue({queue: `${operation}.${correlationId}`, style: 'basic', toRecord: true, purge: purgeQueues});
243
+ await amqpOperator.nackMessages(messages);
244
+ await amqpOperator.sendToQueue({
245
+ const {messages} = await amqpOperator.checkQueue({queue, style: 'basic', toRecords: false, purge: false});
246
+ await amqpOperator.ackMessages(messages);
247
+ const processMessage = await amqpOperator.checkQueue({queue: processQueue, style: 'one', toRecord: false, purge: false});
248
+ const {headers: firstMessageHeaders, messages} = await amqpOperator.checkQueue({queue, style: 'basic', toRecord: false, purge: false});
249
+ const queueMessagesCount = await amqpOperator.checkQueue({queue, style: 'messages'});
250
+ */
251
+ }
252
+ //# sourceMappingURL=amqp.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"amqp.spec.js","names":["debug","createDebugLogger","setTimeoutPromise","promisify","setTimeout","generateTests","callback","path","__dirname","recurse","useMetadataFile","fixura","failWhenNotFound","reader","READERS","JSON","testData","queue","correlationId","data","amqpUrl","amqpOperator","amqpFactory","testHealthCheckLoopWorking","testHealthCheckLoopErroring","closeConnection","amqpOperator2","purgeMessage","checkQueue","toRecord","purge","expect","to","eql","testSendToQueue","messageCount","style","message","not","equal","nackMessages","messageCountAfterNack","message2","ackMessages","messageCountAfterAck","removeResult","removeQueue","testUndefinedQueue","error","errorAsString","stringify","be","an","instanceof","ApiError","closeChannel","headers","sendToQueue","undefined","throw"],"sources":["../src/amqp.spec.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Shared modules for microservices of Melinda rest api batch import system\n*\n* Copyright (C) 2022 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-rest-api-commons\n*\n* melinda-rest-api-commons program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Affero General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-rest-api-commons is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Affero General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport {expect} from 'chai';\nimport {READERS} from '@natlibfi/fixura';\nimport generateTests from '@natlibfi/fixugen';\nimport createDebugLogger from 'debug';\nimport {amqpFactory} from './index';\nimport {Error as ApiError} from '@natlibfi/melinda-commons';\n//import inspect from 'util';\nimport {promisify} from 'util';\n\nconst debug = createDebugLogger('@natlibfi/melinda-rest-api-commons:amqp:test');\n//const debugData = debug.extend('data');\n\nconst setTimeoutPromise = promisify(setTimeout);\n\ngenerateTests({\n callback,\n path: [__dirname, '..', 'test-fixtures', 'amqp'],\n recurse: false,\n useMetadataFile: true,\n fixura: {\n failWhenNotFound: false,\n reader: READERS.JSON\n }\n});\n\n// eslint-disable-next-line max-statements\nasync function callback() {\n\n const testData = {\n queue: 'TESTQUEUE',\n correlationId: '5b7be681-0d4d-47ca-b5d7-1531173ec6bf',\n data: {'leader': '02518cam a2200745zi 4500', 'fields': [{'tag': '001', 'value': '000019640'}]}\n };\n\n debug(`Testing amqp against a local AMQP instance - we'll need some kind of mockup for this`);\n const amqpUrl = 'amqp://127.0.0.1:5672/';\n\n debug(`Connecting to ${amqpUrl}, with healthCheck running`);\n const amqpOperator = await amqpFactory(amqpUrl, true);\n\n debug(`**********`);\n await testHealthCheckLoopWorking(amqpOperator);\n\n debug(`**********`);\n await testHealthCheckLoopErroring(amqpOperator);\n\n await amqpOperator.closeConnection();\n\n debug(`--- Create a new amqpOperator2 ----`);\n debug(`Connecting to ${amqpUrl}, without healthCheck running`);\n const amqpOperator2 = await amqpFactory(amqpUrl);\n\n debug(`**********`);\n debug(`*** Test purging the queue: ${testData.queue} *******`);\n const purgeMessage = await amqpOperator2.checkQueue({queue: testData.queue, toRecord: false, purge: true});\n expect(purgeMessage).to.eql(false);\n await testSendToQueue(amqpOperator2, testData);\n debug(`* wait, otherwise queue is not ready *`);\n await setTimeoutPromise('100');\n\n debug(`*** Test getting messageCount from theQueue: ${testData.queue} *******`);\n const messageCount = await amqpOperator2.checkQueue({queue: testData.queue, style: 'messages'});\n debug(messageCount);\n expect(messageCount).to.eql(1);\n\n debug(`*** Test checking theQueue: ${testData.queue} *******`);\n const message = await amqpOperator2.checkQueue({queue: testData.queue, style: 'one', toRecord: false, purge: false});\n expect(message).to.not.equal('goo');\n debug(message);\n\n debug(`*** Test nacking the message: ${testData.queue} *******`);\n await amqpOperator2.nackMessages([message]);\n debug(`* wait, otherwise queue is not ready *`);\n await setTimeoutPromise('100');\n\n const messageCountAfterNack = await amqpOperator2.checkQueue({queue: testData.queue, style: 'messages'});\n debug(`After nack: ${messageCountAfterNack}`);\n expect(messageCountAfterNack).to.eql(1);\n\n const message2 = await amqpOperator2.checkQueue({queue: testData.queue, style: 'one', toRecord: false, purge: false});\n\n debug(`*** Test acking the message: ${testData.queue} *******`);\n await amqpOperator2.ackMessages([message2]);\n debug(`* wait, otherwise queue is not ready *`);\n await setTimeoutPromise('100');\n\n const messageCountAfterAck = await amqpOperator2.checkQueue({queue: testData.queue, style: 'messages'});\n debug(`After ack: ${messageCountAfterAck}`);\n expect(messageCountAfterAck).to.eql(0);\n\n debug(`*** Test removing the the queue: ${testData.queue} *******`);\n const removeResult = await amqpOperator2.removeQueue(testData.queue);\n debug(removeResult);\n\n\n debug(`**********`);\n try {\n await testUndefinedQueue(amqpOperator2, testData);\n } catch (error) {\n //expect(error()).to.be.an('apierror');\n const errorAsString = JSON.stringify(error);\n expect(error).to.be.an.instanceof(ApiError);\n expect(errorAsString).to.eql(`{\"status\":500,\"payload\":\"Undefined queue!\"}`);\n }\n debug(`**********`);\n\n debug(`--- Closing amqpOperator2 ----`);\n await amqpOperator2.closeChannel();\n await amqpOperator2.closeConnection();\n\n debug(`**********`);\n\n try {\n await testSendToQueue(amqpOperator2, testData);\n } catch (error) {\n expect(error.message).to.eql(`Channel closed`);\n debug(`We got an error: ${JSON.stringify(error)}`);\n }\n debug(`**********`);\n\n debug(`Done`);\n //}\n\n async function testHealthCheckLoopWorking(amqpOperator) {\n debug(`Testing healthCheckLoop for ${amqpOperator}`);\n debug(`Waiting 0.5s and expecting healthCheckLoop to work`);\n await setTimeoutPromise('500');\n debug(`Amqp Operator should have been alive.`);\n }\n\n async function testHealthCheckLoopErroring(amqpOperator) {\n debug(`Testing healthCheckLoop with closed channel`);\n amqpOperator.closeChannel();\n debug(`Waiting 0.5s and expecting healthCheckLoop to throw error`);\n await setTimeoutPromise('500');\n debug(`amqpOperator should have errored`);\n }\n\n async function testSendToQueue(amqpOperator, testData) {\n // Test sendToQueue\n debug(`*** Testing sendToQueue ***`);\n\n const {queue, correlationId, data} = testData;\n const headers = {correlationId};\n\n await amqpOperator.sendToQueue({queue, correlationId, headers, data});\n return;\n }\n\n /*\n async function testCheckQueue(amqpOperator, testData) {\n debug(`Testing checkQueue`);\n const {queue} = testData;\n const message = await amqpOperator.checkQueue({queue, style: 'one', toRecord: false, purge: false});\n debug(message);\n return message;\n //expect(message).to.be.defined;\n }\n*/\n\n async function testUndefinedQueue(amqpOperator, testData) {\n // Test sendToQueue\n debug(`Testing sendToQueue with undefined queue`);\n const {correlationId, data} = testData;\n const headers = {correlationId};\n const queue = undefined;\n\n expect(await amqpOperator.sendToQueue({queue, correlationId, headers, data})).to.throw();\n }\n\n\n /*\n\n\n await amqpOperator.sendToQueue({queue, correlationId, headers, data});\n\n\n await amqpOperator.ackMessages([message]);\n const message2 = await amqpOperator.checkQueue({queue, style: 'one', toRecord: false, purge: false});\n await amqpOperator.ackMessages([message2]);\n\n expect(message2).to.be(true);\n\n\n //debug(`FOO: ${JSON.stringify(message)}`);\n\n\n // http:\n // await amqpOperator.sendToQueue({queue: 'REQUESTS', correlationId, headers, data});\n\n // validator:\n // const message = await amqpOperator.checkQueue({queue: 'REQUESTS', style: 'one', toRecord: false, purge: false});\n // await amqpOperator.ackMessages([message]);\n // const message = await amqpOperator.checkQueue({queue: validatorQueue, style: 'one', toRecord: false, purge: false});\n // amqpOperator.removeQueue(validatorQueue);\n //await amqpOperator.checkQueue({queue: operationQueue, style: 'messages', purge: true});\n // await amqpOperator.checkQueue({queue: `${headers.operation}.${correlationId}`, style: 'messages', purge: true});\n\n // importer\n /*\nconst {headers, records, messages} = await amqpOperator.checkQueue({queue: `${operation}.${correlationId}`, style: 'basic', toRecord: true, purge: purgeQueues});\n await amqpOperator.nackMessages(messages);\n await amqpOperator.sendToQueue({\n const {messages} = await amqpOperator.checkQueue({queue, style: 'basic', toRecords: false, purge: false});\n await amqpOperator.ackMessages(messages);\n const processMessage = await amqpOperator.checkQueue({queue: processQueue, style: 'one', toRecord: false, purge: false});\n const {headers: firstMessageHeaders, messages} = await amqpOperator.checkQueue({queue, style: 'basic', toRecord: false, purge: false});\n const queueMessagesCount = await amqpOperator.checkQueue({queue, style: 'messages'});\n\n\n */\n\n}\n\n"],"mappings":";;AA4BA;AACA;AACA;AACA;AACA;AACA;AAEA;AAA+B;AAnC/B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAQA;;AAGA,MAAMA,KAAK,GAAG,IAAAC,cAAiB,EAAC,8CAA8C,CAAC;AAC/E;;AAEA,MAAMC,iBAAiB,GAAG,IAAAC,eAAS,EAACC,UAAU,CAAC;AAE/C,IAAAC,gBAAa,EAAC;EACZC,QAAQ;EACRC,IAAI,EAAE,CAACC,SAAS,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,CAAC;EAChDC,OAAO,EAAE,KAAK;EACdC,eAAe,EAAE,IAAI;EACrBC,MAAM,EAAE;IACNC,gBAAgB,EAAE,KAAK;IACvBC,MAAM,EAAEC,eAAO,CAACC;EAClB;AACF,CAAC,CAAC;;AAEF;AACA,eAAeT,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AAI,CAAC,CAAC;IACrE;EACF;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;EAEE,eAAe4B,kBAAkB,CAAC1B,YAAY,EAAEL,QAAQ,EAAE;IAC1D;IACEhB,KAAK,CAAE,0CAAyC,CAAC;IACjD,MAAM;MAACkB,aAAa;MAAEC;IAAI,CAAC,GAAGH,QAAQ;IACtC,MAAMwC,OAAO,GAAG;MAACtC;IAAa,CAAC;IAC/B,MAAMD,KAAK,GAAGyC,SAAS;IAEvB,IAAA3B,YAAM,EAAC,MAAMV,YAAY,CAACoC,WAAW,CAAC;MAACxC,KAAK;MAAEC,aAAa;MAAEsC,OAAO;MAAErC;IAAI,CAAC,CAAC,CAAC,CAACa,EAAE,CAAC2B,KAAK,EAAE;EAC1F;;EAGA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAeA"}
package/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "url": "git@github.com:natlibfi/melinda-rest-api-commons.git"
15
15
  },
16
16
  "license": "AGPL-3.0+",
17
- "version": "2.3.2-alpha.7",
17
+ "version": "2.3.2-alpha.8",
18
18
  "main": "./dist/index.js",
19
19
  "engines": {
20
20
  "node": ">=14"
@@ -28,7 +28,8 @@
28
28
  "lint:dev": "eslint ./src --fix",
29
29
  "test": "npm run lint && npm run test:base -- src/**/*.spec.js",
30
30
  "test:dev": "npm run lint:dev && npm run test:base -- src/**/*.spec.js",
31
- "test:base": "cross-env NODE_ENV=test nyc mocha --require @babel/register",
31
+ "test:base": "cross-env NODE_ENV=test nyc mocha --require @babel/register --exclude src/amqp.spec.js",
32
+ "test:local": "cross-env NODE_ENV=test nyc mocha --require @babel/register -- src/amqp.spec.js",
32
33
  "dev": "NODE_ENV=development cross-env DEBUG=1 nodemon",
33
34
  "build": "babel src --source-maps --copy-files --delete-dir-on-start --out-dir=dist"
34
35
  },