Brokerless Messaging with NetMQ

Brokerless Messaging with NetMQ

NetMQ removes the broker requirement, not the need to define queues, backpressure, socket ownership, acknowledgement and reconnect semantics.

No broker does not mean no queue.

NetMQ implements ZeroMQ-style messaging in C#. Because there is no separate RabbitMQ or Kafka service, part of the reliability contract moves into the application.

Messaging patterns

NetMQ provides Request/Reply, Publish/Subscribe, Push/Pull and Router/Dealer. These are stateful messaging contracts rather than thin wrappers over TCP.

Request/Reply constrains the sequence of operations; it is not interchangeable with an unrestricted stream of messages. Router/Dealer gives more control but also transfers correlation and protocol-state responsibilities to the application. Message framing and multipart boundaries must be part of the contract between peers.

Why brokerless can be useful

Removing a central broker can reduce deployment complexity and an intermediate network hop. It also means durability, replay and centralized queue management are not automatically provided.

Socket ownership

NetMQ sockets are designed around thread ownership. I prefer a single poller/event loop to own the socket while other threads communicate with that owner through controlled boundaries.

High-water mark is backpressure

Producer and consumer rates eventually diverge. High-water mark limits queue growth; when reached, the application needs an explicit backpressure policy.

The configured limit should be interpreted together with socket pattern, peer queues and send behavior. Reaching a queue limit may block or discard according to the pattern and configuration. It is not a universal promise that every producer will receive the same rejection signal. Observe what the selected API reports and decide how the application reacts.

PUB/SUB accepts loss semantics

A subscriber that is disconnected or not yet connected can miss messages. That can be acceptable for replaceable telemetry and unacceptable for commands. Pattern choice must match business semantics.

TCP ACK is not application acknowledgement

A successful transport send does not prove that the remote application processed a message. Processing confirmation, when needed, belongs to the application protocol.

A useful application acknowledgement identifies the message and the point reached: received, validated, committed or completed. If the sender times out after the receiver commits, retry can duplicate the business operation. A durable deduplication rule, where required, must survive the failures covered by the delivery contract; a process-local set does not provide that property after restart.

Poller and event-loop design

Long CPU or blocking I/O work should not execute inside the socket-owning poller. The event loop itself is a capacity boundary.

Workers can process expensive tasks outside the event loop and return completion notifications through an ownership-safe channel. The handoff queue itself needs a capacity policy. Moving work off the poller without bounding pending tasks merely relocates the backlog.

Failure and reconnect

Reconnect behavior should define queue retention, duplicate handling, message expiry and shutdown ordering. Without idempotency, transport recovery can produce duplicate business effects.

I use brokerless messaging when components need a lightweight transport and the application can explicitly own durability and recovery. When durable replay is the primary requirement, a broker may be the better abstraction.

Test disconnect before send, after receive and after commit but before acknowledgement. Also test expired messages and shutdown while work is pending. The expected outcome for each case should distinguish transport recovery from business recovery. Reconnection alone does not establish durable replay or exactly-once processing.

References

Responsibility Boundary in Brokerless Messaging

Brokerless messaging removes the separate broker service, not the delivery, queueing and failure semantics of the system. More of that contract moves into the application protocol: socket pattern, high-water mark, the fate of queued messages during reconnect, and the point at which processing is genuinely acknowledged all matter.

Lower deployment complexity therefore comes with greater application ownership. If durable replay, centralized consumer tracking or broker-managed persistence is a primary requirement, a brokerless design should not be selected merely because the transport is lighter.

QR code for this page