void zsock_set_unbounded (zsock_t *self) { #if (ZMQ_VERSION_MAJOR == 2) zsock_set_hwm (self, 0); #else zsock_set_sndhwm (self, 0); zsock_set_rcvhwm (self, 0); #endif }
static zsock_t* subscriber_sub_socket_new(subscriber_state_t *state) { zsock_t *socket = zsock_new(ZMQ_SUB); assert(socket); zsock_set_rcvhwm(socket, state->rcv_hwm); // set subscription if (!state->subscriptions || zlist_size(state->subscriptions) == 0) { if (!state->subscriptions) state->subscriptions = zlist_new(); zlist_append(state->subscriptions, zconfig_resolve(state->config, "/logjam/subscription", "")); } char *subscription = zlist_first(state->subscriptions); bool subscribed_to_all = false; while (subscription) { printf("[I] subscriber: subscribing to '%s'\n", subscription); if (streq(subscription, "")) subscribed_to_all = true; zsock_set_subscribe(socket, subscription); subscription = zlist_next(state->subscriptions); } if (!subscribed_to_all) zsock_set_subscribe(socket, "heartbeat"); if (!state->devices || zlist_size(state->devices) == 0) { // convert config file to list of devices if (!state->devices) state->devices = zlist_new(); zconfig_t *endpoints = zconfig_locate(state->config, "/logjam/endpoints"); if (!endpoints) { zlist_append(state->devices, "tcp://localhost:9606"); } else { zconfig_t *endpoint = zconfig_child(endpoints); while (endpoint) { char *spec = zconfig_value(endpoint); char *new_spec = augment_zmq_connection_spec(spec, 9606); zlist_append(state->devices, new_spec); endpoint = zconfig_next(endpoint); } } } char* device = zlist_first(state->devices); while (device) { printf("[I] subscriber: connecting SUB socket to logjam-device via %s\n", device); int rc = zsock_connect(socket, "%s", device); log_zmq_error(rc, __FILE__, __LINE__); assert(rc == 0); device = zlist_next(state->devices); } return socket; }
int main(int argc, char const * const *argv) { int rc; zsys_set_sndhwm(1); zsys_set_linger(100); void *pusher = zsock_new(ZMQ_PUSH); assert(pusher); zsock_set_sndhwm(pusher, 1000); zsock_set_linger(pusher, 500); rc = zsock_connect(pusher, "tcp://localhost:12345"); assert(rc==0); void *puller = zsock_new(ZMQ_PULL); assert(puller); zsock_set_rcvhwm(puller, 1000); zsock_set_linger(puller, 500); rc = zsock_bind(puller, "tcp://*:12345"); if (rc != 12345){ printf("bind failed: %s\n", zmq_strerror(errno)); } assert(rc == 12345); void *publisher = zsock_new(ZMQ_PUB); assert(publisher); zsock_set_sndhwm(publisher, 1000); zsock_set_linger(publisher, 500); rc = zsock_bind(publisher, "tcp://*:12346"); assert(rc==12346); // set up event loop zloop_t *loop = zloop_new(); assert(loop); zloop_set_verbose(loop, 0); // push data every 10 ms rc = zloop_timer(loop, 1, 0, timer_event, pusher); assert(rc != -1); zmq_pollitem_t item; item.socket = puller; item.events = ZMQ_POLLIN; rc = zloop_poller(loop, &item, forward, publisher); assert(rc == 0); rc = zloop_start(loop); printf("zloop return: %d", rc); zloop_destroy(&loop); assert(loop == NULL); return 0; }
static zsock_t* subscriber_sub_socket_new(zconfig_t* config, zlist_t* devices) { zsock_t *socket = zsock_new(ZMQ_SUB); assert(socket); zsock_set_rcvhwm(socket, rcv_hwm); zsock_set_linger(socket, 0); zsock_set_reconnect_ivl(socket, 100); // 100 ms zsock_set_reconnect_ivl_max(socket, 10 * 1000); // 10 s // connect socket to endpoints char* spec = zlist_first(devices); while (spec) { if (!quiet) printf("[I] subscriber: connecting SUB socket to: %s\n", spec); int rc = zsock_connect(socket, "%s", spec); log_zmq_error(rc, __FILE__, __LINE__); assert(rc == 0); spec = zlist_next(devices); } return socket; }
int main(int argc, char * const *argv) { int rc = 0; process_arguments(argc, argv); setvbuf(stdout, NULL, _IOLBF, 0); setvbuf(stderr, NULL, _IOLBF, 0); if (!quiet) printf("[I] started %s\n" "[I] sub-port: %d\n" "[I] push-port: %d\n" "[I] io-threads: %lu\n" "[I] rcv-hwm: %d\n" "[I] snd-hwm: %d\n" , argv[0], pull_port, pub_port, io_threads, rcv_hwm, snd_hwm); // load config config_file_exists = zsys_file_exists(config_file_name); if (config_file_exists) { config_file_init(); config = zconfig_load((char*)config_file_name); } // set global config zsys_init(); zsys_set_rcvhwm(10000); zsys_set_sndhwm(10000); zsys_set_pipehwm(1000); zsys_set_linger(100); zsys_set_io_threads(io_threads); // create socket to receive messages on zsock_t *receiver = zsock_new(ZMQ_SUB); assert_x(receiver != NULL, "sub socket creation failed", __FILE__, __LINE__); zsock_set_rcvhwm(receiver, rcv_hwm); // bind externally char* host = zlist_first(hosts); while (host) { if (!quiet) printf("[I] connecting to: %s\n", host); rc = zsock_connect(receiver, "%s", host); assert_x(rc == 0, "sub socket connect failed", __FILE__, __LINE__); host = zlist_next(hosts); } tracker = device_tracker_new(hosts, receiver); // create socket for publishing zsock_t *publisher = zsock_new(ZMQ_PUSH); assert_x(publisher != NULL, "pub socket creation failed", __FILE__, __LINE__); zsock_set_sndhwm(publisher, snd_hwm); rc = zsock_bind(publisher, "tcp://%s:%d", "*", pub_port); assert_x(rc == pub_port, "pub socket bind failed", __FILE__, __LINE__); // create compressor sockets zsock_t *compressor_input = zsock_new(ZMQ_PUSH); assert_x(compressor_input != NULL, "compressor input socket creation failed", __FILE__, __LINE__); rc = zsock_bind(compressor_input, "inproc://compressor-input"); assert_x(rc==0, "compressor input socket bind failed", __FILE__, __LINE__); zsock_t *compressor_output = zsock_new(ZMQ_PULL); assert_x(compressor_output != NULL, "compressor output socket creation failed", __FILE__, __LINE__); rc = zsock_bind(compressor_output, "inproc://compressor-output"); assert_x(rc==0, "compressor output socket bind failed", __FILE__, __LINE__); // create compressor agents zactor_t *compressors[MAX_COMPRESSORS]; for (size_t i = 0; i < num_compressors; i++) compressors[i] = message_decompressor_new(i); // set up event loop zloop_t *loop = zloop_new(); assert(loop); zloop_set_verbose(loop, 0); // calculate statistics every 1000 ms int timer_id = zloop_timer(loop, 1000, 0, timer_event, NULL); assert(timer_id != -1); // setup handler for the receiver socket publisher_state_t publisher_state = { .receiver = zsock_resolve(receiver), .publisher = zsock_resolve(publisher), .compressor_input = zsock_resolve(compressor_input), .compressor_output = zsock_resolve(compressor_output), }; // setup handler for compression results rc = zloop_reader(loop, compressor_output, read_zmq_message_and_forward, &publisher_state); assert(rc == 0); zloop_reader_set_tolerant(loop, compressor_output); // setup handdler for messages incoming from the outside or rabbit_listener rc = zloop_reader(loop, receiver, read_zmq_message_and_forward, &publisher_state); assert(rc == 0); zloop_reader_set_tolerant(loop, receiver); // initialize clock global_time = zclock_time(); // setup subscriptions if (subscriptions == NULL || zlist_size(subscriptions) == 0) { if (!quiet) printf("[I] subscribing to all log messages\n"); zsock_set_subscribe(receiver, ""); } else { char *subscription = zlist_first(subscriptions); while (subscription) { if (!quiet) printf("[I] subscribing to %s\n", subscription); zsock_set_subscribe(receiver, subscription); subscription = zlist_next(subscriptions); } zsock_set_subscribe(receiver, "heartbeat"); } // run the loop if (!zsys_interrupted) { if (verbose) printf("[I] starting main event loop\n"); bool should_continue_to_run = getenv("CPUPROFILE") != NULL; do { rc = zloop_start(loop); should_continue_to_run &= errno == EINTR && !zsys_interrupted; log_zmq_error(rc, __FILE__, __LINE__); } while (should_continue_to_run); if (verbose) printf("[I] main event zloop terminated with return code %d\n", rc); } zloop_destroy(&loop); assert(loop == NULL); if (!quiet) { printf("[I] received %zu messages\n", received_messages_count); printf("[I] shutting down\n"); } zlist_destroy(&hosts); zlist_destroy(&subscriptions); zsock_destroy(&receiver); zsock_destroy(&publisher); zsock_destroy(&compressor_input); zsock_destroy(&compressor_output); device_tracker_destroy(&tracker); for (size_t i = 0; i < num_compressors; i++) zactor_destroy(&compressors[i]); zsys_shutdown(); if (!quiet) printf("[I] terminated\n"); return rc; }
/// // Set socket option `rcvhwm`. void QZsock::setRcvhwm (int rcvhwm) { zsock_set_rcvhwm (self, rcvhwm); }
JNIEXPORT void JNICALL Java_org_zeromq_czmq_Zsock__1_1setRcvhwm (JNIEnv *env, jclass c, jlong self, jint rcvhwm) { zsock_set_rcvhwm ((zsock_t *) (intptr_t) self, (int) rcvhwm); }