You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.1 KiB

  1. /*
  2. * node-rdkafka - Node.js wrapper for RdKafka C/C++ library
  3. *
  4. * Copyright (c) 2016 Blizzard Entertainment
  5. *
  6. * This software may be modified and distributed under the terms
  7. * of the MIT license. See the LICENSE.txt file for details.
  8. */
  9. 'use strict';
  10. var net = require('net');
  11. var util = require('util');
  12. var Emitter = require('events');
  13. function KafkaServer(config) {
  14. if (!(this instanceof KafkaServer)) {
  15. return new KafkaServer(config);
  16. }
  17. if (config === undefined) {
  18. config = {};
  19. } else if (typeof config !== 'object') {
  20. throw new TypeError('"config" must be an object');
  21. }
  22. Emitter.call(this);
  23. var self = this;
  24. this.socket = net.createServer(function(socket) {
  25. socket.end();
  26. }); //.unref();
  27. this.socket.on('error', function(err) {
  28. console.error(err);
  29. });
  30. this.socket.listen({
  31. port: 9092,
  32. host: 'localhost'
  33. }, function() {
  34. self.address = self.socket.address();
  35. self.emit('ready');
  36. });
  37. }
  38. util.inherits(KafkaServer, Emitter);
  39. KafkaServer.prototype.close = function(cb) {
  40. this.socket.close(cb);
  41. };
  42. module.exports = KafkaServer;