Fabric3 supports low-latency, high performance communications between clients and services and producers and consumers (Pub/Sub) via a binding built on the ZeroMQ Library. The following messaging patterns are supported:
- Non-blocking queue-based messaging
- Non-blocking pub/sub messaging
- Request-reply messaging
- Callbacks
It is recommended for performance reasons that services uses non-blocking (asynchronous) ZeroMQ messaging, that is, either one-way service invocations or channels. If a service needs to return a response to a client, callbacks will generally scale better than blocking-request-response messaging.
Channel (Pub/Sub) Communications
ZeroMQ can be used to bind a channel so that producers and consumers can connect to it remotely. In the following example, ProducerComposite
and ConsumerComposite
are deployed to different zones (they could also be deployed to the same zone). Fabric3 will transparently setup ZeroMQ pub/sub sockets and propagate the socket addresses so that the publisher and consumer can connect remotely:
The following excerpt shows how this channel binding is configured:
<composite name="ProducerComposite" ...> <component name="TestProducer"> <implementation.java class="..."/> <producer name="channel" target="TestChannel"/> </component> </composite> <composite name="ChannelComposite"...> <channel name="TestChannel"> <f3:binding.zeromq/> </channel> </composite> <composite name="ConsumerComposite" ...> <component name="TestConsumer"> <implementation.java class="..."/> <consumer name="channel" source="TestChannel"/> </component> </composite>
Using ZeroMQ as the SCA Binding
Typically, ZeroMQ is used as the default remote transport when no binding is configured (the "default" binding is called the SCA binding, or "binding.sca"). When used in this fashion, Fabric3 will automatically provision ZeroMQ sockets as well as propagate socket address information across clusters so that remote clients can connect. In addition, if socket address information changes (e.g. a runtime joins a cluster or drops out), this information will be automatically propagated and updates applied across clusters.
Assuming the ZeroMQ profile is installed in a runtime, the following example demonstrates how ZeroMQ can be used as the SCA binding:
<composite name="ClientComposite" ...> <component name="TestProducer"> <implementation.java class="..."/> <reference name="service" target="TestService"/> </component> </composite> <composite name="ServiceComposite" ...> <component name="TestService"> <implementation.java class="..."/> </component> </composite>
Notice there is no binding configuration. If the ClientComposite and ServiceComposite are deployed to different zones, Fabric3 will create the appropriate ZeroMQ socket type to wire the components. The socket type chose will depend on the service contract. For example, a service contract with @OneWay
operations will create a ZeroMQ non-blocking socket (ZMQ.PUSH). However, if the service contract has request-reply operations, a ZeroMQ request-response (ZMQ.XREQ) socket is created. Similarly, if the service interface requires a callback, Fabric3 will create a callback socket for replies.
Configuration
The following ZeroMQ values may be configured as attributes on the <f3:zeromq.binding>
element contained in the controller and single-VM configurations (systemConfig.xml):
- high.water
- multicastRate
- multicastRecovery
- sendBuffer
- receiveBuffer
The following ZeroMQ values may be configured as attributes on the <f3:zeromq.binding>
element contained in the participant and single-VM configurations:
- pollTimeout
Port Allocation
The ZeroMQ binding attempts to acquire ports for sockets from the block configured for a particular runtime or zone. For information on how to configure a port block, see Port Allocation.
Multi-Homed Configuration
To force ZeroMQ to bind sockets to a particular address on a multi-homed machine, use the host.address attribute on the <f3:runtime>
element in the participant or single-VM systemConfig. For details, see Multi-Homed Configuration.
Add Comment