Skip to content

Nanomsg-next-gen

nanomsg-next-generation - light-weight brokerless messaging.

This project is a rewrite of the Scalability Protocols library known as libnanomsg, and adds significant new capabilities, while retaining compatibility with the original.

About

NNG, like its predecessors nanomsg (and to some extent ZeroMQ), is a lightweight, broker-less library, offering a simple API to solve common recurring messaging problems, such as publish/subscribe, RPC-style request/reply, or service discovery. The API frees the programmer from worrying about details like connection management, retries, and other common considerations, so that they can focus on the application instead of the plumbing.

NNG is implemented in C, requiring only C99 and CMake to build. It can be built as a shared or a static library, and is readily embeddable. It is also designed to be easy to port to new platforms if your platform is not already supported.

The communication patterns, also called "scalability protocols", are basic blocks for building distributed systems. By combining them you can create a vast array of distributed applications. The following scalability protocols are currently available:

  • PAIR - simple one-to-one communication
  • BUS - simple many-to-many communication
  • REQREP - allows to build clusters of stateless services to process user requests
  • PUBSUB - distributes messages to large sets of interested subscribers
  • PIPELINE - aggregates messages from multiple sources and load balances them among many destinations
  • SURVEY - allows to query state of multiple applications in a single go

Scalability protocols are layered on top of the transport layer in the network stack. At the moment, the nanomsg library supports the following transports mechanisms:

  • INPROC - transport within a process (between threads, modules etc.)
  • IPC - transport between processes on a single machine
  • TCP - network transport via TCP
  • WS - websockets over TCP

The library exposes a BSD-socket-like C API to the applications.

It is licensed under the MIT/X11 license.

Messaging Patterns

nng is a messaging framework that attempts to help solve common messaging problems with one of a few patterns ('protocols' in nng parlance.)

Pipeline (A One-Way Pipe)

Pipeline This pattern is useful for solving producer/consumer problems, including load-balancing. Messages flow from the push side to the pull side. If multiple peers are connected, the pattern attempts to distribute fairly.

  • 이 패턴은 부하 분산을 포함하여 생산자 / 소비자 문제를 해결하는 데 유용합니다.
  • 메시지는 푸시 쪽에서 풀쪽으로 흐릅니다.
  • 여러 피어가 연결된 경우 패턴은 공정하게 배포하려고합니다.

Request/Reply (I ask, you answer)

Request/Reply Request/Reply is used for synchronous communications where each question is responded with a single answer, for example remote procedure calls (RPCs). Like Pipeline, it also can perform load-balancing. This is the only reliable messaging pattern in the suite, as it automatically will retry if a request is not matched with a response.

  • 요청 / 응답은 원격 프로 시저 호출 (RPC)과 같이 각 질문이 단일 응답으로 응답되는 동기식 통신에 사용됩니다.
  • Pipeline과 마찬가지로로드 밸런싱도 수행 할 수 있습니다.
  • 요청이 응답과 일치하지 않으면 자동으로 재 시도하므로 스위트에서 유일한 신뢰할 수있는 메시징 패턴입니다.

Pair (Two Way Radio)

Pair The pair pattern is used when there a one-to-one peer relationship. Only one peer may be connected to another peer at a time, but both may speak freely.

  • 쌍 패턴은 일대일 피어 관계가있을 때 사용됩니다.
  • 한 번에 한 피어 만 다른 피어와 연결될 수 있지만 둘 다 자유롭게 말할 수 있습니다.

Pub/Sub (Topics & Broadcast)

Pub/Sub This pattern is used to allow a single broadcaster to publish messages to many subscribers, which may choose to limit which messages they receive.

  • 이 패턴은 단일 브로드 캐스터가 여러 구독자에게 메시지를 게시 할 수 있도록하는 데 사용됩니다.
  • 수신되는 메시지를 제한하도록 선택할 수 있습니다.

Survey (Everybody Votes)

Survey The surveyor pattern is used to send a timed survey out, responses are individually returned until the survey has expired. This pattern is useful for service discovery and voting algorithms.

  • 설문 조사 패턴은 시간 제한 설문 조사를 보내는 데 사용되며 설문 조사가 만료 될 때까지 응답이 개별적으로 반환됩니다.
  • 이 패턴은 서비스 검색 및 투표 알고리즘에 유용합니다.

Bus (Routing)

Bus The bus protocol is useful for routing applications, or for building fully interconnected mesh networks. In this pattern, messages are sent to every directly connected peer.

  • 버스 프로토콜은 라우팅 애플리케이션이나 완전히 상호 연결된 메시 네트워크를 구축하는 데 유용합니다.
  • 이 패턴에서 메시지는 직접 연결된 모든 피어로 전송됩니다.

TCP implementation

src/platform/posix/posix_tcpconn.c 파일에 tcp_conn_dowrite()함수와 tcp_conn_doread()함수를 확인하면 된다. 사용하는 API는 sendmsg와 readv를 사용한다.

Troubleshooting

TCP 프로토콜 사용시 localhost 접속 문제

TCP 프로토콜에 접속하려고 보면 정상적으로 접속되지 않을 수 있다.

참고로 localhost/etc/hosts파일을 확인해 보면 된다.

127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost

IPv4 또는 IPv6 연결 문제일 가능성이 있다.

바인딩시 tcp://0.0.0.0:20002을 사용하면 다음과 같이 연결된다. (isof를 사용해 확인할 수 있다)

c2node     9683 yourname   16u  IPv4 0x9ffbc70c9776a8f5      0t0  TCP *:20002 (LISTEN)

tcp://*:20002을 사용하면 다음과 같이 연결된다.

c2node     9683 yourname   16u  IPv6 0x9ffbc70c9776a8f5      0t0  TCP *:20002 (LISTEN)

따라서 클라이언트 접속시 IP 버전을 확인하는 것이 좋다.

See also

Favorite site

References


  1. Dissecting_Message_Queues_–_Brave_New_Geek.pdf 

  2. Priotitised_Load_Balancing_with_nanomsg_-_250bpm.pdf