Announcements
This site is in read only until July 22 as we migrate to a new platform; refer to this community post for more details.
Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Microgateway loading plugin multiple times

Not applicable

My Micro Gateway seems to be calling my plugin multiple times on startup and when requests come through. I added a console.log to the beginning of one of the sample plugins in the Apigee tutorials and its printing 8 times:

'use strict';

var debug = require('debug')('plugin:response-override');

console.log("Before");

module.exports.init = function(config, logger, stats) {

console.log("after");

return {

ondata_response: function(req, res, data, next) {

debug('***** plugin ondata_response');

next(null, null);

},

onend_response: function(req, res, data, next) {

debug('***** plugin onend_response');

next(null, "#Overwriting Response\n\n");

}

};

}

This is what it prints when the gateway starts

Before

after

Before

after

Before

after

Before

after

Before

after

Before

after

Before

after

Before

after

Solved Solved
0 3 143
1 ACCEPTED SOLUTION

Former Community Member
Not applicable

Microgateway runs is a cluster mode. By default there is a worker process for each CPU. Each worker process loads/instantiates the plugins. So yes plugins are loaded multiple times.

View solution in original post

3 REPLIES 3

Former Community Member
Not applicable

Microgateway runs is a cluster mode. By default there is a worker process for each CPU. Each worker process loads/instantiates the plugins. So yes plugins are loaded multiple times.

Is there a way to have a leader worker node so parts of a plugin wouldn't be run by each worker? My plugin is querying a service discovery app and loading a variable to be used by requests, but when the code runs its running on all workers, and i end up with the same query results 8 times in my variable. Ideally this query would only be run by 1 node, but requests could hit any.

Actually i think my question above is invalid. The way i was logging things it looked like my variable had 8 copies of the data, but i think it was each worker logging its single copy of the data sequentially.

Thank you for clarifying!