ZeroMQ Services

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 (asynchronous) queue-based messaging
  • Non-blocking  (asynchronous) queue-based messaging with callbacks
  • Request-reply messaging

It is generally recommended to use non-blocking message patterns for better performance.

Configuring a Service and Reference Binding

Wiring a reference to a service using the ZeroMQ is done as follows in Java (note the ZeroMQ annotation is in the org.fabric3:fabrice3-binding-zeromq-api module):

public class Client ...{
 
	@ZeroMQ(target="ZMQService")
	protected Service service;
 
	public void invoke(){
		service.invoke("message");
	}
}

@ZeroMQ(service="ZMQService")
public class ServiceImpl implements Service {

	public void invoke(String message){
		//....
	}
}

Or in XML as follows:

<component name="Client">
   <implementation.java class="org.fabric3.binding.zeromq.client.Client"/>
   <reference name="service">
       <f3:binding.zeromq target="ZMQService"/>
   </reference>
</component>

 
<component name="ZMQService">
   <implementation.java class="org.fabric3.binding.zeromq.service.ServiceImpl"/>
   <service name="ZMQService">
      <f3:binding.zeromq/>
   </service>
</component>

In the above example, if Service uses non-blocking operations (i.e. uses operations annotated with @OneWay), a ZeroMQ PUSH/PULL socket will be established between the reference and service. If the operations are blocking, XREQ/XREP will be used instead.

Cluster Operation

Note that the binding configuration in the previous figure did not specify an IP address and port combination to connect/bind to. If one is not specified, Fabric3 will allocate a port from the block reserved for each runtime. Addressing information will then be propagated by Fabric3 to required runtimes in the domain. For example, if Client is hosted on a different machine than Service, Fabric3 will transparently propagate the latter's address so that Client can connect to the service.


Further, if TestService is deployed to a clustered zone, all endpoint addresses will be propagated to Client, which in turn will round-robin requests to cluster instances.

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.

    Â