Exemplo n.º 1
0
static VALUE rwire_amq_content_basic_alloc(VALUE klass)
{
	amq_content_basic_t * content = amq_content_basic_new();
	if (!content)
		rb_raise(rb_eRuntimeError, "Failed to create content object");
	VALUE rb_content = Data_Wrap_Struct(klass, 0, rwire_amq_content_basic_free, content);
	return rb_content;
}
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
static VALUE rwire_amq_client_session_publish_content(VALUE self,
	VALUE r_content,
	VALUE exchange,
	VALUE routing_key,
        VALUE r_mandatory,
        VALUE r_immediate)
{
	char * exch = NULL;
	char * rkey = 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);
	}

	Data_Get_Struct(self, amq_client_session_t, session);
	Data_Get_Struct(r_content, amq_content_basic_t, content);

	int rc = 0;
	do {
		rc = amq_client_session_basic_publish(session, content, 0, exch, rkey, mandatory, immediate);
		if (rc) {
			rb_raise(eAMQError, "Failed to publish message");
		}
	} while (false);

	return self;
}
Exemplo n.º 4
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;
}