Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

ZeroMQ transport for nginx

branch: master

Enable ZMQ_PULL socket, now that all the pieces are in place.

Change-Id: I3841594d1a5ef01dd45595734150bd17e8fd6bac
Signed-off-by: Piotr Sikora <piotr.sikora@frickle.com>
latest commit 0c5cc008dd
Piotr Sikora PiotrSikora authored January 23, 2012
Octocat-spinner-32 src Enable ZMQ_PULL socket, now that all the pieces are in place. January 23, 2012
Octocat-spinner-32 LICENSE Proof-of-concept. January 05, 2012
Octocat-spinner-32 README.md Enforce use of random port numbers for local endpoints. January 13, 2012
Octocat-spinner-32 config Proof-of-concept. January 05, 2012
README.md

About

ngx_zeromq is a transport module which allows nginx to use ZeroMQ message-oriented transport layer when communicating with upstream servers.

It's level 7 protocol agnostic, which means that it can be used with any well-behaving upstream modules (proxy, fastcgi, uwsgi, scgi, etc.).

Status

This is experimental module and it's compatible with following nginx releases:

  • 1.0.x (tested with 1.0.0 to 1.0.11),
  • 1.1.x (tested with 1.1.0 to 1.1.12).

Caveats

At this time, ngx_zeromq support only REQ/REP ZeroMQ sockets, which means that upstream response must be delivered in a single ZeroMQ message (although it can be multipart message).

Each message part must fit into upstream buffer (as defined by proxy_buffer_size, proxy_buffers and other directives).

ZeroMQ is hungry for file descriptors, it will crash and bring worker process down with it once it runs out of them. In order to guarantee that it doesn't happen, worker connections limit (see: worker_connections) should be set few times lower than the file descriptors limit (see: worker_rlimit_nofile).

SSL is another transport module, which means that it cannot be combined with ngx_zeromq on the same connection (but this matters only for communication with upstream servers, clients can still use SSL when connecting to nginx).

Configuration directives

zeromq_threads

  • syntax: zeromq_threads <number>
  • default: 1
  • context: main

Configure number of ZeroMQ I/O threads to be used by each worker process.

zeromq_local

  • syntax: zeromq_local <socket_type> <local_endpoint>
  • default: none
  • context: upstream

Configure local ZeroMQ endpoint (must use random port numbers).

zeromq_remote

  • syntax: zeromq_remote <socket_type> <remote_endpoint>
  • default: none
  • context: upstream

Configure remote ZeroMQ endpoint (cannot use random port numbers).

zeromq_single

  • syntax: zeromq_single on|off
  • default: off
  • context: upstream

Enable single mode which allows use of predefined port numbers for local endpoints. It comes at a price (only one worker can bind to such endpoint and it will stop working after nginx reload) and it's supposed to be used only during testing and development. Do not use this mode in production.

Sample configuration

Use HTTP over ZeroMQ (using standard proxy module).

http {
    upstream blackhole {
        zeromq_remote   REQ tcp://127.0.0.1:5555;
    }

    server {
        location / {
            proxy_pass  http://blackhole;
        }
    }
}

License

Copyright (c) 2012, FRiCKLE <info@frickle.com>
Copyright (c) 2012, Piotr Sikora <piotr.sikora@frickle.com>
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in the
   documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Something went wrong with that request. Please try again.