mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
add kafka producer
This commit is contained in:
parent
b5ccc35340
commit
abb5c5ad31
12 changed files with 185 additions and 2 deletions
|
@ -62,7 +62,7 @@ public:
|
|||
};
|
||||
|
||||
/**
|
||||
* the async callback for dvr.
|
||||
* the async callback for dvr, callback and other async worker.
|
||||
* when worker call with the task, the worker will do it in isolate thread.
|
||||
* that is, the task is execute/call in async mode.
|
||||
*/
|
||||
|
|
|
@ -1539,6 +1539,7 @@ int SrsConfig::reload_conf(SrsConfig* conf)
|
|||
}
|
||||
|
||||
// TODO: FIXME: support reload stream_caster.
|
||||
// TODO: FIXME: support reload kafka.
|
||||
|
||||
// merge config: vhost
|
||||
if ((ret = reload_vhost(old_root)) != ERROR_SUCCESS) {
|
||||
|
|
68
trunk/src/app/srs_app_kafka.cpp
Normal file
68
trunk/src/app/srs_app_kafka.cpp
Normal file
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013-2015 SRS(simple-rtmp-server)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <srs_app_kafka.hpp>
|
||||
|
||||
#include <srs_kernel_error.hpp>
|
||||
#include <srs_kernel_log.hpp>
|
||||
#include <srs_app_config.hpp>
|
||||
#include <srs_app_async_call.hpp>
|
||||
|
||||
SrsKafkaProducer::SrsKafkaProducer()
|
||||
{
|
||||
worker = new SrsAsyncCallWorker();
|
||||
}
|
||||
|
||||
SrsKafkaProducer::~SrsKafkaProducer()
|
||||
{
|
||||
srs_freep(worker);
|
||||
}
|
||||
|
||||
int SrsKafkaProducer::initialize()
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
srs_trace("initialize kafka producer ok.");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SrsKafkaProducer::start()
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
if ((ret = worker->start()) != ERROR_SUCCESS) {
|
||||
srs_error("start kafka failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
srs_trace("start kafka async worker ok.");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void SrsKafkaProducer::stop()
|
||||
{
|
||||
worker->stop();
|
||||
}
|
||||
|
47
trunk/src/app/srs_app_kafka.hpp
Normal file
47
trunk/src/app/srs_app_kafka.hpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013-2015 SRS(simple-rtmp-server)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef SRS_APP_KAFKA_HPP
|
||||
#define SRS_APP_KAFKA_HPP
|
||||
|
||||
/*
|
||||
#include <srs_app_kafka.hpp>
|
||||
*/
|
||||
#include <srs_core.hpp>
|
||||
|
||||
class SrsAsyncCallWorker;
|
||||
|
||||
class SrsKafkaProducer
|
||||
{
|
||||
private:
|
||||
SrsAsyncCallWorker* worker;
|
||||
public:
|
||||
SrsKafkaProducer();
|
||||
virtual ~SrsKafkaProducer();
|
||||
public:
|
||||
virtual int initialize();
|
||||
virtual int start();
|
||||
virtual void stop();
|
||||
};
|
||||
|
||||
#endif
|
|
@ -49,6 +49,7 @@ using namespace std;
|
|||
#include <srs_app_caster_flv.hpp>
|
||||
#include <srs_core_mem_watch.hpp>
|
||||
#include <srs_kernel_consts.hpp>
|
||||
#include <srs_app_kafka.hpp>
|
||||
|
||||
// system interval in ms,
|
||||
// all resolution times should be times togother,
|
||||
|
@ -508,6 +509,7 @@ SrsServer::SrsServer()
|
|||
#ifdef SRS_AUTO_INGEST
|
||||
ingester = NULL;
|
||||
#endif
|
||||
kafka = new SrsKafkaProducer();
|
||||
}
|
||||
|
||||
SrsServer::~SrsServer()
|
||||
|
@ -537,6 +539,8 @@ void SrsServer::destroy()
|
|||
srs_freep(ingester);
|
||||
#endif
|
||||
|
||||
srs_freep(kafka);
|
||||
|
||||
if (pid_fd > 0) {
|
||||
::close(pid_fd);
|
||||
pid_fd = -1;
|
||||
|
@ -561,6 +565,8 @@ void SrsServer::dispose()
|
|||
ingester->dispose();
|
||||
#endif
|
||||
|
||||
kafka->stop();
|
||||
|
||||
SrsSource::dispose_all();
|
||||
|
||||
while (!conns.empty()) {
|
||||
|
@ -864,6 +870,18 @@ int SrsServer::ingest()
|
|||
return ret;
|
||||
}
|
||||
|
||||
int SrsServer::start_kafka()
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
if ((ret = kafka->initialize()) != ERROR_SUCCESS) {
|
||||
srs_error("initialize the kafka producer failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return kafka->start();
|
||||
}
|
||||
|
||||
int SrsServer::cycle()
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
|
|
@ -55,6 +55,7 @@ class SrsTcpListener;
|
|||
#ifdef SRS_AUTO_STREAM_CASTER
|
||||
class SrsAppCasterFlv;
|
||||
#endif
|
||||
class SrsKafkaProducer;
|
||||
|
||||
// listener type for server to identify the connection,
|
||||
// that is, use different type to process the connection.
|
||||
|
@ -247,6 +248,7 @@ private:
|
|||
#ifdef SRS_AUTO_INGEST
|
||||
SrsIngester* ingester;
|
||||
#endif
|
||||
SrsKafkaProducer* kafka;
|
||||
private:
|
||||
/**
|
||||
* the pid file fd, lock the file write when server is running.
|
||||
|
@ -307,6 +309,7 @@ public:
|
|||
virtual int register_signal();
|
||||
virtual int http_handle();
|
||||
virtual int ingest();
|
||||
virtual int start_kafka();
|
||||
virtual int cycle();
|
||||
// IConnectionManager
|
||||
public:
|
||||
|
|
|
@ -382,6 +382,10 @@ int run_master()
|
|||
return ret;
|
||||
}
|
||||
|
||||
if ((ret = _srs_server->start_kafka()) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if ((ret = _srs_server->cycle()) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue