├── README.md
├── amqp-util.lua
├── amqp.lua
└── nginx.conf
/README.md:
--------------------------------------------------------------------------------
1 | nginx-rabbitmq
2 | ==============
3 | This version would be better:
4 | https://github.com/AlanWangWP/nginx-amqp
5 |
6 |
7 |
8 |
9 |
10 | This module is used to forward data stream in http GET request to RabbitMQ. In this module, nginx will take values of rum and send them to RabbitMQ.
11 | For example, if request is : localhost/test?rum=test&v=0.9, nginx would send "test" to RabbitMQ
12 |
13 | Installation
14 | ============
15 | 1. Download openresty: http://openresty.org/
16 | 2. Unzip source and go to unzipped directory in terminal
17 | 3. Type: ./configure --with-luajit && sudo make && sudo make install
18 | 4. Install RabbitMQ-C library: https://github.com/alanxz/rabbitmq-c
Follow the instructions to install rabbitmq-c
19 | 5. Put amqp.lua and amqp-util.lua to /usr/local/share/luajit-2.1.0-alpha/
You can change this directory if you want. But you also need to change lua_package_path in nginx.conf file
20 | 6. Use above nginx.conf file to override /usr/local/openresty/nginx/conf/nginx.conf
You can change your ip, exchange, queue, user, password variables for RabbitMQ in nginx.conf file
21 | 7. Restart your nginx and open terminal to type: curl -i localhost/test?rum=test&v=0.9
If you get similar reply like this, then your data is successfully sent to RabbitMQ
22 |
23 | HTTP/1.1 200 OK
24 |
25 | Server: openresty/1.7.0.1
26 | Date: Wed, 25 Jun 2014 18:07:11 GMT
27 | Content-Type: application/octet-stream
28 | Transfer-Encoding: chunked
29 | Connection: keep-alive
30 | Content-type: text/plain
31 |
32 | Sent:[test] to RabbitMQ.
33 |
34 |
35 |
36 |
37 | ==============
38 | The lua code is from https://github.com/tcoram/rabbitmq-lua
39 |
--------------------------------------------------------------------------------
/amqp-util.lua:
--------------------------------------------------------------------------------
1 | --
2 | -- AMQP/RabbitMQ utilities and helper functions for LuaJIT
3 | -- Requires at least librrabbitmq.so.1.0
4 | --
5 | -- Copyright (c) 2013, Todd Coram. All rights reserved.
6 | -- See LICENSE for details.
7 | --
8 |
9 | local ffi = require("ffi")
10 |
11 | local A = require "amqp"
12 | local M = { }
13 |
14 | function M.connect_rabbit(opt)
15 | local opt = opt or {}
16 | local host = opt.host or "127.0.0.1"
17 | local port = opt.port or 5672
18 | local vhost = opt.vhost or "/"
19 | local user = opt.user or "guest"
20 | local password = opt.password or "guest"
21 | local channel = opt.channel or 1
22 |
23 | local conn=A.amqp_new_connection()
24 | local sockfd = M.die_on_error(A.amqp_open_socket(host,port),"Can't open socket.")
25 |
26 | A.amqp_set_sockfd(conn,sockfd)
27 |
28 | M.die_on_amqp_error(A.amqp_login(conn, vhost, 0, 131072, 0, 0, user, password),
29 | "Can't login.")
30 |
31 | A.amqp_channel_open(conn,channel)
32 | M.die_on_amqp_error(A.amqp_get_rpc_reply(conn), "Can't open channel.")
33 | return conn
34 | end
35 |
36 | function M.disconnect_rabbit(conn,opt)
37 | local opt = opt or {}
38 | local channel = opt.channel or 1
39 | M.die_on_amqp_error(A.amqp_channel_close(conn,channel,A.AMQP_REPLY_SUCCESS),
40 | "Closing channel.")
41 | M.die_on_amqp_error(A.amqp_connection_close(conn,A.AMQP_REPLY_SUCCESS),
42 | "Closing connection.")
43 | M.die_on_error(A.amqp_destroy_connection(conn),
44 | "Ending Connection.")
45 | end
46 |
47 | function M.declare_exchange(conn,ename,etype,opt)
48 | local opt = opt or {}
49 | local channel = opt.channel or 1
50 | local passive = opt.passive or 0
51 | local durable = opt.durable or 0
52 | A.amqp_exchange_declare(conn, channel,
53 | A.amqp_cstring_bytes(ename),
54 | A.amqp_cstring_bytes(etype),
55 | passive, durable, A.amqp_empty_table)
56 | M.die_on_amqp_error(A.amqp_get_rpc_reply(conn), "Declaring exchange")
57 | end
58 |
59 | function M.declare_queue(conn,name,opt)
60 | local opt = opt or {}
61 | -- Can't handle autonamed queues (yet)
62 | -- local name = opt.name or ""
63 | local channel = opt.channel or 1
64 | local passive = opt.passive or 0
65 | local durable = opt.durable or 0
66 | local exclusive = opt.exclusive or 0
67 | local auto_delete = opt.autodelete or 0
68 | A.amqp_queue_declare(conn, channel,
69 | A.amqp_cstring_bytes(name), passive, durable, exclusive,
70 | auto_delete, A.amqp_empty_table)
71 | M.die_on_amqp_error(A.amqp_get_rpc_reply(conn), "Declaring queue.")
72 | end
73 |
74 | function M.bind_queue(conn,name,exchange,opt)
75 | local opt = opt or {}
76 | local channel = opt.channel or 1
77 | local bindingkey = opt.bindingkey or ""
78 | A.amqp_queue_bind(conn, channel,
79 | A.amqp_cstring_bytes(name),
80 | A.amqp_cstring_bytes(exchange),
81 | A.amqp_cstring_bytes(bindingkey),
82 | A.amqp_empty_table)
83 | M.die_on_amqp_error(A.amqp_get_rpc_reply(conn), "Binding queue.")
84 | end
85 |
86 | function M.create_consumer(conn,queuename,cbfunc,opt)
87 | local opt = opt or {}
88 | local channel = opt.channel or 1
89 | local consumer_tag = opt.consumer_tag or queuename
90 | local no_local = opt.no_local or 0
91 | local no_ack = opt.no_ack or 0
92 | local exclusive = opt.exclusive or 0
93 |
94 | A.amqp_basic_consume(conn,channel,
95 | A.amqp_cstring_bytes(queuename),
96 | A.amqp_cstring_bytes(consumer_tag),
97 | no_local, no_ack, exclusive, A.amqp_empty_table)
98 | M.die_on_amqp_error(A.amqp_get_rpc_reply(conn), "Consuming.")
99 | f = function(delinfo,data)
100 | cbfunc(consumer_tag,data)
101 | if no_ack == 0 then
102 | A.amqp_basic_ack(conn,channel, delinfo.delivery_tag, 0)
103 | end
104 |
105 | end
106 | return f
107 | end
108 |
109 |
110 | function M.wait_for_messages(conn,consumers,count)
111 | local count = count or -1
112 | local result
113 | local frame = ffi.new("amqp_frame_t",{})
114 | local body_target
115 | local body_received
116 | local consumer_tbl = {}
117 |
118 | for q,fo in pairs(consumers) do
119 | f,opts = fo[1],fo[2]
120 | consumer_tbl[q] = M.create_consumer(conn,q,f,opts)
121 | end
122 |
123 | repeat
124 | local databuf = ""
125 | A.amqp_maybe_release_buffers(conn)
126 | result=A.amqp_simple_wait_frame(conn,frame)
127 | if result < 0 then break end
128 | if frame.frame_type == A.AMQP_FRAME_METHOD and
129 | frame.payload.method.id == A.AMQP_BASIC_DELIVER_METHOD then
130 | local delinfo = ffi.cast("amqp_basic_deliver_t *", frame.payload.method.decoded)
131 | result=tonumber(A.amqp_simple_wait_frame(conn,frame))
132 | if result < 0 then break end
133 | if frame.frame_type ~= A.AMQP_FRAME_HEADER then
134 | error("Expected header!")
135 | end
136 | body_target = tonumber(frame.payload.properties.body_size)
137 | body_received = 0
138 | while body_received < body_target do
139 | result=tonumber(A.amqp_simple_wait_frame(conn,frame))
140 | if result < 0 then break end
141 | if frame.frame_type ~= A.AMQP_FRAME_BODY then
142 | error("Expected header!")
143 | end
144 | body_received = body_received + tonumber(frame.payload.body_fragment.len)
145 |
146 | databuf = databuf .. ffi.string(frame.payload.body_fragment.bytes,
147 | tonumber(frame.payload.body_fragment.len))
148 | end
149 | tag=ffi.string(delinfo.consumer_tag.bytes,delinfo.consumer_tag.len)
150 | consumer_tbl[tag](delinfo,databuf)
151 | end
152 | if count > 0 then count = count -1 end
153 | until count == 0
154 | end
155 |
156 | function M.publish(conn,exchange,msg,opt)
157 | local opt = opt or {}
158 | local channel = opt.channel or 1
159 | local mandatory = opt.mandatory or 0
160 | local immediate = opt.immediate or 0
161 | local bindingkey = opt.bindingkey or ""
162 | local routingkey = opt.routingkey or ""
163 | local properties = opt.properties or nil
164 |
165 | buf = A.amqp_bytes_malloc(#msg)
166 | ffi.copy(buf.bytes,msg,#msg)
167 | buf.len = #msg
168 |
169 | A.amqp_basic_publish(conn, channel,
170 | A.amqp_cstring_bytes(exchange),
171 | A.amqp_cstring_bytes(routingkey),
172 | mandatory, immediate, properties,
173 | buf)
174 |
175 | A.amqp_bytes_free(buf)
176 |
177 | M.die_on_amqp_error(A.amqp_get_rpc_reply(conn), "Publish.")
178 | end
179 |
180 |
181 | function M.die_on_error(t,msg)
182 | assert(t,msg)
183 | return t
184 | end
185 |
186 | function M.die_on_amqp_error(v,msg)
187 | rep=tonumber(v.reply_type)
188 | if rep < 2 then
189 | return v
190 | elseif rep == 2 then
191 | error(msg .. ": AMQP_RESPONSE_LIBRARY_EXCEPTION")
192 | elseif rep == 3 then
193 | error(string.format(msg .. ": AMQP_RESPONSE_SERVER_EXCEPTION: %d", v.reply.id))
194 | else
195 | error(msg .. ": UNKNOWN AMQP EXCEPTION")
196 | end
197 | end
198 |
199 |
200 | setmetatable(M, { __index = A })
201 | return M
--------------------------------------------------------------------------------
/amqp.lua:
--------------------------------------------------------------------------------
1 | --
2 | -- AMQP/RabbitMQ Bindings for LuaJIT
3 | -- Requires at least librrabbitmq.so.1.0 (https://github.com/alanxz/rabbitmq-c)
4 | --
5 | -- The contents of this file has been
6 | -- derived (by hand) from rabbitmq-c's amqp.h and amqp-framing.h
7 | --
8 |
9 |
10 | local ffi = require("ffi")
11 |
12 | ffi.cdef[[
13 |
14 | static const int AMQP_PROTOCOL_VERSION_MAJOR = 0;
15 | static const int AMQP_PROTOCOL_VERSION_MINOR = 9;
16 | static const int AMQP_PROTOCOL_VERSION_REVISION = 1;
17 | static const int AMQP_PROTOCOL_PORT = 5672;
18 | static const int AMQP_FRAME_METHOD = 1;
19 | static const int AMQP_FRAME_HEADER = 2;
20 | static const int AMQP_FRAME_BODY = 3;
21 | static const int AMQP_FRAME_HEARTBEAT = 8;
22 | static const int AMQP_FRAME_MIN_SIZE = 4096;
23 | static const int AMQP_FRAME_END = 206;
24 | static const int AMQP_REPLY_SUCCESS = 200;
25 | static const int AMQP_CONTENT_TOO_LARGE = 311;
26 | static const int AMQP_NO_ROUTE = 312;
27 | static const int AMQP_NO_CONSUMERS = 313;
28 | static const int AMQP_ACCESS_REFUSED = 403;
29 | static const int AMQP_NOT_FOUND = 404;
30 | static const int AMQP_RESOURCE_LOCKED = 405;
31 | static const int AMQP_PRECONDITION_FAILED = 406;
32 | static const int AMQP_CONNECTION_FORCED = 320;
33 | static const int AMQP_INVALID_PATH = 402;
34 | static const int AMQP_FRAME_ERROR = 501;
35 | static const int AMQP_SYNTAX_ERROR = 502;
36 | static const int AMQP_COMMAND_INVALID = 503;
37 | static const int AMQP_CHANNEL_ERROR = 504;
38 | static const int AMQP_UNEXPECTED_FRAME = 505;
39 | static const int AMQP_RESOURCE_ERROR = 506;
40 | static const int AMQP_NOT_ALLOWED = 530;
41 | static const int AMQP_NOT_IMPLEMENTED = 540;
42 | static const int AMQP_INTERNAL_ERROR = 541;
43 |
44 | static const int AMQP_CONNECTION_START_METHOD = (0x000A000A);
45 | static const int AMQP_CONNECTION_START_OK_METHOD = (0x000A000B);
46 | static const int AMQP_CONNECTION_SECURE_METHOD = (0x000A0014);
47 | static const int AMQP_CONNECTION_SECURE_OK_METHOD = (0x000A0015);
48 | static const int AMQP_CONNECTION_TUNE_METHOD = (0x000A001E);
49 | static const int AMQP_CONNECTION_TUNE_OK_METHOD = (0x000A001F);
50 | static const int AMQP_CONNECTION_OPEN_METHOD = (0x000A0028);
51 | static const int AMQP_CONNECTION_OPEN_OK_METHOD = (0x000A0029);
52 | static const int AMQP_CONNECTION_CLOSE_METHOD = (0x000A0032);
53 | static const int AMQP_CONNECTION_CLOSE_OK_METHOD = (0x000A0033);
54 | static const int AMQP_CHANNEL_OPEN_METHOD = (0x0014000A);
55 | static const int AMQP_CHANNEL_OPEN_OK_METHOD = (0x0014000B);
56 | static const int AMQP_CHANNEL_FLOW_METHOD = (0x00140014);
57 | static const int AMQP_CHANNEL_FLOW_OK_METHOD = (0x00140015);
58 | static const int AMQP_CHANNEL_CLOSE_METHOD = (0x00140028);
59 | static const int AMQP_CHANNEL_CLOSE_OK_METHOD = (0x00140029);
60 | static const int AMQP_ACCESS_REQUEST_METHOD = (0x001E000A);
61 | static const int AMQP_ACCESS_REQUEST_OK_METHOD = (0x001E000B);
62 | static const int AMQP_EXCHANGE_DECLARE_METHOD = (0x0028000A);
63 | static const int AMQP_EXCHANGE_DECLARE_OK_METHOD = (0x0028000B);
64 | static const int AMQP_EXCHANGE_DELETE_METHOD = (0x00280014);
65 | static const int AMQP_EXCHANGE_DELETE_OK_METHOD = (0x00280015);
66 | static const int AMQP_EXCHANGE_BIND_METHOD = (0x0028001E);
67 | static const int AMQP_EXCHANGE_BIND_OK_METHOD = (0x0028001F);
68 | static const int AMQP_EXCHANGE_UNBIND_METHOD = (0x00280028);
69 | static const int AMQP_EXCHANGE_UNBIND_OK_METHOD = (0x00280033);
70 | static const int AMQP_QUEUE_DECLARE_METHOD = (0x0032000A);
71 | static const int AMQP_QUEUE_DECLARE_OK_METHOD = (0x0032000B);
72 | static const int AMQP_QUEUE_BIND_METHOD = (0x00320014);
73 | static const int AMQP_QUEUE_BIND_OK_METHOD = (0x00320015);
74 | static const int AMQP_QUEUE_PURGE_METHOD = (0x0032001E);
75 | static const int AMQP_QUEUE_PURGE_OK_METHOD = (0x0032001F);
76 | static const int AMQP_QUEUE_DELETE_METHOD = (0x00320028);
77 | static const int AMQP_QUEUE_DELETE_OK_METHOD = (0x00320029);
78 | static const int AMQP_QUEUE_UNBIND_METHOD = (0x00320032);
79 | static const int AMQP_QUEUE_UNBIND_OK_METHOD = (0x00320033);
80 | static const int AMQP_BASIC_QOS_METHOD = (0x003C000A);
81 | static const int AMQP_BASIC_QOS_OK_METHOD = (0x003C000B);
82 | static const int AMQP_BASIC_CONSUME_METHOD = (0x003C0014);
83 | static const int AMQP_BASIC_CONSUME_OK_METHOD = (0x003C0015);
84 | static const int AMQP_BASIC_CANCEL_METHOD = (0x003C001E);
85 | static const int AMQP_BASIC_CANCEL_OK_METHOD = (0x003C001F);
86 | static const int AMQP_BASIC_PUBLISH_METHOD = (0x003C0028);
87 | static const int AMQP_BASIC_RETURN_METHOD = (0x003C0032);
88 | static const int AMQP_BASIC_DELIVER_METHOD = (0x003C003C);
89 | static const int AMQP_BASIC_GET_METHOD = (0x003C0046);
90 | static const int AMQP_BASIC_GET_OK_METHOD = (0x003C0047);
91 | static const int AMQP_BASIC_GET_EMPTY_METHOD = (0x003C0048);
92 | static const int AMQP_BASIC_ACK_METHOD = (0x003C0050);
93 | static const int AMQP_BASIC_REJECT_METHOD = (0x003C005A);
94 | static const int AMQP_BASIC_RECOVER_ASYNC_METHOD = (0x003C0064);
95 | static const int AMQP_BASIC_RECOVER_METHOD = (0x003C006E);
96 | static const int AMQP_BASIC_RECOVER_OK_METHOD = (0x003C006F);
97 | static const int AMQP_BASIC_NACK_METHOD = (0x003C0078);
98 | static const int AMQP_TX_SELECT_METHOD = (0x005A000A);
99 | static const int AMQP_TX_SELECT_OK_METHOD = (0x005A000B);
100 | static const int AMQP_TX_COMMIT_METHOD = (0x005A0014);
101 | static const int AMQP_TX_COMMIT_OK_METHOD = (0x005A0015);
102 | static const int AMQP_TX_ROLLBACK_METHOD = (0x005A001E);
103 | static const int AMQP_TX_ROLLBACK_OK_METHOD = (0x005A001F);
104 | static const int AMQP_CONFIRM_SELECT_METHOD = (0x0055000A);
105 | static const int AMQP_CONFIRM_SELECT_OK_METHOD = (0x0055000B);
106 | static const int AMQP_CONNECTION_CLASS = (0x000A);
107 | static const int AMQP_CHANNEL_CLASS = (0x0014);
108 | static const int AMQP_ACCESS_CLASS = (0x001E);
109 | static const int AMQP_EXCHANGE_CLASS = (0x0028);
110 | static const int AMQP_QUEUE_CLASS = (0x0032);
111 | static const int AMQP_BASIC_CLASS = (0x003C);
112 | static const int AMQP_BASIC_CONTENT_TYPE_FLAG = (1<<15);
113 | static const int AMQP_BASIC_CONTENT_ENCODING_FLAG = (1<<14);
114 | static const int AMQP_BASIC_HEADERS_FLAG = (1<<13);
115 | static const int AMQP_BASIC_DELIVERY_MODE_FLAG = (1<<12);
116 | static const int AMQP_BASIC_PRIORITY_FLAG = (1<<11);
117 | static const int AMQP_BASIC_CORRELATION_ID_FLAG = (1<<10);
118 | static const int AMQP_BASIC_REPLY_TO_FLAG = (1<<9);
119 | static const int AMQP_BASIC_EXPIRATION_FLAG = (1<<8);
120 | static const int AMQP_BASIC_MESSAGE_ID_FLAG = (1<<7);
121 | static const int AMQP_BASIC_TIMESTAMP_FLAG = (1<<6);
122 | static const int AMQP_BASIC_TYPE_FLAG = (1<<5);
123 | static const int AMQP_BASIC_USER_ID_FLAG = (1<<4);
124 | static const int AMQP_BASIC_APP_ID_FLAG = (1<<3);
125 | static const int AMQP_BASIC_CLUSTER_ID_FLAG = (1<<2);
126 | static const int AMQP_TX_CLASS = (0x005A);
127 | static const int AMQP_CONFIRM_CLASS = (0x0055);
128 |
129 |
130 | typedef int amqp_boolean_t;
131 | typedef uint32_t amqp_method_number_t;
132 | typedef uint32_t amqp_flags_t;
133 | typedef uint16_t amqp_channel_t;
134 |
135 | typedef struct amqp_bytes_t_ {
136 | size_t len;
137 | void *bytes;
138 | } amqp_bytes_t;
139 |
140 | typedef struct amqp_decimal_t_ {
141 | uint8_t decimals;
142 | uint32_t value;
143 | } amqp_decimal_t;
144 |
145 | typedef struct amqp_table_t_ {
146 | int num_entries;
147 | struct amqp_table_entry_t_ *entries;
148 | } amqp_table_t;
149 |
150 | typedef struct amqp_array_t_ {
151 | int num_entries;
152 | struct amqp_field_value_t_ *entries;
153 | } amqp_array_t;
154 | typedef struct amqp_field_value_t_ {
155 | uint8_t kind;
156 | union {
157 | amqp_boolean_t boolean;
158 | int8_t i8;
159 | uint8_t u8;
160 | int16_t i16;
161 | uint16_t u16;
162 | int32_t i32;
163 | uint32_t u32;
164 | int64_t i64;
165 | uint64_t u64;
166 | float f32;
167 | double f64;
168 | amqp_decimal_t decimal;
169 | amqp_bytes_t bytes;
170 | amqp_table_t table;
171 | amqp_array_t array;
172 | } value;
173 | } amqp_field_value_t;
174 |
175 | typedef struct amqp_table_entry_t_ {
176 | amqp_bytes_t key;
177 | amqp_field_value_t value;
178 | } amqp_table_entry_t;
179 |
180 | typedef enum {
181 | AMQP_FIELD_KIND_BOOLEAN = 't',
182 | AMQP_FIELD_KIND_I8 = 'b',
183 | AMQP_FIELD_KIND_U8 = 'B',
184 | AMQP_FIELD_KIND_I16 = 's',
185 | AMQP_FIELD_KIND_U16 = 'u',
186 | AMQP_FIELD_KIND_I32 = 'I',
187 | AMQP_FIELD_KIND_U32 = 'i',
188 | AMQP_FIELD_KIND_I64 = 'l',
189 | AMQP_FIELD_KIND_U64 = 'L',
190 | AMQP_FIELD_KIND_F32 = 'f',
191 | AMQP_FIELD_KIND_F64 = 'd',
192 | AMQP_FIELD_KIND_DECIMAL = 'D',
193 | AMQP_FIELD_KIND_UTF8 = 'S',
194 | AMQP_FIELD_KIND_ARRAY = 'A',
195 | AMQP_FIELD_KIND_TIMESTAMP = 'T',
196 | AMQP_FIELD_KIND_TABLE = 'F',
197 | AMQP_FIELD_KIND_VOID = 'V',
198 | AMQP_FIELD_KIND_BYTES = 'x'
199 | } amqp_field_value_kind_t;
200 |
201 | typedef struct amqp_pool_blocklist_t_ {
202 | int num_blocks;
203 | void **blocklist;
204 | } amqp_pool_blocklist_t;
205 |
206 | typedef struct amqp_pool_t_ {
207 | size_t pagesize;
208 |
209 | amqp_pool_blocklist_t pages;
210 | amqp_pool_blocklist_t large_blocks;
211 |
212 | int next_page;
213 | char *alloc_block;
214 | size_t alloc_used;
215 | } amqp_pool_t;
216 |
217 | typedef struct amqp_method_t_ {
218 | amqp_method_number_t id;
219 | void *decoded;
220 | } amqp_method_t;
221 |
222 | typedef struct amqp_frame_t_ {
223 | uint8_t frame_type;
224 | amqp_channel_t channel;
225 | union {
226 | amqp_method_t method;
227 | struct {
228 | uint16_t class_id;
229 | uint64_t body_size;
230 | void *decoded;
231 | amqp_bytes_t raw;
232 | } properties;
233 | amqp_bytes_t body_fragment;
234 | struct {
235 | uint8_t transport_high;
236 | uint8_t transport_low;
237 | uint8_t protocol_version_major;
238 | uint8_t protocol_version_minor;
239 | } protocol_header;
240 | } payload;
241 | } amqp_frame_t;
242 |
243 | typedef enum amqp_response_type_enum_ {
244 | AMQP_RESPONSE_NONE = 0,
245 | AMQP_RESPONSE_NORMAL,
246 | AMQP_RESPONSE_LIBRARY_EXCEPTION,
247 | AMQP_RESPONSE_SERVER_EXCEPTION
248 | } amqp_response_type_enum;
249 |
250 | typedef struct amqp_rpc_reply_t_ {
251 | amqp_response_type_enum reply_type;
252 | amqp_method_t reply;
253 | int library_error;
254 | } amqp_rpc_reply_t;
255 |
256 | typedef enum amqp_sasl_method_enum_ {
257 | AMQP_SASL_METHOD_PLAIN = 0
258 | } amqp_sasl_method_enum;
259 |
260 | typedef struct amqp_connection_state_t_ *amqp_connection_state_t;
261 |
262 |
263 | char const *
264 | amqp_version(void);
265 |
266 | const amqp_bytes_t amqp_empty_bytes;
267 | const amqp_table_t amqp_empty_table;
268 | const amqp_array_t amqp_empty_array;
269 |
270 |
271 |
272 | void
273 | init_amqp_pool(amqp_pool_t *pool, size_t pagesize);
274 |
275 |
276 | void
277 | recycle_amqp_pool(amqp_pool_t *pool);
278 |
279 |
280 | void
281 | empty_amqp_pool(amqp_pool_t *pool);
282 |
283 |
284 | void *
285 | amqp_pool_alloc(amqp_pool_t *pool, size_t amount);
286 |
287 |
288 | void
289 | amqp_pool_alloc_bytes(amqp_pool_t *pool, size_t amount, amqp_bytes_t *output);
290 |
291 |
292 | amqp_bytes_t
293 | amqp_cstring_bytes(char const *cstr);
294 |
295 |
296 | amqp_bytes_t
297 | amqp_bytes_malloc_dup(amqp_bytes_t src);
298 |
299 |
300 | amqp_bytes_t
301 | amqp_bytes_malloc(size_t amount);
302 |
303 |
304 | void
305 | amqp_bytes_free(amqp_bytes_t bytes);
306 |
307 |
308 | amqp_connection_state_t
309 | amqp_new_connection(void);
310 |
311 |
312 | int
313 | amqp_get_sockfd(amqp_connection_state_t state);
314 |
315 |
316 | void
317 | amqp_set_sockfd(amqp_connection_state_t state, int sockfd);
318 |
319 |
320 | int
321 | amqp_tune_connection(amqp_connection_state_t state,
322 | int channel_max,
323 | int frame_max,
324 | int heartbeat);
325 |
326 |
327 | int
328 | amqp_get_channel_max(amqp_connection_state_t state);
329 |
330 |
331 | int
332 | amqp_destroy_connection(amqp_connection_state_t state);
333 |
334 |
335 | int
336 | amqp_handle_input(amqp_connection_state_t state,
337 | amqp_bytes_t received_data,
338 | amqp_frame_t *decoded_frame);
339 |
340 |
341 | amqp_boolean_t
342 | amqp_release_buffers_ok(amqp_connection_state_t state);
343 |
344 |
345 | void
346 | amqp_release_buffers(amqp_connection_state_t state);
347 |
348 |
349 | void
350 | amqp_maybe_release_buffers(amqp_connection_state_t state);
351 |
352 |
353 | int
354 | amqp_send_frame(amqp_connection_state_t state, amqp_frame_t const *frame);
355 |
356 |
357 | int
358 | amqp_table_entry_cmp(void const *entry1, void const *entry2);
359 |
360 |
361 | int
362 | amqp_open_socket(char const *hostname, int portnumber);
363 |
364 |
365 | int
366 | amqp_send_header(amqp_connection_state_t state);
367 |
368 |
369 | amqp_boolean_t
370 | amqp_frames_enqueued(amqp_connection_state_t state);
371 |
372 |
373 | int
374 | amqp_simple_wait_frame(amqp_connection_state_t state,
375 | amqp_frame_t *decoded_frame);
376 |
377 |
378 | int
379 | amqp_simple_wait_method(amqp_connection_state_t state,
380 | amqp_channel_t expected_channel,
381 | amqp_method_number_t expected_method,
382 | amqp_method_t *output);
383 |
384 |
385 | int
386 | amqp_send_method(amqp_connection_state_t state,
387 | amqp_channel_t channel,
388 | amqp_method_number_t id,
389 | void *decoded);
390 |
391 |
392 | amqp_rpc_reply_t
393 | amqp_simple_rpc(amqp_connection_state_t state,
394 | amqp_channel_t channel,
395 | amqp_method_number_t request_id,
396 | amqp_method_number_t *expected_reply_ids,
397 | void *decoded_request_method);
398 |
399 |
400 | void *
401 | amqp_simple_rpc_decoded(amqp_connection_state_t state,
402 | amqp_channel_t channel,
403 | amqp_method_number_t request_id,
404 | amqp_method_number_t reply_id,
405 | void *decoded_request_method);
406 |
407 |
408 |
409 | amqp_rpc_reply_t
410 | amqp_get_rpc_reply(amqp_connection_state_t state);
411 |
412 |
413 | amqp_rpc_reply_t
414 | amqp_login(amqp_connection_state_t state, char const *vhost,
415 | int channel_max, int frame_max, int heartbeat,
416 | amqp_sasl_method_enum sasl_method, ...);
417 |
418 | struct amqp_basic_properties_t_;
419 |
420 |
421 | int
422 | amqp_basic_publish(amqp_connection_state_t state, amqp_channel_t channel,
423 | amqp_bytes_t exchange, amqp_bytes_t routing_key,
424 | amqp_boolean_t mandatory, amqp_boolean_t immediate,
425 | struct amqp_basic_properties_t_ const *properties,
426 | amqp_bytes_t body);
427 |
428 |
429 | amqp_rpc_reply_t
430 | amqp_channel_close(amqp_connection_state_t state, amqp_channel_t channel,
431 | int code);
432 |
433 |
434 | amqp_rpc_reply_t
435 | amqp_connection_close(amqp_connection_state_t state, int code);
436 |
437 |
438 | int
439 | amqp_basic_ack(amqp_connection_state_t state, amqp_channel_t channel,
440 | uint64_t delivery_tag, amqp_boolean_t multiple);
441 |
442 |
443 | amqp_rpc_reply_t
444 | amqp_basic_get(amqp_connection_state_t state, amqp_channel_t channel,
445 | amqp_bytes_t queue, amqp_boolean_t no_ack);
446 |
447 |
448 | int
449 | amqp_basic_reject(amqp_connection_state_t state, amqp_channel_t channel,
450 | uint64_t delivery_tag, amqp_boolean_t requeue);
451 |
452 |
453 | amqp_boolean_t
454 | amqp_data_in_buffer(amqp_connection_state_t state);
455 |
456 |
457 |
458 | char *
459 | amqp_error_string(int err);
460 |
461 |
462 | int
463 | amqp_decode_table(amqp_bytes_t encoded, amqp_pool_t *pool,
464 | amqp_table_t *output, size_t *offset);
465 |
466 |
467 | int
468 | amqp_encode_table(amqp_bytes_t encoded, amqp_table_t *input, size_t *offset);
469 |
470 | struct amqp_connection_info {
471 | char *user;
472 | char *password;
473 | char *host;
474 | char *vhost;
475 | int port;
476 | };
477 |
478 |
479 | void
480 | amqp_default_connection_info(struct amqp_connection_info *parsed);
481 |
482 |
483 | int
484 | amqp_parse_url(char *url, struct amqp_connection_info *parsed);
485 |
486 |
487 |
488 | char const *
489 | amqp_constant_name(int constantNumber);
490 |
491 |
492 | amqp_boolean_t
493 | amqp_constant_is_hard_error(int constantNumber);
494 |
495 |
496 | char const *
497 | amqp_method_name(amqp_method_number_t methodNumber);
498 |
499 |
500 | amqp_boolean_t
501 | amqp_method_has_content(amqp_method_number_t methodNumber);
502 |
503 |
504 | int
505 | amqp_decode_method(amqp_method_number_t methodNumber,
506 | amqp_pool_t *pool,
507 | amqp_bytes_t encoded,
508 | void **decoded);
509 |
510 |
511 | int
512 | amqp_decode_properties(uint16_t class_id,
513 | amqp_pool_t *pool,
514 | amqp_bytes_t encoded,
515 | void **decoded);
516 |
517 |
518 | int
519 | amqp_encode_method(amqp_method_number_t methodNumber,
520 | void *decoded,
521 | amqp_bytes_t encoded);
522 |
523 |
524 | int
525 | amqp_encode_properties(uint16_t class_id,
526 | void *decoded,
527 | amqp_bytes_t encoded);
528 |
529 | /* Method field records. */
530 |
531 | typedef struct amqp_connection_start_t_ {
532 | uint8_t version_major;
533 | uint8_t version_minor;
534 | amqp_table_t server_properties;
535 | amqp_bytes_t mechanisms;
536 | amqp_bytes_t locales;
537 | } amqp_connection_start_t;
538 |
539 | typedef struct amqp_connection_start_ok_t_ {
540 | amqp_table_t client_properties;
541 | amqp_bytes_t mechanism;
542 | amqp_bytes_t response;
543 | amqp_bytes_t locale;
544 | } amqp_connection_start_ok_t;
545 |
546 | typedef struct amqp_connection_secure_t_ {
547 | amqp_bytes_t challenge;
548 | } amqp_connection_secure_t;
549 |
550 | typedef struct amqp_connection_secure_ok_t_ {
551 | amqp_bytes_t response;
552 | } amqp_connection_secure_ok_t;
553 |
554 | typedef struct amqp_connection_tune_t_ {
555 | uint16_t channel_max;
556 | uint32_t frame_max;
557 | uint16_t heartbeat;
558 | } amqp_connection_tune_t;
559 |
560 | typedef struct amqp_connection_tune_ok_t_ {
561 | uint16_t channel_max;
562 | uint32_t frame_max;
563 | uint16_t heartbeat;
564 | } amqp_connection_tune_ok_t;
565 |
566 | typedef struct amqp_connection_open_t_ {
567 | amqp_bytes_t virtual_host;
568 | amqp_bytes_t capabilities;
569 | amqp_boolean_t insist;
570 | } amqp_connection_open_t;
571 |
572 | typedef struct amqp_connection_open_ok_t_ {
573 | amqp_bytes_t known_hosts;
574 | } amqp_connection_open_ok_t;
575 |
576 | typedef struct amqp_connection_close_t_ {
577 | uint16_t reply_code;
578 | amqp_bytes_t reply_text;
579 | uint16_t class_id;
580 | uint16_t method_id;
581 | } amqp_connection_close_t;
582 |
583 | typedef struct amqp_connection_close_ok_t_ {
584 | char dummy; /* Dummy field to avoid empty struct */
585 | } amqp_connection_close_ok_t;
586 |
587 | typedef struct amqp_channel_open_t_ {
588 | amqp_bytes_t out_of_band;
589 | } amqp_channel_open_t;
590 |
591 | typedef struct amqp_channel_open_ok_t_ {
592 | amqp_bytes_t channel_id;
593 | } amqp_channel_open_ok_t;
594 |
595 | typedef struct amqp_channel_flow_t_ {
596 | amqp_boolean_t active;
597 | } amqp_channel_flow_t;
598 |
599 | typedef struct amqp_channel_flow_ok_t_ {
600 | amqp_boolean_t active;
601 | } amqp_channel_flow_ok_t;
602 |
603 | typedef struct amqp_channel_close_t_ {
604 | uint16_t reply_code;
605 | amqp_bytes_t reply_text;
606 | uint16_t class_id;
607 | uint16_t method_id;
608 | } amqp_channel_close_t;
609 |
610 | typedef struct amqp_channel_close_ok_t_ {
611 | char dummy; /* Dummy field to avoid empty struct */
612 | } amqp_channel_close_ok_t;
613 |
614 | typedef struct amqp_access_request_t_ {
615 | amqp_bytes_t realm;
616 | amqp_boolean_t exclusive;
617 | amqp_boolean_t passive;
618 | amqp_boolean_t active;
619 | amqp_boolean_t write;
620 | amqp_boolean_t read;
621 | } amqp_access_request_t;
622 |
623 | typedef struct amqp_access_request_ok_t_ {
624 | uint16_t ticket;
625 | } amqp_access_request_ok_t;
626 |
627 | typedef struct amqp_exchange_declare_t_ {
628 | uint16_t ticket;
629 | amqp_bytes_t exchange;
630 | amqp_bytes_t type;
631 | amqp_boolean_t passive;
632 | amqp_boolean_t durable;
633 | amqp_boolean_t auto_delete;
634 | amqp_boolean_t internal;
635 | amqp_boolean_t nowait;
636 | amqp_table_t arguments;
637 | } amqp_exchange_declare_t;
638 |
639 | typedef struct amqp_exchange_declare_ok_t_ {
640 | char dummy; /* Dummy field to avoid empty struct */
641 | } amqp_exchange_declare_ok_t;
642 |
643 | typedef struct amqp_exchange_delete_t_ {
644 | uint16_t ticket;
645 | amqp_bytes_t exchange;
646 | amqp_boolean_t if_unused;
647 | amqp_boolean_t nowait;
648 | } amqp_exchange_delete_t;
649 |
650 | typedef struct amqp_exchange_delete_ok_t_ {
651 | char dummy; /* Dummy field to avoid empty struct */
652 | } amqp_exchange_delete_ok_t;
653 |
654 | typedef struct amqp_exchange_bind_t_ {
655 | uint16_t ticket;
656 | amqp_bytes_t destination;
657 | amqp_bytes_t source;
658 | amqp_bytes_t routing_key;
659 | amqp_boolean_t nowait;
660 | amqp_table_t arguments;
661 | } amqp_exchange_bind_t;
662 |
663 | typedef struct amqp_exchange_bind_ok_t_ {
664 | char dummy; /* Dummy field to avoid empty struct */
665 | } amqp_exchange_bind_ok_t;
666 |
667 | typedef struct amqp_exchange_unbind_t_ {
668 | uint16_t ticket;
669 | amqp_bytes_t destination;
670 | amqp_bytes_t source;
671 | amqp_bytes_t routing_key;
672 | amqp_boolean_t nowait;
673 | amqp_table_t arguments;
674 | } amqp_exchange_unbind_t;
675 |
676 | typedef struct amqp_exchange_unbind_ok_t_ {
677 | char dummy; /* Dummy field to avoid empty struct */
678 | } amqp_exchange_unbind_ok_t;
679 |
680 | typedef struct amqp_queue_declare_t_ {
681 | uint16_t ticket;
682 | amqp_bytes_t queue;
683 | amqp_boolean_t passive;
684 | amqp_boolean_t durable;
685 | amqp_boolean_t exclusive;
686 | amqp_boolean_t auto_delete;
687 | amqp_boolean_t nowait;
688 | amqp_table_t arguments;
689 | } amqp_queue_declare_t;
690 |
691 | typedef struct amqp_queue_declare_ok_t_ {
692 | amqp_bytes_t queue;
693 | uint32_t message_count;
694 | uint32_t consumer_count;
695 | } amqp_queue_declare_ok_t;
696 |
697 | typedef struct amqp_queue_bind_t_ {
698 | uint16_t ticket;
699 | amqp_bytes_t queue;
700 | amqp_bytes_t exchange;
701 | amqp_bytes_t routing_key;
702 | amqp_boolean_t nowait;
703 | amqp_table_t arguments;
704 | } amqp_queue_bind_t;
705 |
706 | typedef struct amqp_queue_bind_ok_t_ {
707 | char dummy; /* Dummy field to avoid empty struct */
708 | } amqp_queue_bind_ok_t;
709 |
710 | typedef struct amqp_queue_purge_t_ {
711 | uint16_t ticket;
712 | amqp_bytes_t queue;
713 | amqp_boolean_t nowait;
714 | } amqp_queue_purge_t;
715 |
716 | typedef struct amqp_queue_purge_ok_t_ {
717 | uint32_t message_count;
718 | } amqp_queue_purge_ok_t;
719 |
720 | typedef struct amqp_queue_delete_t_ {
721 | uint16_t ticket;
722 | amqp_bytes_t queue;
723 | amqp_boolean_t if_unused;
724 | amqp_boolean_t if_empty;
725 | amqp_boolean_t nowait;
726 | } amqp_queue_delete_t;
727 |
728 | typedef struct amqp_queue_delete_ok_t_ {
729 | uint32_t message_count;
730 | } amqp_queue_delete_ok_t;
731 |
732 | typedef struct amqp_queue_unbind_t_ {
733 | uint16_t ticket;
734 | amqp_bytes_t queue;
735 | amqp_bytes_t exchange;
736 | amqp_bytes_t routing_key;
737 | amqp_table_t arguments;
738 | } amqp_queue_unbind_t;
739 |
740 | typedef struct amqp_queue_unbind_ok_t_ {
741 | char dummy; /* Dummy field to avoid empty struct */
742 | } amqp_queue_unbind_ok_t;
743 |
744 | typedef struct amqp_basic_qos_t_ {
745 | uint32_t prefetch_size;
746 | uint16_t prefetch_count;
747 | amqp_boolean_t global;
748 | } amqp_basic_qos_t;
749 |
750 | typedef struct amqp_basic_qos_ok_t_ {
751 | char dummy; /* Dummy field to avoid empty struct */
752 | } amqp_basic_qos_ok_t;
753 |
754 | typedef struct amqp_basic_consume_t_ {
755 | uint16_t ticket;
756 | amqp_bytes_t queue;
757 | amqp_bytes_t consumer_tag;
758 | amqp_boolean_t no_local;
759 | amqp_boolean_t no_ack;
760 | amqp_boolean_t exclusive;
761 | amqp_boolean_t nowait;
762 | amqp_table_t arguments;
763 | } amqp_basic_consume_t;
764 |
765 | typedef struct amqp_basic_consume_ok_t_ {
766 | amqp_bytes_t consumer_tag;
767 | } amqp_basic_consume_ok_t;
768 |
769 | typedef struct amqp_basic_cancel_t_ {
770 | amqp_bytes_t consumer_tag;
771 | amqp_boolean_t nowait;
772 | } amqp_basic_cancel_t;
773 |
774 | typedef struct amqp_basic_cancel_ok_t_ {
775 | amqp_bytes_t consumer_tag;
776 | } amqp_basic_cancel_ok_t;
777 |
778 | typedef struct amqp_basic_publish_t_ {
779 | uint16_t ticket;
780 | amqp_bytes_t exchange;
781 | amqp_bytes_t routing_key;
782 | amqp_boolean_t mandatory;
783 | amqp_boolean_t immediate;
784 | } amqp_basic_publish_t;
785 |
786 | typedef struct amqp_basic_return_t_ {
787 | uint16_t reply_code;
788 | amqp_bytes_t reply_text;
789 | amqp_bytes_t exchange;
790 | amqp_bytes_t routing_key;
791 | } amqp_basic_return_t;
792 |
793 | typedef struct amqp_basic_deliver_t_ {
794 | amqp_bytes_t consumer_tag;
795 | uint64_t delivery_tag;
796 | amqp_boolean_t redelivered;
797 | amqp_bytes_t exchange;
798 | amqp_bytes_t routing_key;
799 | } amqp_basic_deliver_t;
800 |
801 | typedef struct amqp_basic_get_t_ {
802 | uint16_t ticket;
803 | amqp_bytes_t queue;
804 | amqp_boolean_t no_ack;
805 | } amqp_basic_get_t;
806 |
807 | typedef struct amqp_basic_get_ok_t_ {
808 | uint64_t delivery_tag;
809 | amqp_boolean_t redelivered;
810 | amqp_bytes_t exchange;
811 | amqp_bytes_t routing_key;
812 | uint32_t message_count;
813 | } amqp_basic_get_ok_t;
814 |
815 | typedef struct amqp_basic_get_empty_t_ {
816 | amqp_bytes_t cluster_id;
817 | } amqp_basic_get_empty_t;
818 |
819 | typedef struct amqp_basic_ack_t_ {
820 | uint64_t delivery_tag;
821 | amqp_boolean_t multiple;
822 | } amqp_basic_ack_t;
823 |
824 | typedef struct amqp_basic_reject_t_ {
825 | uint64_t delivery_tag;
826 | amqp_boolean_t requeue;
827 | } amqp_basic_reject_t;
828 |
829 | typedef struct amqp_basic_recover_async_t_ {
830 | amqp_boolean_t requeue;
831 | } amqp_basic_recover_async_t;
832 |
833 | typedef struct amqp_basic_recover_t_ {
834 | amqp_boolean_t requeue;
835 | } amqp_basic_recover_t;
836 |
837 | typedef struct amqp_basic_recover_ok_t_ {
838 | char dummy; /* Dummy field to avoid empty struct */
839 | } amqp_basic_recover_ok_t;
840 |
841 | typedef struct amqp_basic_nack_t_ {
842 | uint64_t delivery_tag;
843 | amqp_boolean_t multiple;
844 | amqp_boolean_t requeue;
845 | } amqp_basic_nack_t;
846 |
847 | typedef struct amqp_tx_select_t_ {
848 | char dummy; /* Dummy field to avoid empty struct */
849 | } amqp_tx_select_t;
850 |
851 | typedef struct amqp_tx_select_ok_t_ {
852 | char dummy; /* Dummy field to avoid empty struct */
853 | } amqp_tx_select_ok_t;
854 |
855 | typedef struct amqp_tx_commit_t_ {
856 | char dummy; /* Dummy field to avoid empty struct */
857 | } amqp_tx_commit_t;
858 |
859 | typedef struct amqp_tx_commit_ok_t_ {
860 | char dummy; /* Dummy field to avoid empty struct */
861 | } amqp_tx_commit_ok_t;
862 |
863 | typedef struct amqp_tx_rollback_t_ {
864 | char dummy; /* Dummy field to avoid empty struct */
865 | } amqp_tx_rollback_t;
866 |
867 | typedef struct amqp_tx_rollback_ok_t_ {
868 | char dummy; /* Dummy field to avoid empty struct */
869 | } amqp_tx_rollback_ok_t;
870 |
871 | typedef struct amqp_confirm_select_t_ {
872 | amqp_boolean_t nowait;
873 | } amqp_confirm_select_t;
874 |
875 | typedef struct amqp_confirm_select_ok_t_ {
876 | char dummy; /* Dummy field to avoid empty struct */
877 | } amqp_confirm_select_ok_t;
878 |
879 | /* Class property records. */
880 | typedef struct amqp_connection_properties_t_ {
881 | amqp_flags_t _flags;
882 | char dummy; /* Dummy field to avoid empty struct */
883 | } amqp_connection_properties_t;
884 |
885 | typedef struct amqp_channel_properties_t_ {
886 | amqp_flags_t _flags;
887 | char dummy; /* Dummy field to avoid empty struct */
888 | } amqp_channel_properties_t;
889 |
890 | typedef struct amqp_access_properties_t_ {
891 | amqp_flags_t _flags;
892 | char dummy; /* Dummy field to avoid empty struct */
893 | } amqp_access_properties_t;
894 |
895 | typedef struct amqp_exchange_properties_t_ {
896 | amqp_flags_t _flags;
897 | char dummy; /* Dummy field to avoid empty struct */
898 | } amqp_exchange_properties_t;
899 |
900 | typedef struct amqp_queue_properties_t_ {
901 | amqp_flags_t _flags;
902 | char dummy; /* Dummy field to avoid empty struct */
903 | } amqp_queue_properties_t;
904 |
905 | typedef struct amqp_basic_properties_t_ {
906 | amqp_flags_t _flags;
907 | amqp_bytes_t content_type;
908 | amqp_bytes_t content_encoding;
909 | amqp_table_t headers;
910 | uint8_t delivery_mode;
911 | uint8_t priority;
912 | amqp_bytes_t correlation_id;
913 | amqp_bytes_t reply_to;
914 | amqp_bytes_t expiration;
915 | amqp_bytes_t message_id;
916 | uint64_t timestamp;
917 | amqp_bytes_t type;
918 | amqp_bytes_t user_id;
919 | amqp_bytes_t app_id;
920 | amqp_bytes_t cluster_id;
921 | } amqp_basic_properties_t;
922 |
923 | typedef struct amqp_tx_properties_t_ {
924 | amqp_flags_t _flags;
925 | char dummy; /* Dummy field to avoid empty struct */
926 | } amqp_tx_properties_t;
927 |
928 | typedef struct amqp_confirm_properties_t_ {
929 | amqp_flags_t _flags;
930 | char dummy; /* Dummy field to avoid empty struct */
931 | } amqp_confirm_properties_t;
932 |
933 | /* API functions for methods */
934 |
935 | amqp_channel_open_ok_t * amqp_channel_open(amqp_connection_state_t state, amqp_channel_t channel);
936 | amqp_channel_flow_ok_t * amqp_channel_flow(amqp_connection_state_t state, amqp_channel_t channel, amqp_boolean_t active);
937 | amqp_exchange_declare_ok_t * amqp_exchange_declare(amqp_connection_state_t state, amqp_channel_t channel, amqp_bytes_t exchange, amqp_bytes_t type, amqp_boolean_t passive, amqp_boolean_t durable, amqp_table_t arguments);
938 | amqp_exchange_delete_ok_t * amqp_exchange_delete(amqp_connection_state_t state, amqp_channel_t channel, amqp_bytes_t exchange, amqp_boolean_t if_unused);
939 | amqp_exchange_bind_ok_t * amqp_exchange_bind(amqp_connection_state_t state, amqp_channel_t channel, amqp_bytes_t destination, amqp_bytes_t source, amqp_bytes_t routing_key, amqp_table_t arguments);
940 | amqp_exchange_unbind_ok_t * amqp_exchange_unbind(amqp_connection_state_t state, amqp_channel_t channel, amqp_bytes_t destination, amqp_bytes_t source, amqp_bytes_t routing_key, amqp_table_t arguments);
941 | amqp_queue_declare_ok_t * amqp_queue_declare(amqp_connection_state_t state, amqp_channel_t channel, amqp_bytes_t queue, amqp_boolean_t passive, amqp_boolean_t durable, amqp_boolean_t exclusive, amqp_boolean_t auto_delete, amqp_table_t arguments);
942 | amqp_queue_bind_ok_t * amqp_queue_bind(amqp_connection_state_t state, amqp_channel_t channel, amqp_bytes_t queue, amqp_bytes_t exchange, amqp_bytes_t routing_key, amqp_table_t arguments);
943 | amqp_queue_purge_ok_t * amqp_queue_purge(amqp_connection_state_t state, amqp_channel_t channel, amqp_bytes_t queue);
944 | amqp_queue_delete_ok_t * amqp_queue_delete(amqp_connection_state_t state, amqp_channel_t channel, amqp_bytes_t queue, amqp_boolean_t if_unused, amqp_boolean_t if_empty);
945 | amqp_queue_unbind_ok_t * amqp_queue_unbind(amqp_connection_state_t state, amqp_channel_t channel, amqp_bytes_t queue, amqp_bytes_t exchange, amqp_bytes_t routing_key, amqp_table_t arguments);
946 | amqp_basic_qos_ok_t * amqp_basic_qos(amqp_connection_state_t state, amqp_channel_t channel, uint32_t prefetch_size, uint16_t prefetch_count, amqp_boolean_t global);
947 | amqp_basic_consume_ok_t * amqp_basic_consume(amqp_connection_state_t state, amqp_channel_t channel, amqp_bytes_t queue, amqp_bytes_t consumer_tag, amqp_boolean_t no_local, amqp_boolean_t no_ack, amqp_boolean_t exclusive, amqp_table_t arguments);
948 | amqp_basic_cancel_ok_t * amqp_basic_cancel(amqp_connection_state_t state, amqp_channel_t channel, amqp_bytes_t consumer_tag);
949 | amqp_basic_recover_ok_t * amqp_basic_recover(amqp_connection_state_t state, amqp_channel_t channel, amqp_boolean_t requeue);
950 | amqp_tx_select_ok_t * amqp_tx_select(amqp_connection_state_t state, amqp_channel_t channel);
951 | amqp_tx_commit_ok_t * amqp_tx_commit(amqp_connection_state_t state, amqp_channel_t channel);
952 | amqp_tx_rollback_ok_t * amqp_tx_rollback(amqp_connection_state_t state, amqp_channel_t channel);
953 | amqp_confirm_select_ok_t * amqp_confirm_select(amqp_connection_state_t state, amqp_channel_t channel);
954 |
955 | ]]
956 |
957 | return (ffi.load("/usr/local/lib/librabbitmq.so.1"))
958 |
959 |
--------------------------------------------------------------------------------
/nginx.conf:
--------------------------------------------------------------------------------
1 |
2 | #user nobody;
3 | worker_processes 1;
4 | #error_log logs/error.log;
5 | #error_log logs/error.log notice;
6 | #error_log logs/error.log info;
7 |
8 | #pid logs/nginx.pid;
9 |
10 |
11 | events {
12 | worker_connections 1024;
13 | }
14 |
15 |
16 | http {
17 | lua_package_path '/usr/local/share/luajit-2.1.0-alpha/?.lua;;';
18 | lua_package_cpath ';;';
19 | include mime.types;
20 | default_type application/octet-stream;
21 |
22 | #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
23 | # '$status $body_bytes_sent "$http_referer" '
24 | # '"$http_user_agent" "$http_x_forwarded_for"';
25 |
26 | #access_log logs/access.log main;
27 |
28 | sendfile on;
29 | #tcp_nopush on;
30 |
31 | #keepalive_timeout 0;
32 | keepalive_timeout 65;
33 |
34 | #gzip on;
35 |
36 | server {
37 | listen 80;
38 | server_name localhost;
39 |
40 | #charset koi8-r;
41 |
42 | #access_log logs/host.access.log main;
43 |
44 | location / {
45 | root html;
46 | index index.html index.htm;
47 | }
48 | location /test {
49 | set $ip_addr "10.128.136.170";
50 | set $exchange "rumExchange";
51 | set $queue "rumQueue";
52 | set $user "rum";
53 | set $password "rum";
54 | add_header Content-type "text/plain";
55 |
56 | content_by_lua '
57 |
58 | rb=require "amqp-util"
59 |
60 | msg=ngx.var["arg_rum"]
61 | conn = rb.connect_rabbit{host=ngx.var.ip_addr, user=ngx.var.user, password=ngx.var.password}
62 | rb.declare_exchange(conn, ngx.var.exchange, "fanout")
63 | rb.declare_queue(conn, ngx.var.queue, ngx.var.exchange)
64 | rb.bind_queue(conn, ngx.var.queue, ngx.var.exchange)
65 | rb.publish(conn, ngx.var.exchange, msg)
66 | rb.disconnect_rabbit(conn)
67 |
68 | ngx.print("Sent:[", msg,"] to RabbitMQ. Referer: ", ngx.var["http_referer"]);
69 | ';
70 | }
71 | #error_page 404 /404.html;
72 |
73 | # redirect server error pages to the static page /50x.html
74 | #
75 | error_page 500 502 503 504 /50x.html;
76 | location = /50x.html {
77 | root html;
78 | }
79 |
80 | # proxy the PHP scripts to Apache listening on 127.0.0.1:80
81 | #
82 | #location ~ \.php$ {
83 | # proxy_pass http://127.0.0.1;
84 | #}
85 |
86 | # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
87 | #
88 | #location ~ \.php$ {
89 | # root html;
90 | # fastcgi_pass 127.0.0.1:9000;
91 | # fastcgi_index index.php;
92 | # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
93 | # include fastcgi_params;
94 | #}
95 |
96 | # deny access to .htaccess files, if Apache's document root
97 | # concurs with nginx's one
98 | #
99 | #location ~ /\.ht {
100 | # deny all;
101 | #}
102 | }
103 |
104 |
105 | # another virtual host using mix of IP-, name-, and port-based configuration
106 | #
107 | #server {
108 | # listen 8000;
109 | # listen somename:8080;
110 | # server_name somename alias another.alias;
111 |
112 | # location / {
113 | # root html;
114 | # index index.html index.htm;
115 | # }
116 | #}
117 |
118 |
119 | # HTTPS server
120 | #
121 | #server {
122 | # listen 443 ssl;
123 | # server_name localhost;
124 |
125 | # ssl_certificate cert.pem;
126 | # ssl_certificate_key cert.key;
127 |
128 | # ssl_session_cache shared:SSL:1m;
129 | # ssl_session_timeout 5m;
130 |
131 | # ssl_ciphers HIGH:!aNULL:!MD5;
132 | # ssl_prefer_server_ciphers on;
133 |
134 | # location / {
135 | # root html;
136 | # index index.html index.htm;
137 | # }
138 | #}
139 |
140 | }
141 |
--------------------------------------------------------------------------------