Beispiel #1
0
        inline virtual size_t receive ()
        {
            //  Get next message; if none is available wait for it.
            amq_content_basic_t *content =
                amq_client_session_basic_arrived (session);

            if (!content) {

                //  Wait while next message arrives.
                amq_client_session_wait (session, 0);

                //  Exit the loop if Ctrl+C is encountered.
//  FIXME
//                if (!connection->alive)
//                    assert (false);

                //  Get the message.
                content = amq_client_session_basic_arrived (session);
                assert (content);
            }

            //  Retrieve message size.
            size_t size = amq_content_basic_get_body_size (content);

            //  Destroy the message.
            amq_content_basic_unlink (&content);

            return size;
        }
Beispiel #2
0
// Helper function to destroy the underlying amq_content_basic_t object when
// GC free the corresponding Ruby Object
static void rwire_amq_content_basic_free(void *p)
{
	amq_content_basic_t * content = (amq_content_basic_t *)p;
	if (content) {
		amq_content_basic_unlink(&content);
	}
}
Beispiel #3
0
void free_amq_content_cls( amq_content_cls *obj) {
  if (obj && obj->content) {
    amq_content_basic_unlink(&(obj->content));
    obj->content=0;
  }
  if (obj)
    free(obj);
}
Beispiel #4
0
static VALUE rwire_amq_content_basic_unlink(VALUE self)
{
	// NOTE: Use DATA_PTR to get the underlying ptr instead of the helper
	// macro Data_Get_Struct which makes a copy of the underlying struct.

	amq_content_basic_unlink((amq_content_basic_t**)&(DATA_PTR(self)));

	return self;
}
Beispiel #5
0
        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);
        }
Beispiel #6
0
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;
}