static VALUE rwire_amq_content_basic_set_body(VALUE self, VALUE value) { amq_content_basic_t *content = NULL; char *_value = StringValuePtr(value); Data_Get_Struct(self, amq_content_basic_t, content); int len = RSTRING(value)->len; char * copy = malloc(len); memcpy(copy, _value, len); if (amq_content_basic_set_body(content, copy, RSTRING(value)->len, free)) { rb_raise(eAMQError, "Failed to set content body"); } return self; }
inline virtual void send (size_t size_) { // Create the message body. void *message_body = malloc (size_); assert (message_body); // Create the message itself. amq_content_basic_t *content = amq_content_basic_new (); amq_content_basic_set_body (content, message_body, size_, free); // Send the message. amq_client_session_basic_publish (session, content, 0, "amq.direct", (char*) send_rk, FALSE, FALSE); // Release the message. amq_content_basic_unlink (&content); }
static VALUE rwire_amq_client_session_publish_body(VALUE self, VALUE body, VALUE exchange, VALUE routing_key, VALUE r_mandatory, VALUE r_immediate, VALUE r_reply_to) { char * exch = NULL; char * rkey = NULL; char * reply_to = NULL; bool mandatory = TO_BOOL(r_mandatory); bool immediate = TO_BOOL(r_immediate); amq_client_session_t * session = NULL; amq_content_basic_t * content = amq_content_basic_new(); if (!NIL_P(exchange)) { exch = StringValuePtr(exchange); } if (!NIL_P(routing_key)) { rkey = StringValuePtr(routing_key); } if (!NIL_P(r_reply_to)) { reply_to = StringValuePtr(r_reply_to); } Data_Get_Struct(self, amq_client_session_t, session); int rc = 0; char * errmsg = NULL; do { char * blob = new_blob_from_rb_str(body); int size = RSTRING_LEN(body); // Set the content body rc = amq_content_basic_set_body(content, blob, size, free); if (rc) { errmsg = "Unable to set content body"; break; } // Set the reply_to field if passed in if (reply_to) { rc = amq_content_basic_set_reply_to(content, reply_to); if (rc) { errmsg = "Unable to set reply_to field"; break; } } // Publish rc = amq_client_session_basic_publish(session, content, 0, exch, rkey, mandatory, immediate); if (rc) { errmsg = "Failed to publish message"; break; } } while (false); if (content) { amq_content_basic_unlink(&content); } if (rc) { rb_raise(eAMQError, errmsg); } //TODO check for a more useful value to return return self; }