When messages are sent from source node to destination node very rapidly, the source node could run out of memory. There are quite a few solutions to this, such as flow management. However, it may not be feasible in some situations.
ZeroMQ uses a high watermark to set the capacity of pipes. In ZeroMQ v2.x, the default value is infinite whereas in ZeroMQ v3.x the default value is 1,000.
When a socket reaches a high watermark, it either drops the message or blocks it. The REQ-REP socket will block the message whereas PUB will drop it.
The following is an example:
/*
HWM example.
*/
#include "czmq.h"
int main (int argc, char const *argv[]) {
zctx_t* context = zctx_new();
void* pub = zsocket_new(context, ZMQ_PUB);
zsocket_bind(pub, "tcp://*:4040");
zsocket_set_hwm(pub, 10);
for(;;) {
zstr_sendm(pub, "Company1");
zstr_send(pub, "Message to be ignored.");
zstr_sendm(pub, "Company10");
zstr_send(pub, "Message to receive.");
zclock_sleep(10);
...