Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/orch_zmq_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ std::shared_ptr<swss::ZmqServer> swss::create_zmq_server(std::string zmq_address
}

SWSS_LOG_NOTICE("Create ZMQ server with address: %s, vrf: %s", zmq_address.c_str(), vrf.c_str());
return std::make_shared<ZmqServer>(zmq_address, vrf);

// To prevent message loss between ZmqServer's bind operation and the creation of ZmqProducerStateTable,
// use lazy binding and call bind() only after the handler has been registered.
return std::make_shared<ZmqServer>(zmq_address, vrf, true);
}

bool swss::get_feature_status(std::string feature, bool default_value)
Expand Down
8 changes: 8 additions & 0 deletions orchagent/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,14 @@ int main(int argc, char **argv)
syncd_apply_view();
}

if (zmq_server)
{
// To prevent message loss between ZmqServer's bind operation and the creation of ZmqProducerStateTable,
// use lazy binding and call bind() only after the handler has been registered.
zmq_server->bind();
SWSS_LOG_NOTICE("ZMQ channel on the northbound side of Orchagent successfully bound: %s, %s", zmq_server_address.c_str(), vrf.c_str());
}

orchDaemon->start(heartBeatInterval);

return 0;
Expand Down
3 changes: 2 additions & 1 deletion tests/mock_tests/zmq_orch_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ TEST(ZmqOrchTest, CreateZmqClient)
auto zmq_client = swss::create_zmq_client(zmq_server_address);

zmq_server->registerMessageHandler("test_db", "test_table", &zmq_handler);
zmq_server->bind();

std::vector<KeyOpFieldsValuesTuple> value;
zmq_client->sendMsg("test_db", "test_table", value);
Expand Down Expand Up @@ -127,4 +128,4 @@ TEST(ZmqOrchTest, GetFeatureStatusException)
config_db.hset("DEVICE_METADATA|localhost", HGET_THROW_EXCEPTION_FIELD_NAME, "true");
enabled = swss::get_feature_status(HGET_THROW_EXCEPTION_FIELD_NAME, false);
EXPECT_FALSE(enabled);
}
}
Loading