@@ -176,12 +176,24 @@ Sample usage
176
176
============
177
177
178
178
``` nginx
179
+ # initial setup
179
180
# ...
180
181
init_worker_by_lua_block {
182
+ -- initialize a ZMQ Logger
183
+ local ZmqLogger = require "api-gateway.zmq.ZeroMQLogger"
184
+ local zmqLogger = ZmqLogger:new()
185
+ zmqLogger:connect(ZmqLogger.SOCKET_TYPE.ZMQ_PUB, "ipc:///tmp/nginx_queue_listen")
186
+
181
187
ngx.apiGateway = ngx.apiGateway or {}
188
+ ngx.apiGateway.zmqLogger = zmqLogger
182
189
ngx.apiGateway.validation = require "api-gateway.validation.factory" -- enforce ACTIONs
183
190
ngx.apiGateway.tracking = require "api-gateway.tracking.factory" -- track requests
184
191
}
192
+ # dictionaries used for storing the throttling / rate limiting rules
193
+ lua_shared_dict tracking_rules_dict 5m;
194
+ lua_shared_dict blocking_rules_dict 5m;
195
+ lua_shared_dict delaying_rules_dict 5m;
196
+ lua_shared_dict rewriting_rules_dict 5m;
185
197
# ...
186
198
187
199
#
@@ -207,7 +219,7 @@ location /t {
207
219
```
208
220
209
221
210
- Expose a simple HTTP Service to register rules:
222
+ Expose a simple HTTP Service to register rules and list the active ones :
211
223
212
224
``` nginx
213
225
server {
@@ -218,7 +230,24 @@ server {
218
230
}
219
231
```
220
232
221
- See [ tracking_service.conf] ( test/resources/tracking_service.conf ) that details the HTTP endpoints.
233
+ See [ tracking_service.conf] ( test/resources/api-gateway/tracking_service.conf ) that details the HTTP endpoints.
234
+
235
+ The following request adds a new blocking rule (expiring on ` 7/1/2016 ` ):
236
+
237
+ ``` bash
238
+ curl -i -X POST http://< docker_host_ip> :5000/tracking \
239
+ --data ' { "id": 10, "domain" : "1234", "format": "$http_x_api_key", "expire_at_utc": 1467331200000, "action" : "BLOCK"}'
240
+
241
+ {" result" :" success" }
242
+ ```
243
+
244
+ To check which rules are active:
245
+
246
+ ``` bash
247
+ curl http://< docker_host_ip> :5000/tracking/block
248
+
249
+ [{" domain" :" 1234" ," format" :" $http_x_api_key " ," id" :10," action" :" BLOCK" ," expire_at_utc" :1467331200000}]
250
+ ```
222
251
223
252
[ Back to TOC] ( #table-of-contents )
224
253
0 commit comments