Commit 457cb0dd authored by Tobinsk's avatar Tobinsk
Browse files

Merge branch 'url-resolver-kafka' into 'master'

Url resolver kafka

See merge request !26
parents cfb07cbd 999ea0f5
Pipeline #4140 passed with stages
in 2 minutes and 5 seconds
......@@ -6,13 +6,13 @@
},
"consumer": {
"config": {
"group.id": "response-geoconcordance-1",
"group.id": "response-geoconcordance-url",
"socket.keepalive.enable": true,
"enable.auto.commit": true,
"queued.max.messages.kbytes": 100
},
"topics": {
"topics": ["response-geoconcordance", "response-geoconcordance-metadata"]
"topics": ["response-geoconcordance-url", "response-geoconcordance-metadata"]
},
"stream": {
"request.required.acks": 1
......
......@@ -30,9 +30,11 @@ const version = 2;
/**
* Init the core
* todo: perhaps into module with exports. Then we could interact more freely with it
* @type {Core}
*/
export const core: InterfaceCore = Core.init('Api', './config.json');
export const core = Core.init('Api', './config.json');
export const logger = core.getLogger();
// Create Express server
const app = express();
......@@ -135,13 +137,16 @@ kafka.init().then(async () => {
* General error handling
* This has to be done in this callback
*/
app.use((err: any, req: Request, res: Response, next: NextFunction) => {
console.error(err.stack);
res.status(500).send('Something broke!') });
app.use((err, req, res, next) => {
if (err.isServer) {
core.getLogger().error(err.output);
}
return res.status(err.output.statusCode).json(err.output.payload);
});
core.getLogger().info("We are ready to interact with kafka")
}).catch((error) => {
core.getLogger().error('error while connecting to kafka');
core.getLogger().error('Problem to connect to kafka');
throw error;
});
......
......@@ -236,6 +236,7 @@ export class ApiController {
// the message needs to be compatible to the schema
const url = req.url || req.originalUrl;
const id = shajs('sha256').update(url).digest('hex');
const language = req.validatedBody.language || 'de';
// get the verb from the params or the options
const verb: string = req.params.verb || options.verb;
......@@ -248,6 +249,7 @@ export class ApiController {
id,
verb,
node,
language,
config: options,
}
}
......
import errorHandler = require('errorhandler');
import app from './app';
import app, {logger} from './app';
/**
* Error Handler. Provides full stack - remove for production
......@@ -11,12 +11,8 @@ app.use(errorHandler());
* Start Express server.
*/
const server = app.listen(app.get('port'), () => {
console.log(
' App is running at http://localhost:%d in %s mode',
app.get('port'),
app.get('env')
);
console.log(' Press CTRL-C to stop\n');
logger.info('App is running at http://localhost:%d in %s mode', app.get('port'), app.get('env'));
logger.info('Press CTRL-C to stop');
});
export default server;
\ No newline at end of file
import {logger} from '../app';
const EventEmitter = require('events');
class KafkaEventEmitter extends EventEmitter {}
// event emitter for kafka events
......@@ -5,8 +6,8 @@ const kafkaEventEmitter = new KafkaEventEmitter();
// allow more than 10 parallel event listeners
kafkaEventEmitter.setMaxListeners(100);
kafkaEventEmitter.on('error', (err) => {
console.error('There was an error in the kafkaEventEmitter');
console.error(err);
logger.error('There was an error in the kafkaEventEmitter');
logger.error(err);
process.exit(1);
});
export default kafkaEventEmitter;
import {logger} from '../app';
/**
* Small class to stop the time and di a reporting
*/
......@@ -16,9 +18,9 @@ class Timer {
report(lab?: string) {
if(typeof this.labs[lab] === 'undefined') return null;
console.log("start :" + this.labs[lab].start);
logger.info("Start timer lab:" + this.labs[lab].start);
for(let steps of this.labs[lab].lab) {
console.log("lab :" + ( steps - this.labs[lab].start) + 'ms');
logger.info("Lab time:" + ( steps - this.labs[lab].start) + 'ms');
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment