1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-15 04:42:04 +00:00

notify kafka when client close

This commit is contained in:
winlin 2015-10-23 14:36:55 +08:00
parent 71451878c9
commit d2ca51ac50
3 changed files with 38 additions and 4 deletions

View file

@ -383,6 +383,13 @@ void SrsKafkaProducer::stop()
int SrsKafkaProducer::on_client(int key, SrsListenerType type, string ip) int SrsKafkaProducer::on_client(int key, SrsListenerType type, string ip)
{ {
int ret = ERROR_SUCCESS;
bool enabled = _srs_config->get_kafka_enabled();
if (!enabled) {
return ret;
}
SrsJsonObject* obj = SrsJsonAny::object(); SrsJsonObject* obj = SrsJsonAny::object();
obj->set("msg", SrsJsonAny::str("accept")); obj->set("msg", SrsJsonAny::str("accept"));
@ -392,6 +399,22 @@ int SrsKafkaProducer::on_client(int key, SrsListenerType type, string ip)
return worker->execute(new SrsKafkaMessage(this, key, obj)); return worker->execute(new SrsKafkaMessage(this, key, obj));
} }
int SrsKafkaProducer::on_close(int key)
{
int ret = ERROR_SUCCESS;
bool enabled = _srs_config->get_kafka_enabled();
if (!enabled) {
return ret;
}
SrsJsonObject* obj = SrsJsonAny::object();
obj->set("msg", SrsJsonAny::str("close"));
return worker->execute(new SrsKafkaMessage(this, key, obj));
}
int SrsKafkaProducer::send(int key, SrsJsonObject* obj) int SrsKafkaProducer::send(int key, SrsJsonObject* obj)
{ {
int ret = ERROR_SUCCESS; int ret = ERROR_SUCCESS;

View file

@ -137,11 +137,16 @@ public:
public: public:
/** /**
* when got any client connect to SRS, notify kafka. * when got any client connect to SRS, notify kafka.
* @param key the partition map key, a id or hash. * @param key the partition map key, the client id or hash(ip).
* @param type the type of client. * @param type the type of client.
* @param ip the peer ip of client. * @param ip the peer ip of client.
*/ */
virtual int on_client(int key, SrsListenerType type, std::string ip) = 0; virtual int on_client(int key, SrsListenerType type, std::string ip) = 0;
/**
* when client close or disconnect for error.
* @param key the partition map key, the client id or hash(ip).
*/
virtual int on_close(int key) = 0;
}; };
/** /**
@ -168,11 +173,10 @@ public:
virtual int initialize(); virtual int initialize();
virtual int start(); virtual int start();
virtual void stop(); virtual void stop();
// interface ISrsKafkaCluster
public: public:
/**
* when got any client connect to SRS, notify kafka.
*/
virtual int on_client(int key, SrsListenerType type, std::string ip); virtual int on_client(int key, SrsListenerType type, std::string ip);
virtual int on_close(int key);
// for worker to call task to send object. // for worker to call task to send object.
public: public:
/** /**

View file

@ -1556,6 +1556,13 @@ int SrsRtmpConn::on_disconnect()
http_hooks_on_close(); http_hooks_on_close();
#ifdef SRS_AUTO_KAFKA
if ((ret = kafka->on_close(srs_id())) != ERROR_SUCCESS) {
srs_error("notify kafka failed. ret=%d", ret);
return ret;
}
#endif
// TODO: implements it. // TODO: implements it.
return ret; return ret;