Skip to content

Commit

Permalink
Remove hooks from configuration object.
Browse files Browse the repository at this point in the history
Since the configuration object changes every time the connection is constructed, it doesn't make sense to have the hooks there.
  • Loading branch information
ramhr committed Feb 8, 2024
1 parent 27ceab5 commit 494965e
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 56 deletions.
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,6 @@ const arnavmq = require('arnavmq')({
* * params - An optional object containing extra parameters that can provide extra context for the event.
*/
logger: utils.emptyLogger,

/**
* Configure hooks to register on the connection, consumer and producer.
*/
hooks: undefined,
});
```

Expand Down
2 changes: 1 addition & 1 deletion src/modules/consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Consumer {
constructor(connection) {
this._connection = connection;
this._configuration = this._connection.config;
this.hooks = new ConsumerHooks(this._configuration.hooks && this._configuration.hooks.consumer);
this.hooks = new ConsumerHooks();
}

set connection(value) {
Expand Down
14 changes: 0 additions & 14 deletions src/modules/hooks/connection_hooks.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
const BaseHooks = require('./base_hooks');

class ConnectionHooks extends BaseHooks {
constructor(hooks) {
super();

if (!hooks) {
return;
}
if (hooks.afterConnect) {
this.afterConnect(hooks.afterConnect);
}
if (hooks.beforeConnect) {
this.beforeConnect(hooks.beforeConnect);
}
}

/**
* Registers callback/callbacks to be invoked before creating a connection to rabbitmq.
* The callback is invoked with 'this' set to the connection wrapper instance creating the connection, and a single "payload" argument of the following shape:
Expand Down
20 changes: 0 additions & 20 deletions src/modules/hooks/consumer_hooks.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,6 @@
const BaseHooks = require('./base_hooks');

class ConsumerHooks extends BaseHooks {
constructor(hooks) {
super();

if (!hooks) {
return;
}
if (hooks.beforeProcessMessage) {
this.beforeProcessMessage(hooks.beforeProcessMessage);
}
if (hooks.afterProcessMessage) {
this.afterProcessMessage(hooks.afterProcessMessage);
}
if (hooks.beforeRpcReply) {
this.beforeRpcReply(hooks.beforeRpcReply);
}
if (hooks.afterRpcReply) {
this.afterRpcReply(hooks.afterRpcReply);
}
}

/**
* Registers callback/callbacks to be invoked before consumer starts processing a received message.
* The callback is invoked with 'this' set to the consumer instance, and a single "payload" argument of the following shape:
Expand Down
14 changes: 0 additions & 14 deletions src/modules/hooks/producer_hooks.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
const BaseHooks = require('./base_hooks');

class ProducerHooks extends BaseHooks {
constructor(hooks) {
super();

if (!hooks) {
return;
}
if (hooks.beforePublish) {
this.beforePublish(hooks.beforePublish);
}
if (hooks.afterPublish) {
this.afterPublish(hooks.afterPublish);
}
}

/**
* Registers callback/callbacks to be invoked before producer publishes a message.
* The callback is invoked with 'this' set to the producer instance, and a single "payload" argument of the following shape:
Expand Down
3 changes: 1 addition & 2 deletions src/modules/producer.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ class ProducerError extends Error {
class Producer {
constructor(connection) {
this._connection = connection;
const { hooks } = this._connection.config;
this.hooks = new ProducerHooks(hooks && hooks.producer);
this.hooks = new ProducerHooks();

/**
* Map of rpc queues
Expand Down

0 comments on commit 494965e

Please sign in to comment.