├── Makefile ├── README ├── amqp.h ├── amqp_framing.h ├── emit_log_direct ├── emit_log_direct.c ├── librabbitmq.a ├── receive_logs_direct ├── receive_logs_direct.c ├── rmq_new_task ├── rmq_new_task.c ├── rmq_worker ├── rmq_worker.c ├── unix └── platform_utils.c ├── utils.c └── utils.h /Makefile: -------------------------------------------------------------------------------- 1 | all:rmq_worker rmq_new_task emit_log_direct receive_logs_direct 2 | 3 | rmq_worker:rmq_worker.c 4 | gcc -o rmq_worker -Wall rmq_worker.c utils.c unix/platform_utils.c -I. -lrabbitmq 5 | 6 | rmq_new_task:rmq_new_task.c 7 | gcc -o rmq_new_task -Wall rmq_new_task.c utils.c unix/platform_utils.c -I. -lrabbitmq 8 | 9 | emit_log_direct:emit_log_direct.c 10 | gcc -o emit_log_direct -Wall emit_log_direct.c utils.c unix/platform_utils.c -I. -lrabbitmq 11 | 12 | receive_logs_direct:receive_logs_direct.c 13 | gcc -o receive_logs_direct -Wall receive_logs_direct.c utils.c unix/platform_utils.c -I. -lrabbitmq 14 | 15 | clean: 16 | rm rmq_worker rmq_new_task emit_log_direct receive_logs_direct 17 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | I write a demo like the rabbitmq work-queues tutorials(http://www.rabbitmq.com/tutorials/tutorial-two-python.html) with rabbitmq-c lib 2 | 3 | rmq_new_task.c is to new_task.py 4 | rmq_worker.c is to worker.py 5 | 6 | other files is from the rabbitmq-c source files. 7 | 8 | You need the librabbitmq.a to compile the project. 9 | 10 | newer: 11 | a demo like the routing(http://www.rabbitmq.com/tutorials/tutorial-four-python.html) with rabbitmq-c lib 12 | 13 | emit_log_direct.c is to emit_log_direct.py 14 | receive_logs_direct.c is to receive_logs_direct.py 15 | -------------------------------------------------------------------------------- /amqp.h: -------------------------------------------------------------------------------- 1 | #ifndef librabbitmq_amqp_h 2 | #define librabbitmq_amqp_h 3 | 4 | /* 5 | * ***** BEGIN LICENSE BLOCK ***** 6 | * Version: MPL 1.1/GPL 2.0 7 | * 8 | * The contents of this file are subject to the Mozilla Public License 9 | * Version 1.1 (the "License"); you may not use this file except in 10 | * compliance with the License. You may obtain a copy of the License 11 | * at http://www.mozilla.org/MPL/ 12 | * 13 | * Software distributed under the License is distributed on an "AS IS" 14 | * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 15 | * the License for the specific language governing rights and 16 | * limitations under the License. 17 | * 18 | * The Original Code is librabbitmq. 19 | * 20 | * The Initial Developer of the Original Code is VMware, Inc. 21 | * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. 22 | * 23 | * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 24 | * VMware, Inc. and Tony Garnock-Jones. 25 | * 26 | * All rights reserved. 27 | * 28 | * Alternatively, the contents of this file may be used under the terms 29 | * of the GNU General Public License Version 2 or later (the "GPL"), in 30 | * which case the provisions of the GPL are applicable instead of those 31 | * above. If you wish to allow use of your version of this file only 32 | * under the terms of the GPL, and not to allow others to use your 33 | * version of this file under the terms of the MPL, indicate your 34 | * decision by deleting the provisions above and replace them with the 35 | * notice and other provisions required by the GPL. If you do not 36 | * delete the provisions above, a recipient may use your version of 37 | * this file under the terms of any one of the MPL or the GPL. 38 | * 39 | * ***** END LICENSE BLOCK ***** 40 | */ 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | #ifdef _WIN32 47 | #ifdef BUILDING_LIBRABBITMQ 48 | #define RABBITMQ_EXPORT extern __declspec(dllexport) 49 | #else 50 | #define RABBITMQ_EXPORT extern __declspec(dllimport) 51 | #endif 52 | #else 53 | #define RABBITMQ_EXPORT extern 54 | #endif 55 | 56 | typedef int amqp_boolean_t; 57 | typedef uint32_t amqp_method_number_t; 58 | typedef uint32_t amqp_flags_t; 59 | typedef uint16_t amqp_channel_t; 60 | 61 | typedef struct amqp_bytes_t_ { 62 | size_t len; 63 | void *bytes; 64 | } amqp_bytes_t; 65 | 66 | typedef struct amqp_decimal_t_ { 67 | uint8_t decimals; 68 | uint32_t value; 69 | } amqp_decimal_t; 70 | 71 | typedef struct amqp_table_t_ { 72 | int num_entries; 73 | struct amqp_table_entry_t_ *entries; 74 | } amqp_table_t; 75 | 76 | typedef struct amqp_array_t_ { 77 | int num_entries; 78 | struct amqp_field_value_t_ *entries; 79 | } amqp_array_t; 80 | 81 | /* 82 | 0-9 0-9-1 Qpid/Rabbit Type Remarks 83 | --------------------------------------------------------------------------- 84 | t t Boolean 85 | b b Signed 8-bit 86 | B Unsigned 8-bit 87 | U s Signed 16-bit (A1) 88 | u Unsigned 16-bit 89 | I I I Signed 32-bit 90 | i Unsigned 32-bit 91 | L l Signed 64-bit (B) 92 | l Unsigned 64-bit 93 | f f 32-bit float 94 | d d 64-bit float 95 | D D D Decimal 96 | s Short string (A2) 97 | S S S Long string 98 | A Nested Array 99 | T T T Timestamp (u64) 100 | F F F Nested Table 101 | V V V Void 102 | x Byte array 103 | 104 | Remarks: 105 | 106 | A1, A2: Notice how the types **CONFLICT** here. In Qpid and Rabbit, 107 | 's' means a signed 16-bit integer; in 0-9-1, it means a 108 | short string. 109 | 110 | B: Notice how the signednesses **CONFLICT** here. In Qpid and Rabbit, 111 | 'l' means a signed 64-bit integer; in 0-9-1, it means an unsigned 112 | 64-bit integer. 113 | 114 | I'm going with the Qpid/Rabbit types, where there's a conflict, and 115 | the 0-9-1 types otherwise. 0-8 is a subset of 0-9, which is a subset 116 | of the other two, so this will work for both 0-8 and 0-9-1 branches of 117 | the code. 118 | */ 119 | 120 | typedef struct amqp_field_value_t_ { 121 | uint8_t kind; 122 | union { 123 | amqp_boolean_t boolean; 124 | int8_t i8; 125 | uint8_t u8; 126 | int16_t i16; 127 | uint16_t u16; 128 | int32_t i32; 129 | uint32_t u32; 130 | int64_t i64; 131 | uint64_t u64; 132 | float f32; 133 | double f64; 134 | amqp_decimal_t decimal; 135 | amqp_bytes_t bytes; 136 | amqp_table_t table; 137 | amqp_array_t array; 138 | } value; 139 | } amqp_field_value_t; 140 | 141 | typedef struct amqp_table_entry_t_ { 142 | amqp_bytes_t key; 143 | amqp_field_value_t value; 144 | } amqp_table_entry_t; 145 | 146 | typedef enum { 147 | AMQP_FIELD_KIND_BOOLEAN = 't', 148 | AMQP_FIELD_KIND_I8 = 'b', 149 | AMQP_FIELD_KIND_U8 = 'B', 150 | AMQP_FIELD_KIND_I16 = 's', 151 | AMQP_FIELD_KIND_U16 = 'u', 152 | AMQP_FIELD_KIND_I32 = 'I', 153 | AMQP_FIELD_KIND_U32 = 'i', 154 | AMQP_FIELD_KIND_I64 = 'l', 155 | AMQP_FIELD_KIND_U64 = 'L', 156 | AMQP_FIELD_KIND_F32 = 'f', 157 | AMQP_FIELD_KIND_F64 = 'd', 158 | AMQP_FIELD_KIND_DECIMAL = 'D', 159 | AMQP_FIELD_KIND_UTF8 = 'S', 160 | AMQP_FIELD_KIND_ARRAY = 'A', 161 | AMQP_FIELD_KIND_TIMESTAMP = 'T', 162 | AMQP_FIELD_KIND_TABLE = 'F', 163 | AMQP_FIELD_KIND_VOID = 'V', 164 | AMQP_FIELD_KIND_BYTES = 'x' 165 | } amqp_field_value_kind_t; 166 | 167 | typedef struct amqp_pool_blocklist_t_ { 168 | int num_blocks; 169 | void **blocklist; 170 | } amqp_pool_blocklist_t; 171 | 172 | typedef struct amqp_pool_t_ { 173 | size_t pagesize; 174 | 175 | amqp_pool_blocklist_t pages; 176 | amqp_pool_blocklist_t large_blocks; 177 | 178 | int next_page; 179 | char *alloc_block; 180 | size_t alloc_used; 181 | } amqp_pool_t; 182 | 183 | typedef struct amqp_method_t_ { 184 | amqp_method_number_t id; 185 | void *decoded; 186 | } amqp_method_t; 187 | 188 | typedef struct amqp_frame_t_ { 189 | uint8_t frame_type; /* 0 means no event */ 190 | amqp_channel_t channel; 191 | union { 192 | amqp_method_t method; 193 | struct { 194 | uint16_t class_id; 195 | uint64_t body_size; 196 | void *decoded; 197 | amqp_bytes_t raw; 198 | } properties; 199 | amqp_bytes_t body_fragment; 200 | struct { 201 | uint8_t transport_high; 202 | uint8_t transport_low; 203 | uint8_t protocol_version_major; 204 | uint8_t protocol_version_minor; 205 | } protocol_header; 206 | } payload; 207 | } amqp_frame_t; 208 | 209 | typedef enum amqp_response_type_enum_ { 210 | AMQP_RESPONSE_NONE = 0, 211 | AMQP_RESPONSE_NORMAL, 212 | AMQP_RESPONSE_LIBRARY_EXCEPTION, 213 | AMQP_RESPONSE_SERVER_EXCEPTION 214 | } amqp_response_type_enum; 215 | 216 | typedef struct amqp_rpc_reply_t_ { 217 | amqp_response_type_enum reply_type; 218 | amqp_method_t reply; 219 | int library_error; /* if AMQP_RESPONSE_LIBRARY_EXCEPTION, then 0 here means socket EOF */ 220 | } amqp_rpc_reply_t; 221 | 222 | typedef enum amqp_sasl_method_enum_ { 223 | AMQP_SASL_METHOD_PLAIN = 0 224 | } amqp_sasl_method_enum; 225 | 226 | /* Opaque struct. */ 227 | typedef struct amqp_connection_state_t_ *amqp_connection_state_t; 228 | 229 | RABBITMQ_EXPORT char const *amqp_version(void); 230 | 231 | /* Exported empty data structures */ 232 | RABBITMQ_EXPORT const amqp_bytes_t amqp_empty_bytes; 233 | RABBITMQ_EXPORT const amqp_table_t amqp_empty_table; 234 | RABBITMQ_EXPORT const amqp_array_t amqp_empty_array; 235 | 236 | /* Compatibility macros for the above, to avoid the need to update 237 | code written against earlier versions of librabbitmq. */ 238 | #define AMQP_EMPTY_BYTES amqp_empty_bytes 239 | #define AMQP_EMPTY_TABLE amqp_empty_table 240 | #define AMQP_EMPTY_ARRAY amqp_empty_array 241 | 242 | RABBITMQ_EXPORT void init_amqp_pool(amqp_pool_t *pool, size_t pagesize); 243 | RABBITMQ_EXPORT void recycle_amqp_pool(amqp_pool_t *pool); 244 | RABBITMQ_EXPORT void empty_amqp_pool(amqp_pool_t *pool); 245 | 246 | RABBITMQ_EXPORT void *amqp_pool_alloc(amqp_pool_t *pool, size_t amount); 247 | RABBITMQ_EXPORT void amqp_pool_alloc_bytes(amqp_pool_t *pool, 248 | size_t amount, amqp_bytes_t *output); 249 | 250 | RABBITMQ_EXPORT amqp_bytes_t amqp_cstring_bytes(char const *cstr); 251 | RABBITMQ_EXPORT amqp_bytes_t amqp_bytes_malloc_dup(amqp_bytes_t src); 252 | RABBITMQ_EXPORT amqp_bytes_t amqp_bytes_malloc(size_t amount); 253 | RABBITMQ_EXPORT void amqp_bytes_free(amqp_bytes_t bytes); 254 | 255 | RABBITMQ_EXPORT amqp_connection_state_t amqp_new_connection(void); 256 | RABBITMQ_EXPORT int amqp_get_sockfd(amqp_connection_state_t state); 257 | RABBITMQ_EXPORT void amqp_set_sockfd(amqp_connection_state_t state, 258 | int sockfd); 259 | RABBITMQ_EXPORT int amqp_tune_connection(amqp_connection_state_t state, 260 | int channel_max, 261 | int frame_max, 262 | int heartbeat); 263 | RABBITMQ_EXPORT int amqp_get_channel_max(amqp_connection_state_t state); 264 | RABBITMQ_EXPORT int amqp_destroy_connection(amqp_connection_state_t state); 265 | 266 | RABBITMQ_EXPORT int amqp_handle_input(amqp_connection_state_t state, 267 | amqp_bytes_t received_data, 268 | amqp_frame_t *decoded_frame); 269 | 270 | RABBITMQ_EXPORT amqp_boolean_t amqp_release_buffers_ok( 271 | amqp_connection_state_t state); 272 | 273 | RABBITMQ_EXPORT void amqp_release_buffers(amqp_connection_state_t state); 274 | 275 | RABBITMQ_EXPORT void amqp_maybe_release_buffers(amqp_connection_state_t state); 276 | 277 | RABBITMQ_EXPORT int amqp_send_frame(amqp_connection_state_t state, 278 | amqp_frame_t const *frame); 279 | 280 | RABBITMQ_EXPORT int amqp_table_entry_cmp(void const *entry1, 281 | void const *entry2); 282 | 283 | RABBITMQ_EXPORT int amqp_open_socket(char const *hostname, 284 | int portnumber); 285 | 286 | RABBITMQ_EXPORT int amqp_send_header(amqp_connection_state_t state); 287 | 288 | RABBITMQ_EXPORT amqp_boolean_t amqp_frames_enqueued( 289 | amqp_connection_state_t state); 290 | 291 | RABBITMQ_EXPORT int amqp_simple_wait_frame(amqp_connection_state_t state, 292 | amqp_frame_t *decoded_frame); 293 | 294 | RABBITMQ_EXPORT int amqp_simple_wait_method(amqp_connection_state_t state, 295 | amqp_channel_t expected_channel, 296 | amqp_method_number_t expected_method, 297 | amqp_method_t *output); 298 | 299 | RABBITMQ_EXPORT int amqp_send_method(amqp_connection_state_t state, 300 | amqp_channel_t channel, 301 | amqp_method_number_t id, 302 | void *decoded); 303 | 304 | RABBITMQ_EXPORT amqp_rpc_reply_t amqp_simple_rpc(amqp_connection_state_t state, 305 | amqp_channel_t channel, 306 | amqp_method_number_t request_id, 307 | amqp_method_number_t *expected_reply_ids, 308 | void *decoded_request_method); 309 | 310 | RABBITMQ_EXPORT void *amqp_simple_rpc_decoded(amqp_connection_state_t state, 311 | amqp_channel_t channel, 312 | amqp_method_number_t request_id, 313 | amqp_method_number_t reply_id, 314 | void *decoded_request_method); 315 | 316 | /* 317 | * The API methods corresponding to most synchronous AMQP methods 318 | * return a pointer to the decoded method result. Upon error, they 319 | * return NULL, and we need some way of discovering what, if anything, 320 | * went wrong. amqp_get_rpc_reply() returns the most recent 321 | * amqp_rpc_reply_t instance corresponding to such an API operation 322 | * for the given connection. 323 | * 324 | * Only use it for operations that do not themselves return 325 | * amqp_rpc_reply_t; operations that do return amqp_rpc_reply_t 326 | * generally do NOT update this per-connection-global amqp_rpc_reply_t 327 | * instance. 328 | */ 329 | RABBITMQ_EXPORT amqp_rpc_reply_t amqp_get_rpc_reply( 330 | amqp_connection_state_t state); 331 | 332 | RABBITMQ_EXPORT amqp_rpc_reply_t amqp_login(amqp_connection_state_t state, 333 | char const *vhost, 334 | int channel_max, 335 | int frame_max, 336 | int heartbeat, 337 | amqp_sasl_method_enum sasl_method, ...); 338 | 339 | struct amqp_basic_properties_t_; 340 | RABBITMQ_EXPORT int amqp_basic_publish(amqp_connection_state_t state, 341 | amqp_channel_t channel, 342 | amqp_bytes_t exchange, 343 | amqp_bytes_t routing_key, 344 | amqp_boolean_t mandatory, 345 | amqp_boolean_t immediate, 346 | struct amqp_basic_properties_t_ const *properties, 347 | amqp_bytes_t body); 348 | 349 | RABBITMQ_EXPORT amqp_rpc_reply_t amqp_channel_close( 350 | amqp_connection_state_t state, 351 | amqp_channel_t channel, 352 | int code); 353 | RABBITMQ_EXPORT amqp_rpc_reply_t amqp_connection_close( 354 | amqp_connection_state_t state, 355 | int code); 356 | 357 | RABBITMQ_EXPORT int amqp_basic_ack(amqp_connection_state_t state, 358 | amqp_channel_t channel, 359 | uint64_t delivery_tag, 360 | amqp_boolean_t multiple); 361 | 362 | RABBITMQ_EXPORT amqp_rpc_reply_t amqp_basic_get(amqp_connection_state_t state, 363 | amqp_channel_t channel, 364 | amqp_bytes_t queue, 365 | amqp_boolean_t no_ack); 366 | 367 | RABBITMQ_EXPORT int amqp_basic_reject(amqp_connection_state_t state, 368 | amqp_channel_t channel, 369 | uint64_t delivery_tag, 370 | amqp_boolean_t requeue); 371 | 372 | /* 373 | * Can be used to see if there is data still in the buffer, if so 374 | * calling amqp_simple_wait_frame will not immediately enter a 375 | * blocking read. 376 | * 377 | * Possibly amqp_frames_enqueued should be used for this? 378 | */ 379 | RABBITMQ_EXPORT amqp_boolean_t amqp_data_in_buffer( 380 | amqp_connection_state_t state); 381 | 382 | /* 383 | * Get the error string for the given error code. 384 | * 385 | * The returned string resides on the heap; the caller is responsible 386 | * for freeing it. 387 | */ 388 | RABBITMQ_EXPORT char *amqp_error_string(int err); 389 | 390 | RABBITMQ_EXPORT int amqp_decode_table(amqp_bytes_t encoded, 391 | amqp_pool_t *pool, 392 | amqp_table_t *output, 393 | size_t *offset); 394 | 395 | RABBITMQ_EXPORT int amqp_encode_table(amqp_bytes_t encoded, 396 | amqp_table_t *input, 397 | size_t *offset); 398 | 399 | struct amqp_connection_info { 400 | char *user; 401 | char *password; 402 | char *host; 403 | char *vhost; 404 | int port; 405 | }; 406 | 407 | RABBITMQ_EXPORT void amqp_default_connection_info( 408 | struct amqp_connection_info *parsed); 409 | RABBITMQ_EXPORT int amqp_parse_url(char *url, 410 | struct amqp_connection_info *parsed); 411 | 412 | #ifdef __cplusplus 413 | } 414 | #endif 415 | 416 | #endif 417 | -------------------------------------------------------------------------------- /amqp_framing.h: -------------------------------------------------------------------------------- 1 | /* Autogenerated code. Do not edit. */ 2 | #ifndef librabbitmq_amqp_framing_h 3 | #define librabbitmq_amqp_framing_h 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | #define AMQP_PROTOCOL_VERSION_MAJOR 0 10 | #define AMQP_PROTOCOL_VERSION_MINOR 9 11 | #define AMQP_PROTOCOL_VERSION_REVISION 1 12 | #define AMQP_PROTOCOL_PORT 5672 13 | #define AMQP_FRAME_METHOD 1 14 | #define AMQP_FRAME_HEADER 2 15 | #define AMQP_FRAME_BODY 3 16 | #define AMQP_FRAME_HEARTBEAT 8 17 | #define AMQP_FRAME_MIN_SIZE 4096 18 | #define AMQP_FRAME_END 206 19 | #define AMQP_REPLY_SUCCESS 200 20 | #define AMQP_CONTENT_TOO_LARGE 311 21 | #define AMQP_NO_ROUTE 312 22 | #define AMQP_NO_CONSUMERS 313 23 | #define AMQP_ACCESS_REFUSED 403 24 | #define AMQP_NOT_FOUND 404 25 | #define AMQP_RESOURCE_LOCKED 405 26 | #define AMQP_PRECONDITION_FAILED 406 27 | #define AMQP_CONNECTION_FORCED 320 28 | #define AMQP_INVALID_PATH 402 29 | #define AMQP_FRAME_ERROR 501 30 | #define AMQP_SYNTAX_ERROR 502 31 | #define AMQP_COMMAND_INVALID 503 32 | #define AMQP_CHANNEL_ERROR 504 33 | #define AMQP_UNEXPECTED_FRAME 505 34 | #define AMQP_RESOURCE_ERROR 506 35 | #define AMQP_NOT_ALLOWED 530 36 | #define AMQP_NOT_IMPLEMENTED 540 37 | #define AMQP_INTERNAL_ERROR 541 38 | 39 | /* Function prototypes. */ 40 | 41 | extern char const *amqp_constant_name(int constantNumber); 42 | extern amqp_boolean_t amqp_constant_is_hard_error(int constantNumber); 43 | RABBITMQ_EXPORT char const *amqp_method_name(amqp_method_number_t methodNumber); 44 | extern amqp_boolean_t amqp_method_has_content(amqp_method_number_t methodNumber); 45 | extern int amqp_decode_method(amqp_method_number_t methodNumber, 46 | amqp_pool_t *pool, 47 | amqp_bytes_t encoded, 48 | void **decoded); 49 | extern int amqp_decode_properties(uint16_t class_id, 50 | amqp_pool_t *pool, 51 | amqp_bytes_t encoded, 52 | void **decoded); 53 | extern int amqp_encode_method(amqp_method_number_t methodNumber, 54 | void *decoded, 55 | amqp_bytes_t encoded); 56 | extern int amqp_encode_properties(uint16_t class_id, 57 | void *decoded, 58 | amqp_bytes_t encoded); 59 | 60 | /* Method field records. */ 61 | 62 | #define AMQP_CONNECTION_START_METHOD ((amqp_method_number_t) 0x000A000A) /* 10, 10; 655370 */ 63 | typedef struct amqp_connection_start_t_ { 64 | uint8_t version_major; 65 | uint8_t version_minor; 66 | amqp_table_t server_properties; 67 | amqp_bytes_t mechanisms; 68 | amqp_bytes_t locales; 69 | } amqp_connection_start_t; 70 | 71 | #define AMQP_CONNECTION_START_OK_METHOD ((amqp_method_number_t) 0x000A000B) /* 10, 11; 655371 */ 72 | typedef struct amqp_connection_start_ok_t_ { 73 | amqp_table_t client_properties; 74 | amqp_bytes_t mechanism; 75 | amqp_bytes_t response; 76 | amqp_bytes_t locale; 77 | } amqp_connection_start_ok_t; 78 | 79 | #define AMQP_CONNECTION_SECURE_METHOD ((amqp_method_number_t) 0x000A0014) /* 10, 20; 655380 */ 80 | typedef struct amqp_connection_secure_t_ { 81 | amqp_bytes_t challenge; 82 | } amqp_connection_secure_t; 83 | 84 | #define AMQP_CONNECTION_SECURE_OK_METHOD ((amqp_method_number_t) 0x000A0015) /* 10, 21; 655381 */ 85 | typedef struct amqp_connection_secure_ok_t_ { 86 | amqp_bytes_t response; 87 | } amqp_connection_secure_ok_t; 88 | 89 | #define AMQP_CONNECTION_TUNE_METHOD ((amqp_method_number_t) 0x000A001E) /* 10, 30; 655390 */ 90 | typedef struct amqp_connection_tune_t_ { 91 | uint16_t channel_max; 92 | uint32_t frame_max; 93 | uint16_t heartbeat; 94 | } amqp_connection_tune_t; 95 | 96 | #define AMQP_CONNECTION_TUNE_OK_METHOD ((amqp_method_number_t) 0x000A001F) /* 10, 31; 655391 */ 97 | typedef struct amqp_connection_tune_ok_t_ { 98 | uint16_t channel_max; 99 | uint32_t frame_max; 100 | uint16_t heartbeat; 101 | } amqp_connection_tune_ok_t; 102 | 103 | #define AMQP_CONNECTION_OPEN_METHOD ((amqp_method_number_t) 0x000A0028) /* 10, 40; 655400 */ 104 | typedef struct amqp_connection_open_t_ { 105 | amqp_bytes_t virtual_host; 106 | amqp_bytes_t capabilities; 107 | amqp_boolean_t insist; 108 | } amqp_connection_open_t; 109 | 110 | #define AMQP_CONNECTION_OPEN_OK_METHOD ((amqp_method_number_t) 0x000A0029) /* 10, 41; 655401 */ 111 | typedef struct amqp_connection_open_ok_t_ { 112 | amqp_bytes_t known_hosts; 113 | } amqp_connection_open_ok_t; 114 | 115 | #define AMQP_CONNECTION_CLOSE_METHOD ((amqp_method_number_t) 0x000A0032) /* 10, 50; 655410 */ 116 | typedef struct amqp_connection_close_t_ { 117 | uint16_t reply_code; 118 | amqp_bytes_t reply_text; 119 | uint16_t class_id; 120 | uint16_t method_id; 121 | } amqp_connection_close_t; 122 | 123 | #define AMQP_CONNECTION_CLOSE_OK_METHOD ((amqp_method_number_t) 0x000A0033) /* 10, 51; 655411 */ 124 | typedef struct amqp_connection_close_ok_t_ { 125 | char dummy; /* Dummy field to avoid empty struct */ 126 | } amqp_connection_close_ok_t; 127 | 128 | #define AMQP_CHANNEL_OPEN_METHOD ((amqp_method_number_t) 0x0014000A) /* 20, 10; 1310730 */ 129 | typedef struct amqp_channel_open_t_ { 130 | amqp_bytes_t out_of_band; 131 | } amqp_channel_open_t; 132 | 133 | #define AMQP_CHANNEL_OPEN_OK_METHOD ((amqp_method_number_t) 0x0014000B) /* 20, 11; 1310731 */ 134 | typedef struct amqp_channel_open_ok_t_ { 135 | amqp_bytes_t channel_id; 136 | } amqp_channel_open_ok_t; 137 | 138 | #define AMQP_CHANNEL_FLOW_METHOD ((amqp_method_number_t) 0x00140014) /* 20, 20; 1310740 */ 139 | typedef struct amqp_channel_flow_t_ { 140 | amqp_boolean_t active; 141 | } amqp_channel_flow_t; 142 | 143 | #define AMQP_CHANNEL_FLOW_OK_METHOD ((amqp_method_number_t) 0x00140015) /* 20, 21; 1310741 */ 144 | typedef struct amqp_channel_flow_ok_t_ { 145 | amqp_boolean_t active; 146 | } amqp_channel_flow_ok_t; 147 | 148 | #define AMQP_CHANNEL_CLOSE_METHOD ((amqp_method_number_t) 0x00140028) /* 20, 40; 1310760 */ 149 | typedef struct amqp_channel_close_t_ { 150 | uint16_t reply_code; 151 | amqp_bytes_t reply_text; 152 | uint16_t class_id; 153 | uint16_t method_id; 154 | } amqp_channel_close_t; 155 | 156 | #define AMQP_CHANNEL_CLOSE_OK_METHOD ((amqp_method_number_t) 0x00140029) /* 20, 41; 1310761 */ 157 | typedef struct amqp_channel_close_ok_t_ { 158 | char dummy; /* Dummy field to avoid empty struct */ 159 | } amqp_channel_close_ok_t; 160 | 161 | #define AMQP_ACCESS_REQUEST_METHOD ((amqp_method_number_t) 0x001E000A) /* 30, 10; 1966090 */ 162 | typedef struct amqp_access_request_t_ { 163 | amqp_bytes_t realm; 164 | amqp_boolean_t exclusive; 165 | amqp_boolean_t passive; 166 | amqp_boolean_t active; 167 | amqp_boolean_t write; 168 | amqp_boolean_t read; 169 | } amqp_access_request_t; 170 | 171 | #define AMQP_ACCESS_REQUEST_OK_METHOD ((amqp_method_number_t) 0x001E000B) /* 30, 11; 1966091 */ 172 | typedef struct amqp_access_request_ok_t_ { 173 | uint16_t ticket; 174 | } amqp_access_request_ok_t; 175 | 176 | #define AMQP_EXCHANGE_DECLARE_METHOD ((amqp_method_number_t) 0x0028000A) /* 40, 10; 2621450 */ 177 | typedef struct amqp_exchange_declare_t_ { 178 | uint16_t ticket; 179 | amqp_bytes_t exchange; 180 | amqp_bytes_t type; 181 | amqp_boolean_t passive; 182 | amqp_boolean_t durable; 183 | amqp_boolean_t auto_delete; 184 | amqp_boolean_t internal; 185 | amqp_boolean_t nowait; 186 | amqp_table_t arguments; 187 | } amqp_exchange_declare_t; 188 | 189 | #define AMQP_EXCHANGE_DECLARE_OK_METHOD ((amqp_method_number_t) 0x0028000B) /* 40, 11; 2621451 */ 190 | typedef struct amqp_exchange_declare_ok_t_ { 191 | char dummy; /* Dummy field to avoid empty struct */ 192 | } amqp_exchange_declare_ok_t; 193 | 194 | #define AMQP_EXCHANGE_DELETE_METHOD ((amqp_method_number_t) 0x00280014) /* 40, 20; 2621460 */ 195 | typedef struct amqp_exchange_delete_t_ { 196 | uint16_t ticket; 197 | amqp_bytes_t exchange; 198 | amqp_boolean_t if_unused; 199 | amqp_boolean_t nowait; 200 | } amqp_exchange_delete_t; 201 | 202 | #define AMQP_EXCHANGE_DELETE_OK_METHOD ((amqp_method_number_t) 0x00280015) /* 40, 21; 2621461 */ 203 | typedef struct amqp_exchange_delete_ok_t_ { 204 | char dummy; /* Dummy field to avoid empty struct */ 205 | } amqp_exchange_delete_ok_t; 206 | 207 | #define AMQP_EXCHANGE_BIND_METHOD ((amqp_method_number_t) 0x0028001E) /* 40, 30; 2621470 */ 208 | typedef struct amqp_exchange_bind_t_ { 209 | uint16_t ticket; 210 | amqp_bytes_t destination; 211 | amqp_bytes_t source; 212 | amqp_bytes_t routing_key; 213 | amqp_boolean_t nowait; 214 | amqp_table_t arguments; 215 | } amqp_exchange_bind_t; 216 | 217 | #define AMQP_EXCHANGE_BIND_OK_METHOD ((amqp_method_number_t) 0x0028001F) /* 40, 31; 2621471 */ 218 | typedef struct amqp_exchange_bind_ok_t_ { 219 | char dummy; /* Dummy field to avoid empty struct */ 220 | } amqp_exchange_bind_ok_t; 221 | 222 | #define AMQP_EXCHANGE_UNBIND_METHOD ((amqp_method_number_t) 0x00280028) /* 40, 40; 2621480 */ 223 | typedef struct amqp_exchange_unbind_t_ { 224 | uint16_t ticket; 225 | amqp_bytes_t destination; 226 | amqp_bytes_t source; 227 | amqp_bytes_t routing_key; 228 | amqp_boolean_t nowait; 229 | amqp_table_t arguments; 230 | } amqp_exchange_unbind_t; 231 | 232 | #define AMQP_EXCHANGE_UNBIND_OK_METHOD ((amqp_method_number_t) 0x00280033) /* 40, 51; 2621491 */ 233 | typedef struct amqp_exchange_unbind_ok_t_ { 234 | char dummy; /* Dummy field to avoid empty struct */ 235 | } amqp_exchange_unbind_ok_t; 236 | 237 | #define AMQP_QUEUE_DECLARE_METHOD ((amqp_method_number_t) 0x0032000A) /* 50, 10; 3276810 */ 238 | typedef struct amqp_queue_declare_t_ { 239 | uint16_t ticket; 240 | amqp_bytes_t queue; 241 | amqp_boolean_t passive; 242 | amqp_boolean_t durable; 243 | amqp_boolean_t exclusive; 244 | amqp_boolean_t auto_delete; 245 | amqp_boolean_t nowait; 246 | amqp_table_t arguments; 247 | } amqp_queue_declare_t; 248 | 249 | #define AMQP_QUEUE_DECLARE_OK_METHOD ((amqp_method_number_t) 0x0032000B) /* 50, 11; 3276811 */ 250 | typedef struct amqp_queue_declare_ok_t_ { 251 | amqp_bytes_t queue; 252 | uint32_t message_count; 253 | uint32_t consumer_count; 254 | } amqp_queue_declare_ok_t; 255 | 256 | #define AMQP_QUEUE_BIND_METHOD ((amqp_method_number_t) 0x00320014) /* 50, 20; 3276820 */ 257 | typedef struct amqp_queue_bind_t_ { 258 | uint16_t ticket; 259 | amqp_bytes_t queue; 260 | amqp_bytes_t exchange; 261 | amqp_bytes_t routing_key; 262 | amqp_boolean_t nowait; 263 | amqp_table_t arguments; 264 | } amqp_queue_bind_t; 265 | 266 | #define AMQP_QUEUE_BIND_OK_METHOD ((amqp_method_number_t) 0x00320015) /* 50, 21; 3276821 */ 267 | typedef struct amqp_queue_bind_ok_t_ { 268 | char dummy; /* Dummy field to avoid empty struct */ 269 | } amqp_queue_bind_ok_t; 270 | 271 | #define AMQP_QUEUE_PURGE_METHOD ((amqp_method_number_t) 0x0032001E) /* 50, 30; 3276830 */ 272 | typedef struct amqp_queue_purge_t_ { 273 | uint16_t ticket; 274 | amqp_bytes_t queue; 275 | amqp_boolean_t nowait; 276 | } amqp_queue_purge_t; 277 | 278 | #define AMQP_QUEUE_PURGE_OK_METHOD ((amqp_method_number_t) 0x0032001F) /* 50, 31; 3276831 */ 279 | typedef struct amqp_queue_purge_ok_t_ { 280 | uint32_t message_count; 281 | } amqp_queue_purge_ok_t; 282 | 283 | #define AMQP_QUEUE_DELETE_METHOD ((amqp_method_number_t) 0x00320028) /* 50, 40; 3276840 */ 284 | typedef struct amqp_queue_delete_t_ { 285 | uint16_t ticket; 286 | amqp_bytes_t queue; 287 | amqp_boolean_t if_unused; 288 | amqp_boolean_t if_empty; 289 | amqp_boolean_t nowait; 290 | } amqp_queue_delete_t; 291 | 292 | #define AMQP_QUEUE_DELETE_OK_METHOD ((amqp_method_number_t) 0x00320029) /* 50, 41; 3276841 */ 293 | typedef struct amqp_queue_delete_ok_t_ { 294 | uint32_t message_count; 295 | } amqp_queue_delete_ok_t; 296 | 297 | #define AMQP_QUEUE_UNBIND_METHOD ((amqp_method_number_t) 0x00320032) /* 50, 50; 3276850 */ 298 | typedef struct amqp_queue_unbind_t_ { 299 | uint16_t ticket; 300 | amqp_bytes_t queue; 301 | amqp_bytes_t exchange; 302 | amqp_bytes_t routing_key; 303 | amqp_table_t arguments; 304 | } amqp_queue_unbind_t; 305 | 306 | #define AMQP_QUEUE_UNBIND_OK_METHOD ((amqp_method_number_t) 0x00320033) /* 50, 51; 3276851 */ 307 | typedef struct amqp_queue_unbind_ok_t_ { 308 | char dummy; /* Dummy field to avoid empty struct */ 309 | } amqp_queue_unbind_ok_t; 310 | 311 | #define AMQP_BASIC_QOS_METHOD ((amqp_method_number_t) 0x003C000A) /* 60, 10; 3932170 */ 312 | typedef struct amqp_basic_qos_t_ { 313 | uint32_t prefetch_size; 314 | uint16_t prefetch_count; 315 | amqp_boolean_t global; 316 | } amqp_basic_qos_t; 317 | 318 | #define AMQP_BASIC_QOS_OK_METHOD ((amqp_method_number_t) 0x003C000B) /* 60, 11; 3932171 */ 319 | typedef struct amqp_basic_qos_ok_t_ { 320 | char dummy; /* Dummy field to avoid empty struct */ 321 | } amqp_basic_qos_ok_t; 322 | 323 | #define AMQP_BASIC_CONSUME_METHOD ((amqp_method_number_t) 0x003C0014) /* 60, 20; 3932180 */ 324 | typedef struct amqp_basic_consume_t_ { 325 | uint16_t ticket; 326 | amqp_bytes_t queue; 327 | amqp_bytes_t consumer_tag; 328 | amqp_boolean_t no_local; 329 | amqp_boolean_t no_ack; 330 | amqp_boolean_t exclusive; 331 | amqp_boolean_t nowait; 332 | amqp_table_t arguments; 333 | } amqp_basic_consume_t; 334 | 335 | #define AMQP_BASIC_CONSUME_OK_METHOD ((amqp_method_number_t) 0x003C0015) /* 60, 21; 3932181 */ 336 | typedef struct amqp_basic_consume_ok_t_ { 337 | amqp_bytes_t consumer_tag; 338 | } amqp_basic_consume_ok_t; 339 | 340 | #define AMQP_BASIC_CANCEL_METHOD ((amqp_method_number_t) 0x003C001E) /* 60, 30; 3932190 */ 341 | typedef struct amqp_basic_cancel_t_ { 342 | amqp_bytes_t consumer_tag; 343 | amqp_boolean_t nowait; 344 | } amqp_basic_cancel_t; 345 | 346 | #define AMQP_BASIC_CANCEL_OK_METHOD ((amqp_method_number_t) 0x003C001F) /* 60, 31; 3932191 */ 347 | typedef struct amqp_basic_cancel_ok_t_ { 348 | amqp_bytes_t consumer_tag; 349 | } amqp_basic_cancel_ok_t; 350 | 351 | #define AMQP_BASIC_PUBLISH_METHOD ((amqp_method_number_t) 0x003C0028) /* 60, 40; 3932200 */ 352 | typedef struct amqp_basic_publish_t_ { 353 | uint16_t ticket; 354 | amqp_bytes_t exchange; 355 | amqp_bytes_t routing_key; 356 | amqp_boolean_t mandatory; 357 | amqp_boolean_t immediate; 358 | } amqp_basic_publish_t; 359 | 360 | #define AMQP_BASIC_RETURN_METHOD ((amqp_method_number_t) 0x003C0032) /* 60, 50; 3932210 */ 361 | typedef struct amqp_basic_return_t_ { 362 | uint16_t reply_code; 363 | amqp_bytes_t reply_text; 364 | amqp_bytes_t exchange; 365 | amqp_bytes_t routing_key; 366 | } amqp_basic_return_t; 367 | 368 | #define AMQP_BASIC_DELIVER_METHOD ((amqp_method_number_t) 0x003C003C) /* 60, 60; 3932220 */ 369 | typedef struct amqp_basic_deliver_t_ { 370 | amqp_bytes_t consumer_tag; 371 | uint64_t delivery_tag; 372 | amqp_boolean_t redelivered; 373 | amqp_bytes_t exchange; 374 | amqp_bytes_t routing_key; 375 | } amqp_basic_deliver_t; 376 | 377 | #define AMQP_BASIC_GET_METHOD ((amqp_method_number_t) 0x003C0046) /* 60, 70; 3932230 */ 378 | typedef struct amqp_basic_get_t_ { 379 | uint16_t ticket; 380 | amqp_bytes_t queue; 381 | amqp_boolean_t no_ack; 382 | } amqp_basic_get_t; 383 | 384 | #define AMQP_BASIC_GET_OK_METHOD ((amqp_method_number_t) 0x003C0047) /* 60, 71; 3932231 */ 385 | typedef struct amqp_basic_get_ok_t_ { 386 | uint64_t delivery_tag; 387 | amqp_boolean_t redelivered; 388 | amqp_bytes_t exchange; 389 | amqp_bytes_t routing_key; 390 | uint32_t message_count; 391 | } amqp_basic_get_ok_t; 392 | 393 | #define AMQP_BASIC_GET_EMPTY_METHOD ((amqp_method_number_t) 0x003C0048) /* 60, 72; 3932232 */ 394 | typedef struct amqp_basic_get_empty_t_ { 395 | amqp_bytes_t cluster_id; 396 | } amqp_basic_get_empty_t; 397 | 398 | #define AMQP_BASIC_ACK_METHOD ((amqp_method_number_t) 0x003C0050) /* 60, 80; 3932240 */ 399 | typedef struct amqp_basic_ack_t_ { 400 | uint64_t delivery_tag; 401 | amqp_boolean_t multiple; 402 | } amqp_basic_ack_t; 403 | 404 | #define AMQP_BASIC_REJECT_METHOD ((amqp_method_number_t) 0x003C005A) /* 60, 90; 3932250 */ 405 | typedef struct amqp_basic_reject_t_ { 406 | uint64_t delivery_tag; 407 | amqp_boolean_t requeue; 408 | } amqp_basic_reject_t; 409 | 410 | #define AMQP_BASIC_RECOVER_ASYNC_METHOD ((amqp_method_number_t) 0x003C0064) /* 60, 100; 3932260 */ 411 | typedef struct amqp_basic_recover_async_t_ { 412 | amqp_boolean_t requeue; 413 | } amqp_basic_recover_async_t; 414 | 415 | #define AMQP_BASIC_RECOVER_METHOD ((amqp_method_number_t) 0x003C006E) /* 60, 110; 3932270 */ 416 | typedef struct amqp_basic_recover_t_ { 417 | amqp_boolean_t requeue; 418 | } amqp_basic_recover_t; 419 | 420 | #define AMQP_BASIC_RECOVER_OK_METHOD ((amqp_method_number_t) 0x003C006F) /* 60, 111; 3932271 */ 421 | typedef struct amqp_basic_recover_ok_t_ { 422 | char dummy; /* Dummy field to avoid empty struct */ 423 | } amqp_basic_recover_ok_t; 424 | 425 | #define AMQP_BASIC_NACK_METHOD ((amqp_method_number_t) 0x003C0078) /* 60, 120; 3932280 */ 426 | typedef struct amqp_basic_nack_t_ { 427 | uint64_t delivery_tag; 428 | amqp_boolean_t multiple; 429 | amqp_boolean_t requeue; 430 | } amqp_basic_nack_t; 431 | 432 | #define AMQP_TX_SELECT_METHOD ((amqp_method_number_t) 0x005A000A) /* 90, 10; 5898250 */ 433 | typedef struct amqp_tx_select_t_ { 434 | char dummy; /* Dummy field to avoid empty struct */ 435 | } amqp_tx_select_t; 436 | 437 | #define AMQP_TX_SELECT_OK_METHOD ((amqp_method_number_t) 0x005A000B) /* 90, 11; 5898251 */ 438 | typedef struct amqp_tx_select_ok_t_ { 439 | char dummy; /* Dummy field to avoid empty struct */ 440 | } amqp_tx_select_ok_t; 441 | 442 | #define AMQP_TX_COMMIT_METHOD ((amqp_method_number_t) 0x005A0014) /* 90, 20; 5898260 */ 443 | typedef struct amqp_tx_commit_t_ { 444 | char dummy; /* Dummy field to avoid empty struct */ 445 | } amqp_tx_commit_t; 446 | 447 | #define AMQP_TX_COMMIT_OK_METHOD ((amqp_method_number_t) 0x005A0015) /* 90, 21; 5898261 */ 448 | typedef struct amqp_tx_commit_ok_t_ { 449 | char dummy; /* Dummy field to avoid empty struct */ 450 | } amqp_tx_commit_ok_t; 451 | 452 | #define AMQP_TX_ROLLBACK_METHOD ((amqp_method_number_t) 0x005A001E) /* 90, 30; 5898270 */ 453 | typedef struct amqp_tx_rollback_t_ { 454 | char dummy; /* Dummy field to avoid empty struct */ 455 | } amqp_tx_rollback_t; 456 | 457 | #define AMQP_TX_ROLLBACK_OK_METHOD ((amqp_method_number_t) 0x005A001F) /* 90, 31; 5898271 */ 458 | typedef struct amqp_tx_rollback_ok_t_ { 459 | char dummy; /* Dummy field to avoid empty struct */ 460 | } amqp_tx_rollback_ok_t; 461 | 462 | #define AMQP_CONFIRM_SELECT_METHOD ((amqp_method_number_t) 0x0055000A) /* 85, 10; 5570570 */ 463 | typedef struct amqp_confirm_select_t_ { 464 | amqp_boolean_t nowait; 465 | } amqp_confirm_select_t; 466 | 467 | #define AMQP_CONFIRM_SELECT_OK_METHOD ((amqp_method_number_t) 0x0055000B) /* 85, 11; 5570571 */ 468 | typedef struct amqp_confirm_select_ok_t_ { 469 | char dummy; /* Dummy field to avoid empty struct */ 470 | } amqp_confirm_select_ok_t; 471 | 472 | /* Class property records. */ 473 | #define AMQP_CONNECTION_CLASS (0x000A) /* 10 */ 474 | typedef struct amqp_connection_properties_t_ { 475 | amqp_flags_t _flags; 476 | char dummy; /* Dummy field to avoid empty struct */ 477 | } amqp_connection_properties_t; 478 | 479 | #define AMQP_CHANNEL_CLASS (0x0014) /* 20 */ 480 | typedef struct amqp_channel_properties_t_ { 481 | amqp_flags_t _flags; 482 | char dummy; /* Dummy field to avoid empty struct */ 483 | } amqp_channel_properties_t; 484 | 485 | #define AMQP_ACCESS_CLASS (0x001E) /* 30 */ 486 | typedef struct amqp_access_properties_t_ { 487 | amqp_flags_t _flags; 488 | char dummy; /* Dummy field to avoid empty struct */ 489 | } amqp_access_properties_t; 490 | 491 | #define AMQP_EXCHANGE_CLASS (0x0028) /* 40 */ 492 | typedef struct amqp_exchange_properties_t_ { 493 | amqp_flags_t _flags; 494 | char dummy; /* Dummy field to avoid empty struct */ 495 | } amqp_exchange_properties_t; 496 | 497 | #define AMQP_QUEUE_CLASS (0x0032) /* 50 */ 498 | typedef struct amqp_queue_properties_t_ { 499 | amqp_flags_t _flags; 500 | char dummy; /* Dummy field to avoid empty struct */ 501 | } amqp_queue_properties_t; 502 | 503 | #define AMQP_BASIC_CLASS (0x003C) /* 60 */ 504 | #define AMQP_BASIC_CONTENT_TYPE_FLAG (1 << 15) 505 | #define AMQP_BASIC_CONTENT_ENCODING_FLAG (1 << 14) 506 | #define AMQP_BASIC_HEADERS_FLAG (1 << 13) 507 | #define AMQP_BASIC_DELIVERY_MODE_FLAG (1 << 12) 508 | #define AMQP_BASIC_PRIORITY_FLAG (1 << 11) 509 | #define AMQP_BASIC_CORRELATION_ID_FLAG (1 << 10) 510 | #define AMQP_BASIC_REPLY_TO_FLAG (1 << 9) 511 | #define AMQP_BASIC_EXPIRATION_FLAG (1 << 8) 512 | #define AMQP_BASIC_MESSAGE_ID_FLAG (1 << 7) 513 | #define AMQP_BASIC_TIMESTAMP_FLAG (1 << 6) 514 | #define AMQP_BASIC_TYPE_FLAG (1 << 5) 515 | #define AMQP_BASIC_USER_ID_FLAG (1 << 4) 516 | #define AMQP_BASIC_APP_ID_FLAG (1 << 3) 517 | #define AMQP_BASIC_CLUSTER_ID_FLAG (1 << 2) 518 | typedef struct amqp_basic_properties_t_ { 519 | amqp_flags_t _flags; 520 | amqp_bytes_t content_type; 521 | amqp_bytes_t content_encoding; 522 | amqp_table_t headers; 523 | uint8_t delivery_mode; 524 | uint8_t priority; 525 | amqp_bytes_t correlation_id; 526 | amqp_bytes_t reply_to; 527 | amqp_bytes_t expiration; 528 | amqp_bytes_t message_id; 529 | uint64_t timestamp; 530 | amqp_bytes_t type; 531 | amqp_bytes_t user_id; 532 | amqp_bytes_t app_id; 533 | amqp_bytes_t cluster_id; 534 | } amqp_basic_properties_t; 535 | 536 | #define AMQP_TX_CLASS (0x005A) /* 90 */ 537 | typedef struct amqp_tx_properties_t_ { 538 | amqp_flags_t _flags; 539 | char dummy; /* Dummy field to avoid empty struct */ 540 | } amqp_tx_properties_t; 541 | 542 | #define AMQP_CONFIRM_CLASS (0x0055) /* 85 */ 543 | typedef struct amqp_confirm_properties_t_ { 544 | amqp_flags_t _flags; 545 | char dummy; /* Dummy field to avoid empty struct */ 546 | } amqp_confirm_properties_t; 547 | 548 | /* API functions for methods */ 549 | 550 | RABBITMQ_EXPORT amqp_channel_open_ok_t *amqp_channel_open(amqp_connection_state_t state, amqp_channel_t channel); 551 | RABBITMQ_EXPORT amqp_channel_flow_ok_t *amqp_channel_flow(amqp_connection_state_t state, amqp_channel_t channel, amqp_boolean_t active); 552 | RABBITMQ_EXPORT 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); 553 | RABBITMQ_EXPORT 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); 554 | RABBITMQ_EXPORT 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); 555 | RABBITMQ_EXPORT 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); 556 | RABBITMQ_EXPORT 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); 557 | RABBITMQ_EXPORT 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); 558 | RABBITMQ_EXPORT amqp_queue_purge_ok_t *amqp_queue_purge(amqp_connection_state_t state, amqp_channel_t channel, amqp_bytes_t queue); 559 | RABBITMQ_EXPORT 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); 560 | RABBITMQ_EXPORT 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); 561 | RABBITMQ_EXPORT 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); 562 | RABBITMQ_EXPORT 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); 563 | RABBITMQ_EXPORT amqp_basic_cancel_ok_t *amqp_basic_cancel(amqp_connection_state_t state, amqp_channel_t channel, amqp_bytes_t consumer_tag); 564 | RABBITMQ_EXPORT amqp_basic_recover_ok_t *amqp_basic_recover(amqp_connection_state_t state, amqp_channel_t channel, amqp_boolean_t requeue); 565 | RABBITMQ_EXPORT amqp_tx_select_ok_t *amqp_tx_select(amqp_connection_state_t state, amqp_channel_t channel); 566 | RABBITMQ_EXPORT amqp_tx_commit_ok_t *amqp_tx_commit(amqp_connection_state_t state, amqp_channel_t channel); 567 | RABBITMQ_EXPORT amqp_tx_rollback_ok_t *amqp_tx_rollback(amqp_connection_state_t state, amqp_channel_t channel); 568 | RABBITMQ_EXPORT amqp_confirm_select_ok_t *amqp_confirm_select(amqp_connection_state_t state, amqp_channel_t channel); 569 | 570 | #ifdef __cplusplus 571 | } 572 | #endif 573 | 574 | #endif 575 | -------------------------------------------------------------------------------- /emit_log_direct: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuhaobupt/rabbitmq_work_queues_demo-with-rabbit-c-client-lib/f58d5d0b45d999dd93aa82887bcd7626cf988ea3/emit_log_direct -------------------------------------------------------------------------------- /emit_log_direct.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "utils.h" 9 | 10 | int main(int argc, const char **argv) { 11 | 12 | const char *hostname; 13 | int port; 14 | const char *exchange; 15 | const char *routingkey; 16 | const char *messagebody; 17 | const char *exchangetype = "direct"; 18 | 19 | if (argc < 6) { 20 | fprintf(stderr, "Usage: emit_log_direct host port exchange routingkey messagebody\n"); 21 | return 1; 22 | } 23 | 24 | hostname = argv[1]; 25 | port = atoi(argv[2]); 26 | exchange = argv[3]; 27 | routingkey = argv[4]; 28 | messagebody = argv[5]; 29 | 30 | int sockfd; 31 | int channelid = 1; 32 | amqp_connection_state_t conn; 33 | conn = amqp_new_connection(); 34 | 35 | die_on_error(sockfd = amqp_open_socket(hostname, port), "Opening socket"); 36 | amqp_set_sockfd(conn, sockfd); 37 | die_on_amqp_error(amqp_login(conn, "/", 0, 131072, 0, AMQP_SASL_METHOD_PLAIN, "guest", "guest"),"Logging in"); 38 | amqp_channel_open(conn, channelid); 39 | die_on_amqp_error(amqp_get_rpc_reply(conn), "Opening channel"); 40 | 41 | amqp_exchange_declare(conn,channelid,amqp_cstring_bytes(exchange),amqp_cstring_bytes(exchangetype),0,1, 42 | amqp_empty_table); 43 | die_on_amqp_error(amqp_get_rpc_reply(conn),"Declaring exchange"); 44 | 45 | { 46 | amqp_basic_properties_t props; 47 | props._flags = AMQP_BASIC_DELIVERY_MODE_FLAG; 48 | /*props.content_type = amqp_cstring_bytes("text/plain");*/ 49 | props.delivery_mode = 2; /* persistent delivery mode */ 50 | die_on_error(amqp_basic_publish(conn, 51 | channelid, 52 | amqp_cstring_bytes(exchange), 53 | amqp_cstring_bytes(routingkey), 54 | 0, 55 | 0, 56 | &props, 57 | amqp_cstring_bytes(messagebody)), 58 | "Publishing"); 59 | } 60 | 61 | die_on_amqp_error(amqp_channel_close(conn, 1, AMQP_REPLY_SUCCESS), "Closing channel"); 62 | die_on_amqp_error(amqp_connection_close(conn, AMQP_REPLY_SUCCESS), "Closing connection"); 63 | die_on_error(amqp_destroy_connection(conn), "Ending connection"); 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /librabbitmq.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuhaobupt/rabbitmq_work_queues_demo-with-rabbit-c-client-lib/f58d5d0b45d999dd93aa82887bcd7626cf988ea3/librabbitmq.a -------------------------------------------------------------------------------- /receive_logs_direct: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuhaobupt/rabbitmq_work_queues_demo-with-rabbit-c-client-lib/f58d5d0b45d999dd93aa82887bcd7626cf988ea3/receive_logs_direct -------------------------------------------------------------------------------- /receive_logs_direct.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | #include "utils.h" 12 | 13 | int main(int argc, const char **argv) { 14 | 15 | const char *hostname; 16 | int port; 17 | const char *exchange; 18 | const char *routingkey; 19 | const char *exchangetype = "direct"; 20 | 21 | if (argc < 5) { 22 | fprintf(stderr, "Usage: receive_logs_direct host port exchange routingkeys...\n"); 23 | return 1; 24 | } 25 | 26 | hostname = argv[1]; 27 | port = atoi(argv[2]); 28 | exchange = argv[3]; 29 | 30 | int sockfd; 31 | int channelid = 1; 32 | amqp_connection_state_t conn; 33 | conn = amqp_new_connection(); 34 | 35 | die_on_error(sockfd = amqp_open_socket(hostname, port), "Opening socket"); 36 | amqp_set_sockfd(conn, sockfd); 37 | die_on_amqp_error(amqp_login(conn, "/", 0, 131072, 0, AMQP_SASL_METHOD_PLAIN, "guest", "guest"),"Logging in"); 38 | amqp_channel_open(conn, channelid); 39 | die_on_amqp_error(amqp_get_rpc_reply(conn), "Opening channel"); 40 | 41 | amqp_exchange_declare(conn,channelid,amqp_cstring_bytes(exchange),amqp_cstring_bytes(exchangetype),0,1, 42 | amqp_empty_table); 43 | die_on_amqp_error(amqp_get_rpc_reply(conn),"Declaring exchange"); 44 | 45 | amqp_queue_declare_ok_t *r = amqp_queue_declare(conn,channelid,amqp_empty_bytes,0,0,1,0,amqp_empty_table); 46 | 47 | int i; 48 | for(i = 4;i < argc;i++) 49 | { 50 | routingkey = argv[i]; 51 | amqp_queue_bind(conn,channelid,amqp_bytes_malloc_dup(r->queue),amqp_cstring_bytes(exchange), 52 | amqp_cstring_bytes(routingkey),amqp_empty_table); 53 | } 54 | 55 | amqp_basic_qos(conn,channelid,0,1,0); 56 | amqp_basic_consume(conn,channelid,amqp_bytes_malloc_dup(r->queue),amqp_empty_bytes,0,0,0,amqp_empty_table); 57 | die_on_amqp_error(amqp_get_rpc_reply(conn), "Consuming"); 58 | 59 | { 60 | amqp_frame_t frame; 61 | int result; 62 | amqp_basic_deliver_t *d; 63 | amqp_basic_properties_t *p; 64 | size_t body_target; 65 | size_t body_received; 66 | 67 | while (1) { 68 | amqp_maybe_release_buffers(conn); 69 | result = amqp_simple_wait_frame(conn, &frame); 70 | printf("Result %d\n", result); 71 | if (result < 0) 72 | break; 73 | 74 | printf("Frame type %d, channel %d\n", frame.frame_type, frame.channel); 75 | if (frame.frame_type != AMQP_FRAME_METHOD) 76 | continue; 77 | 78 | printf("Method %s\n", amqp_method_name(frame.payload.method.id)); 79 | if (frame.payload.method.id != AMQP_BASIC_DELIVER_METHOD) 80 | continue; 81 | 82 | d = (amqp_basic_deliver_t *) frame.payload.method.decoded; 83 | printf("Delivery %u, exchange %.*s routingkey %.*s\n",(unsigned) d->delivery_tag, 84 | (int) d->exchange.len, (char *) d->exchange.bytes, 85 | (int) d->routing_key.len, (char *) d->routing_key.bytes); 86 | 87 | result = amqp_simple_wait_frame(conn, &frame); 88 | if (result < 0) 89 | break; 90 | 91 | if (frame.frame_type != AMQP_FRAME_HEADER) { 92 | fprintf(stderr, "Expected header!"); 93 | abort(); 94 | } 95 | p = (amqp_basic_properties_t *) frame.payload.properties.decoded; 96 | if (p->_flags & AMQP_BASIC_CONTENT_TYPE_FLAG) { 97 | printf("Content-type: %.*s\n", 98 | (int) p->content_type.len, (char *) p->content_type.bytes); 99 | } 100 | 101 | body_target = frame.payload.properties.body_size; 102 | body_received = 0; 103 | 104 | int sleep_seconds = 0; 105 | while (body_received < body_target) { 106 | result = amqp_simple_wait_frame(conn, &frame); 107 | if (result < 0) 108 | break; 109 | 110 | if (frame.frame_type != AMQP_FRAME_BODY) { 111 | fprintf(stderr, "Expected body!"); 112 | abort(); 113 | } 114 | 115 | body_received += frame.payload.body_fragment.len; 116 | assert(body_received <= body_target); 117 | 118 | int i; 119 | for(i = 0; idelivery_tag,0); 138 | } 139 | } 140 | 141 | die_on_amqp_error(amqp_channel_close(conn, 1, AMQP_REPLY_SUCCESS), "Closing channel"); 142 | die_on_amqp_error(amqp_connection_close(conn, AMQP_REPLY_SUCCESS), "Closing connection"); 143 | die_on_error(amqp_destroy_connection(conn), "Ending connection"); 144 | 145 | return 0; 146 | } 147 | -------------------------------------------------------------------------------- /rmq_new_task: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuhaobupt/rabbitmq_work_queues_demo-with-rabbit-c-client-lib/f58d5d0b45d999dd93aa82887bcd7626cf988ea3/rmq_new_task -------------------------------------------------------------------------------- /rmq_new_task.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "utils.h" 9 | 10 | int main(int argc, const char **argv) { 11 | 12 | const char *hostname; 13 | int port; 14 | const char *exchange; 15 | const char *queuename; 16 | const char *messagebody; 17 | 18 | if (argc < 6) { 19 | fprintf(stderr, "Usage: rmq_new_task host port exchange queuename messagebody\n"); 20 | return 1; 21 | } 22 | 23 | hostname = argv[1]; 24 | port = atoi(argv[2]); 25 | exchange = argv[3]; 26 | queuename = argv[4]; 27 | messagebody = argv[5]; 28 | 29 | int sockfd; 30 | int channelid = 1; 31 | amqp_connection_state_t conn; 32 | conn = amqp_new_connection(); 33 | 34 | die_on_error(sockfd = amqp_open_socket(hostname, port), "Opening socket"); 35 | amqp_set_sockfd(conn, sockfd); 36 | die_on_amqp_error(amqp_login(conn, "/", 0, 131072, 0, AMQP_SASL_METHOD_PLAIN, "crawler", "crawler"),"Logging in"); 37 | amqp_channel_open(conn, channelid); 38 | die_on_amqp_error(amqp_get_rpc_reply(conn), "Opening channel"); 39 | 40 | /* amqp_table_entry_t *arg = malloc(sizeof(amqp_table_entry_t)); 41 | arg->key = amqp_cstring_bytes("x-ha-policy"); 42 | arg->value.value.bytes = amqp_cstring_bytes("all"); 43 | const amqp_table_t args = {1,arg};*/ 44 | 45 | /*amqp_queue_declare(conn,channelid,amqp_cstring_bytes(queuename),0,1,0,0,amqp_empty_table);*/ 46 | 47 | { 48 | amqp_basic_properties_t props; 49 | props._flags = AMQP_BASIC_DELIVERY_MODE_FLAG; 50 | /*props.content_type = amqp_cstring_bytes("text/plain");*/ 51 | props.delivery_mode = 2; /* persistent delivery mode */ 52 | die_on_error(amqp_basic_publish(conn, 53 | channelid, 54 | amqp_cstring_bytes(exchange), 55 | amqp_cstring_bytes(queuename), 56 | 0, 57 | 0, 58 | //&props, 59 | NULL, 60 | amqp_cstring_bytes(messagebody)), 61 | "Publishing"); 62 | } 63 | 64 | die_on_amqp_error(amqp_channel_close(conn, 1, AMQP_REPLY_SUCCESS), "Closing channel"); 65 | die_on_amqp_error(amqp_connection_close(conn, AMQP_REPLY_SUCCESS), "Closing connection"); 66 | die_on_error(amqp_destroy_connection(conn), "Ending connection"); 67 | return 0; 68 | } 69 | -------------------------------------------------------------------------------- /rmq_worker: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuhaobupt/rabbitmq_work_queues_demo-with-rabbit-c-client-lib/f58d5d0b45d999dd93aa82887bcd7626cf988ea3/rmq_worker -------------------------------------------------------------------------------- /rmq_worker.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | #include "utils.h" 12 | 13 | int main(int argc, const char **argv) { 14 | 15 | const char *hostname; 16 | int port; 17 | const char *exchange; 18 | const char *queuename; 19 | 20 | if (argc < 5) { 21 | fprintf(stderr, "Usage: rmq_worker host port exchange queuename\n"); 22 | return 1; 23 | } 24 | 25 | hostname = argv[1]; 26 | port = atoi(argv[2]); 27 | exchange = argv[3]; 28 | queuename = argv[4]; 29 | 30 | int sockfd; 31 | int channelid = 1; 32 | amqp_connection_state_t conn; 33 | conn = amqp_new_connection(); 34 | 35 | die_on_error(sockfd = amqp_open_socket(hostname, port), "Opening socket"); 36 | amqp_set_sockfd(conn, sockfd); 37 | die_on_amqp_error(amqp_login(conn, "/", 0, 131072, 0, AMQP_SASL_METHOD_PLAIN, "guest", "guest"),"Logging in"); 38 | amqp_channel_open(conn, channelid); 39 | die_on_amqp_error(amqp_get_rpc_reply(conn), "Opening channel"); 40 | 41 | amqp_queue_declare(conn,channelid,amqp_cstring_bytes(queuename),0,1,0,0,amqp_empty_table); 42 | 43 | amqp_basic_qos(conn,channelid,0,1,0); 44 | amqp_basic_consume(conn,channelid,amqp_cstring_bytes(queuename),amqp_empty_bytes,0,0,0,amqp_empty_table); 45 | die_on_amqp_error(amqp_get_rpc_reply(conn), "Consuming"); 46 | 47 | { 48 | amqp_frame_t frame; 49 | int result; 50 | amqp_basic_deliver_t *d; 51 | amqp_basic_properties_t *p; 52 | size_t body_target; 53 | size_t body_received; 54 | 55 | while (1) { 56 | amqp_maybe_release_buffers(conn); 57 | result = amqp_simple_wait_frame(conn, &frame); 58 | printf("Result %d\n", result); 59 | if (result < 0) 60 | break; 61 | 62 | printf("Frame type %d, channel %d\n", frame.frame_type, frame.channel); 63 | if (frame.frame_type != AMQP_FRAME_METHOD) 64 | continue; 65 | 66 | printf("Method %s\n", amqp_method_name(frame.payload.method.id)); 67 | if (frame.payload.method.id != AMQP_BASIC_DELIVER_METHOD) 68 | continue; 69 | 70 | d = (amqp_basic_deliver_t *) frame.payload.method.decoded; 71 | printf("Delivery %u, exchange %.*s routingkey %.*s\n",(unsigned) d->delivery_tag, 72 | (int) d->exchange.len, (char *) d->exchange.bytes, 73 | (int) d->routing_key.len, (char *) d->routing_key.bytes); 74 | 75 | result = amqp_simple_wait_frame(conn, &frame); 76 | if (result < 0) 77 | break; 78 | 79 | if (frame.frame_type != AMQP_FRAME_HEADER) { 80 | fprintf(stderr, "Expected header!"); 81 | abort(); 82 | } 83 | p = (amqp_basic_properties_t *) frame.payload.properties.decoded; 84 | if (p->_flags & AMQP_BASIC_CONTENT_TYPE_FLAG) { 85 | printf("Content-type: %.*s\n", 86 | (int) p->content_type.len, (char *) p->content_type.bytes); 87 | } 88 | 89 | body_target = frame.payload.properties.body_size; 90 | body_received = 0; 91 | 92 | int sleep_seconds = 0; 93 | while (body_received < body_target) { 94 | result = amqp_simple_wait_frame(conn, &frame); 95 | if (result < 0) 96 | break; 97 | 98 | if (frame.frame_type != AMQP_FRAME_BODY) { 99 | fprintf(stderr, "Expected body!"); 100 | abort(); 101 | } 102 | 103 | body_received += frame.payload.body_fragment.len; 104 | assert(body_received <= body_target); 105 | 106 | int i; 107 | for(i = 0; idelivery_tag,0); 126 | } 127 | } 128 | 129 | die_on_amqp_error(amqp_channel_close(conn, 1, AMQP_REPLY_SUCCESS), "Closing channel"); 130 | die_on_amqp_error(amqp_connection_close(conn, AMQP_REPLY_SUCCESS), "Closing connection"); 131 | die_on_error(amqp_destroy_connection(conn), "Ending connection"); 132 | 133 | return 0; 134 | } 135 | -------------------------------------------------------------------------------- /unix/platform_utils.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ***** BEGIN LICENSE BLOCK ***** 3 | * Version: MPL 1.1/GPL 2.0 4 | * 5 | * The contents of this file are subject to the Mozilla Public License 6 | * Version 1.1 (the "License"); you may not use this file except in 7 | * compliance with the License. You may obtain a copy of the License 8 | * at http://www.mozilla.org/MPL/ 9 | * 10 | * Software distributed under the License is distributed on an "AS IS" 11 | * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 12 | * the License for the specific language governing rights and 13 | * limitations under the License. 14 | * 15 | * The Original Code is librabbitmq. 16 | * 17 | * The Initial Developer of the Original Code is VMware, Inc. 18 | * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. 19 | * 20 | * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 21 | * VMware, Inc. and Tony Garnock-Jones. 22 | * 23 | * All rights reserved. 24 | * 25 | * Alternatively, the contents of this file may be used under the terms 26 | * of the GNU General Public License Version 2 or later (the "GPL"), in 27 | * which case the provisions of the GPL are applicable instead of those 28 | * above. If you wish to allow use of your version of this file only 29 | * under the terms of the GPL, and not to allow others to use your 30 | * version of this file under the terms of the MPL, indicate your 31 | * decision by deleting the provisions above and replace them with the 32 | * notice and other provisions required by the GPL. If you do not 33 | * delete the provisions above, a recipient may use your version of 34 | * this file under the terms of any one of the MPL or the GPL. 35 | * 36 | * ***** END LICENSE BLOCK ***** 37 | */ 38 | 39 | /* For usleep */ 40 | #define _BSD_SOURCE 41 | 42 | #include 43 | 44 | #include 45 | #include 46 | 47 | uint64_t now_microseconds(void) 48 | { 49 | struct timeval tv; 50 | gettimeofday(&tv, NULL); 51 | return (uint64_t) tv.tv_sec * 1000000 + (uint64_t) tv.tv_usec; 52 | } 53 | 54 | void microsleep(int usec) 55 | { 56 | usleep(usec); 57 | } 58 | -------------------------------------------------------------------------------- /utils.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ***** BEGIN LICENSE BLOCK ***** 3 | * Version: MPL 1.1/GPL 2.0 4 | * 5 | * The contents of this file are subject to the Mozilla Public License 6 | * Version 1.1 (the "License"); you may not use this file except in 7 | * compliance with the License. You may obtain a copy of the License 8 | * at http://www.mozilla.org/MPL/ 9 | * 10 | * Software distributed under the License is distributed on an "AS IS" 11 | * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 12 | * the License for the specific language governing rights and 13 | * limitations under the License. 14 | * 15 | * The Original Code is librabbitmq. 16 | * 17 | * The Initial Developer of the Original Code is VMware, Inc. 18 | * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. 19 | * 20 | * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 21 | * VMware, Inc. and Tony Garnock-Jones. 22 | * 23 | * All rights reserved. 24 | * 25 | * Alternatively, the contents of this file may be used under the terms 26 | * of the GNU General Public License Version 2 or later (the "GPL"), in 27 | * which case the provisions of the GPL are applicable instead of those 28 | * above. If you wish to allow use of your version of this file only 29 | * under the terms of the GPL, and not to allow others to use your 30 | * version of this file under the terms of the MPL, indicate your 31 | * decision by deleting the provisions above and replace them with the 32 | * notice and other provisions required by the GPL. If you do not 33 | * delete the provisions above, a recipient may use your version of 34 | * this file under the terms of any one of the MPL or the GPL. 35 | * 36 | * ***** END LICENSE BLOCK ***** 37 | */ 38 | 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | #include 45 | #include 46 | #include 47 | 48 | #include "utils.h" 49 | 50 | void die_on_error(int x, char const *context) { 51 | if (x < 0) { 52 | char *errstr = amqp_error_string(-x); 53 | fprintf(stderr, "%s: %s\n", context, errstr); 54 | free(errstr); 55 | exit(1); 56 | } 57 | } 58 | 59 | void die_on_amqp_error(amqp_rpc_reply_t x, char const *context) { 60 | switch (x.reply_type) { 61 | case AMQP_RESPONSE_NORMAL: 62 | return; 63 | 64 | case AMQP_RESPONSE_NONE: 65 | fprintf(stderr, "%s: missing RPC reply type!\n", context); 66 | break; 67 | 68 | case AMQP_RESPONSE_LIBRARY_EXCEPTION: 69 | fprintf(stderr, "%s: %s\n", context, amqp_error_string(x.library_error)); 70 | break; 71 | 72 | case AMQP_RESPONSE_SERVER_EXCEPTION: 73 | switch (x.reply.id) { 74 | case AMQP_CONNECTION_CLOSE_METHOD: { 75 | amqp_connection_close_t *m = (amqp_connection_close_t *) x.reply.decoded; 76 | fprintf(stderr, "%s: server connection error %d, message: %.*s\n", 77 | context, 78 | m->reply_code, 79 | (int) m->reply_text.len, (char *) m->reply_text.bytes); 80 | break; 81 | } 82 | case AMQP_CHANNEL_CLOSE_METHOD: { 83 | amqp_channel_close_t *m = (amqp_channel_close_t *) x.reply.decoded; 84 | fprintf(stderr, "%s: server channel error %d, message: %.*s\n", 85 | context, 86 | m->reply_code, 87 | (int) m->reply_text.len, (char *) m->reply_text.bytes); 88 | break; 89 | } 90 | default: 91 | fprintf(stderr, "%s: unknown server error, method id 0x%08X\n", context, x.reply.id); 92 | break; 93 | } 94 | break; 95 | } 96 | 97 | exit(1); 98 | } 99 | 100 | static void dump_row(long count, int numinrow, int *chs) { 101 | int i; 102 | 103 | printf("%08lX:", count - numinrow); 104 | 105 | if (numinrow > 0) { 106 | for (i = 0; i < numinrow; i++) { 107 | if (i == 8) 108 | printf(" :"); 109 | printf(" %02X", chs[i]); 110 | } 111 | for (i = numinrow; i < 16; i++) { 112 | if (i == 8) 113 | printf(" :"); 114 | printf(" "); 115 | } 116 | printf(" "); 117 | for (i = 0; i < numinrow; i++) { 118 | if (isprint(chs[i])) 119 | printf("%c", chs[i]); 120 | else 121 | printf("."); 122 | } 123 | } 124 | printf("\n"); 125 | } 126 | 127 | static int rows_eq(int *a, int *b) { 128 | int i; 129 | 130 | for (i=0; i<16; i++) 131 | if (a[i] != b[i]) 132 | return 0; 133 | 134 | return 1; 135 | } 136 | 137 | void amqp_dump(void const *buffer, size_t len) { 138 | unsigned char *buf = (unsigned char *) buffer; 139 | long count = 0; 140 | int numinrow = 0; 141 | int chs[16]; 142 | int oldchs[16]; 143 | int showed_dots = 0; 144 | int i; 145 | 146 | for (i = 0; i < len; i++) { 147 | int ch = buf[i]; 148 | 149 | if (numinrow == 16) { 150 | int i; 151 | 152 | if (rows_eq(oldchs, chs)) { 153 | if (!showed_dots) { 154 | showed_dots = 1; 155 | printf(" .. .. .. .. .. .. .. .. : .. .. .. .. .. .. .. ..\n"); 156 | } 157 | } else { 158 | showed_dots = 0; 159 | dump_row(count, numinrow, chs); 160 | } 161 | 162 | for (i=0; i<16; i++) 163 | oldchs[i] = chs[i]; 164 | 165 | numinrow = 0; 166 | } 167 | 168 | count++; 169 | chs[numinrow++] = ch; 170 | } 171 | 172 | dump_row(count, numinrow, chs); 173 | 174 | if (numinrow != 0) 175 | printf("%08lX:\n", count); 176 | } 177 | -------------------------------------------------------------------------------- /utils.h: -------------------------------------------------------------------------------- 1 | #ifndef librabbitmq_examples_utils_h 2 | #define librabbitmq_examples_utils_h 3 | 4 | /* 5 | * ***** BEGIN LICENSE BLOCK ***** 6 | * Version: MPL 1.1/GPL 2.0 7 | * 8 | * The contents of this file are subject to the Mozilla Public License 9 | * Version 1.1 (the "License"); you may not use this file except in 10 | * compliance with the License. You may obtain a copy of the License 11 | * at http://www.mozilla.org/MPL/ 12 | * 13 | * Software distributed under the License is distributed on an "AS IS" 14 | * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 15 | * the License for the specific language governing rights and 16 | * limitations under the License. 17 | * 18 | * The Original Code is librabbitmq. 19 | * 20 | * The Initial Developer of the Original Code is VMware, Inc. 21 | * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc. 22 | * 23 | * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010 24 | * VMware, Inc. and Tony Garnock-Jones. 25 | * 26 | * All rights reserved. 27 | * 28 | * Alternatively, the contents of this file may be used under the terms 29 | * of the GNU General Public License Version 2 or later (the "GPL"), in 30 | * which case the provisions of the GPL are applicable instead of those 31 | * above. If you wish to allow use of your version of this file only 32 | * under the terms of the GPL, and not to allow others to use your 33 | * version of this file under the terms of the MPL, indicate your 34 | * decision by deleting the provisions above and replace them with the 35 | * notice and other provisions required by the GPL. If you do not 36 | * delete the provisions above, a recipient may use your version of 37 | * this file under the terms of any one of the MPL or the GPL. 38 | * 39 | * ***** END LICENSE BLOCK ***** 40 | */ 41 | 42 | extern void die_on_error(int x, char const *context); 43 | extern void die_on_amqp_error(amqp_rpc_reply_t x, char const *context); 44 | 45 | extern void amqp_dump(void const *buffer, size_t len); 46 | 47 | extern uint64_t now_microseconds(void); 48 | extern void microsleep(int usec); 49 | 50 | #endif 51 | --------------------------------------------------------------------------------