@@ -35,7 +35,9 @@ Producer::Producer(Conf* gconfig, Conf* tconfig):
3535 m_partitioner_cb () {
3636 std::string errstr;
3737
38- m_gconfig->set (" default_topic_conf" , m_tconfig, errstr);
38+ if (m_tconfig)
39+ m_gconfig->set (" default_topic_conf" , m_tconfig, errstr);
40+
3941 m_gconfig->set (" dr_cb" , &m_dr_cb, errstr);
4042 }
4143
@@ -110,10 +112,6 @@ void Producer::New(const Nan::FunctionCallbackInfo<v8::Value>& info) {
110112 return Nan::ThrowError (" Global configuration data must be specified" );
111113 }
112114
113- if (!info[1 ]->IsObject ()) {
114- return Nan::ThrowError (" Topic configuration must be specified" );
115- }
116-
117115 std::string errstr;
118116
119117 Conf* gconfig =
@@ -124,14 +122,17 @@ void Producer::New(const Nan::FunctionCallbackInfo<v8::Value>& info) {
124122 return Nan::ThrowError (errstr.c_str ());
125123 }
126124
127- Conf* tconfig =
128- Conf::create (RdKafka::Conf::CONF_TOPIC,
129- (info[1 ]->ToObject (Nan::GetCurrentContext ())).ToLocalChecked (), errstr);
125+ // If tconfig isn't set, then just let us pick properties from gconf.
126+ Conf* tconfig = nullptr ;
127+ if (info[1 ]->IsObject ()) {
128+ tconfig = Conf::create (RdKafka::Conf::CONF_TOPIC,
129+ (info[1 ]->ToObject (Nan::GetCurrentContext ())).ToLocalChecked (), errstr);
130130
131- if (!tconfig) {
132- // No longer need this since we aren't instantiating anything
133- delete gconfig;
134- return Nan::ThrowError (errstr.c_str ());
131+ if (!tconfig) {
132+ // No longer need this since we aren't instantiating anything
133+ delete gconfig;
134+ return Nan::ThrowError (errstr.c_str ());
135+ }
135136 }
136137
137138 Producer* producer = new Producer (gconfig, tconfig);
0 commit comments