Filtering Events for Multi-Site (WAN) Distribution
You can optionally create gateway sender and/or gateway receiver filters to control which events are queued and distributed to a remote site, or to modify the data stream that is transmitted between GemFire sites.
You can implement and deploy two different types of filter for multi-site events:
GatewayEventFilterimplementation determines whether a region event is placed in a gateway sender queue and/or whether an event in a gateway queue is distributed to a remote site. You can optionally add one or more
GatewayEventFilterimplementations to a gateway sender, etiher in the
cache.xmlconfiguration file or using the Java API.
GemFire makes a synchronous call to the filter’s
beforeEnqueuemethod before it places a region event in the gateway sender queue. The filter returns a boolean value that specifies whether the event should be added to the queue.
GemFire asynchronously calls the filter’s
beforeTransmitmethod to determine whether the gateway sender dispatcher thread should distribute the event to a remote gateway receiver.
For events that are distributed to another site, GemFire calls the listener’s
afterAcknowledgementmethod to indicate that is has received an ack from the remote site after the event was received.
GatewayTransportFilter. Use a
GatewayTransportFilterimplementation to process the TCP stream that sends a batch of events that is distributed from one GemFire cluster to another over a WAN. A
GatewayTransportFilteris typically used to perform encryption or compression on the data that distributed. You install the same
GatewayTransportFilterimplementation on both a gateway sender and gateway receiver.
When a gateway sender processes a batch of events for distribution, GemFire delivers the stream to the
getInputStreammethod of a configured
GatewayTransportFilterimplementation. The filter processes and returns the stream, which is then transmitted to the gateway receiver. When the gateway receiver receives the batch, GemFire calls the
getOutputStreammethod of a configured filter, which again processes and returns the stream so that the events can be applied in the local cluster.
You install a
GatewayEventFilter implementation to a configured gateway sender in order to decide which events are queued and distributed. You install a
GatewayTransportFilter implementation to both a gateway sender and a gateway receiver to process the stream of batched events that are distributed between two sites:
<cache> <gateway-sender id="remoteA" parallel="true" remote-distributed-system-id="1"> <gateway-event-filter> <class-name>org.apache.geode.util.SampleEventFilter</class-name> <parameter name="param1"> <string>"value1"</string> </parameter> </gateway-event-filter> <gateway-transport-filter> <class-name>org.apache.geode.util.SampleTransportFilter</class-name> <parameter name="param1"> <string>"value1"</string> </parameter> </gateway-transport-filter> </gateway-sender> </cache>
<cache> ... <gateway-receiver start-port="1530" end-port="1551"> <gateway-transport-filter> <class-name>org.apache.geode.util.SampleTransportFilter</class-name> <parameter name="param1"> <string>"value1"</string> </parameter> </gateway-transport-filter> </gateway-receiver> </cache>
gfsh>create gateway-sender --id=remoteA --parallel=true --remote-distributed-id="1" --gateway-event-filter=org.apache.geode.util.SampleEventFilter --gateway-transport-filter=org.apache.geode.util.SampleTransportFilter
gfsh>create gateway-receiver --start-port=1530 --end-port=1551 \ --gateway-transport-filter=org.apache.geode.util.SampleTransportFilter
Note: You cannot specify parameters and values for the Java class you specify with the
Cache cache = new CacheFactory().create(); GatewayEventFilter efilter = new SampleEventFilter(); GatewayTransportFilter tfilter = new SampleTransportFilter(); GatewaySenderFactory gateway = cache.createGatewaySenderFactory(); gateway.setParallel(true); gateway.addGatewayEventFilter(efilter); gateway.addTransportFilter(tfilter); GatewaySender sender = gateway.create("remoteA", "1"); sender.start();
Cache cache = new CacheFactory().create(); GatewayTransportFilter tfilter = new SampleTransportFilter(); GatewayReceiverFactory gateway = cache.createGatewayReceiverFactory(); gateway.setStartPort(1530); gateway.setEndPort(1551); gateway.addTransportFilter(tfilter); GatewayReceiver receiver = gateway.create(); receiver.start();