Beispiel #1
0
int main(int argc, const char **argv)
{
	amqp_connection_state_t conn;
	char *queue = NULL;
	int got_something;

	struct poptOption options[] = {
		INCLUDE_OPTIONS(connect_options),
		{"queue", 'q', POPT_ARG_STRING, &queue, 0,
		 "the queue to consume from", "queue"},
		POPT_AUTOHELP
		{ NULL, 0, 0, NULL, 0 }
	};

	process_all_options(argc, argv, options);

	if (!queue) {
		fprintf(stderr, "queue not specified\n");
		return 1;
	}

	conn = make_connection();
	got_something = do_get(conn, queue);
	close_connection(conn);
	return got_something ? 0 : 2;
}
int main(int argc, const char **argv)
{
  amqp_connection_state_t conn;
  char *queue = NULL;
  int durable = 0;

  struct poptOption options[] = {
    INCLUDE_OPTIONS(connect_options),
    {
      "queue", 'q', POPT_ARG_STRING, &queue, 0,
      "the queue name to declare, or the empty string", "queue"
    },
    {
      "durable", 'd', POPT_ARG_VAL, &durable, 1,
      "declare a durable queue", NULL
    },
    POPT_AUTOHELP
    { NULL, '\0', 0, NULL, 0, NULL, NULL }
  };

  process_all_options(argc, argv, options);

  if (queue == NULL) {
    fprintf(stderr, "queue name not specified\n");
    return 1;
  }

  conn = make_connection();
  {
    amqp_queue_declare_ok_t *reply = amqp_queue_declare(conn, 1,
                                     cstring_bytes(queue),
                                     0,
                                     durable,
                                     0,
                                     0,
                                     amqp_empty_table);
    if (reply == NULL) {
      die_rpc(amqp_get_rpc_reply(conn), "queue.declare");
    }

    printf("%.*s\n", (int)reply->queue.len, (char *)reply->queue.bytes);
  }
  close_connection(conn);
  return 0;
}
Beispiel #3
0
int main(int argc, const char **argv)
{
	amqp_connection_state_t conn;
	char *queue = NULL;
	int if_unused = 0;
	int if_empty = 0;

	struct poptOption options[] = {
		INCLUDE_OPTIONS(connect_options),
		{"queue", 'q', POPT_ARG_STRING, &queue, 0,
		 "the queue name to delete", "queue"},
		{"if-unused", 'u', POPT_ARG_VAL, &if_unused, 1,
		 "do not delete unless queue is unused", NULL},
		{"if-empty", 'e', POPT_ARG_VAL, &if_empty, 1,
		 "do not delete unless queue is empty", NULL},
		POPT_AUTOHELP
		{ NULL, 0, 0, NULL, 0 }
	};

	process_all_options(argc, argv, options);

	if (queue == NULL || *queue == '\0') {
	  fprintf(stderr, "queue name not specified\n");
	  return 1;
	}

	conn = make_connection();
	{
	  amqp_queue_delete_ok_t *reply = amqp_queue_delete(conn, 1,
							    cstring_bytes(queue),
							    if_unused,
							    if_empty);
	  if (reply == NULL) {
	    die_rpc(amqp_get_rpc_reply(conn), "queue.delete");
	  }
	  printf("%u\n", reply->message_count);
	}
	close_connection(conn);
	return 0;
}
Beispiel #4
0
int main(int argc, const char **argv)
{
	amqp_connection_state_t conn;
	char *exchange = NULL;
	char *routing_key = NULL;
	char *content_type = NULL;
	char *content_encoding = NULL;
	char *body = NULL;
	amqp_basic_properties_t props;
	amqp_bytes_t body_bytes;
	int delivery = 1; /* non-persistent by default */

	struct poptOption options[] = {
		INCLUDE_OPTIONS(connect_options),
		{"exchange", 'e', POPT_ARG_STRING, &exchange, 0,
		 "the exchange to publish to", "exchange"},
		{"routing-key", 'r', POPT_ARG_STRING, &routing_key, 0,
		 "the routing key to publish with", "routing key"},
		{"persistent", 'p', POPT_ARG_VAL, &delivery, 2,
		 "use the persistent delivery mode", NULL},
		{"content-type", 'C', POPT_ARG_STRING, &content_type, 0,
		 "the content-type for the message", "content type"},
		{"content-encoding", 'E', POPT_ARG_STRING,
		 &content_encoding, 0,
		 "the content-encoding for the message", "content encoding"},
		{"body", 'b', POPT_ARG_STRING, &body, 0,
                 "specify the message body", "body"},
		POPT_AUTOHELP
		{ NULL, 0, 0, NULL, 0 }
	};

	process_all_options(argc, argv, options);

	if (!exchange && !routing_key) {
		fprintf(stderr,
			"neither exchange nor routing key specified\n");
		return 1;
	}

	memset(&props, 0, sizeof props);
	props._flags = AMQP_BASIC_DELIVERY_MODE_FLAG;
	props.delivery_mode = 2; /* persistent delivery mode */

	if (content_type) {
		props._flags |= AMQP_BASIC_CONTENT_TYPE_FLAG;
		props.content_type = amqp_cstring_bytes(content_type);
	}

	if (content_encoding) {
		props._flags |= AMQP_BASIC_CONTENT_ENCODING_FLAG;
		props.content_encoding = amqp_cstring_bytes(content_encoding);
	}

	conn = make_connection();

	if (body)
		body_bytes = amqp_cstring_bytes(body);
	else
		body_bytes = read_all(0);

	do_publish(conn, exchange, routing_key, &props, body_bytes);

	if (!body)
		free(body_bytes.bytes);

	close_connection(conn);
	return 0;
}