Skip to content

Commit 580bca1

Browse files
committed
[DOC] - Enhanced sample usage (#6)
1 parent d553212 commit 580bca1

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

README.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,24 @@ Sample usage
176176
============
177177

178178
```nginx
179+
# initial setup
179180
# ...
180181
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+
181187
ngx.apiGateway = ngx.apiGateway or {}
188+
ngx.apiGateway.zmqLogger = zmqLogger
182189
ngx.apiGateway.validation = require "api-gateway.validation.factory" -- enforce ACTIONs
183190
ngx.apiGateway.tracking = require "api-gateway.tracking.factory" -- track requests
184191
}
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;
185197
# ...
186198
187199
#
@@ -207,7 +219,7 @@ location /t {
207219
```
208220

209221

210-
Expose a simple HTTP Service to register rules:
222+
Expose a simple HTTP Service to register rules and list the active ones:
211223

212224
```nginx
213225
server {
@@ -218,7 +230,24 @@ server {
218230
}
219231
```
220232

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+
```
222251

223252
[Back to TOC](#table-of-contents)
224253

0 commit comments

Comments
 (0)