int main(void)
{
  burrow_st *burrow;
  client_st client;
  client.message_count = 0;
  client.return_code = 0;
  client.account = "account";
  client.queue = "queue";
  client.messages = (linked list of messages)
  client.current_message = client.messages;

  burrow = burrow_create("http");
  burrow_set_backend_option("server", "burrow.example.com");
  burrow_set_backend_option("port", "1234");

  burrow_set_context(burrow, &client);
  burrow_set_complete_fn(burrow, &_complete);
  burrow_set_log_fn(burrow, &_log);

  /* Insert the first one here to kick the loop off. This only sets start state,
     it doesn't run the loop. */
  message = client.current_messages;
  burrow_create_message(burrow, client.account, client.queue,
    client.current_message->message, NULL, client.current_message->body);

  /* This runs until there are no more tasks. */
  burrow_process(burrow);

  return client->return_code;
}
예제 #2
0
int main(int argc, char **argv)
{
  const char *server = "localhost";
  const char *port = "8080";
  const char *account = getlogin();
  const char *queue = "demo";
  int c;
  int verbose = 0;
  int seed = (int)time(NULL);
  int messages = 0;
  int endless = 0;
  int maxsleep = 25;
    
  app_state_st state = { 0, 0, {0}, 0 };
  
  while ((c = getopt(argc, argv, "s:p:a:q:gchve:r:l:")) != -1)
  {
    switch(c) {
    case 'v':
      verbose++;
      break;
    case 'g':
      state.generator = 1;
      break;
    case 'c':
      state.generator = 0;
      break;
    case 's':
      server = optarg;
      break;
    case 'p':
      port = optarg;
      break;
    case 'a':
      account = optarg;
      break;
    case 'q':
      queue = optarg;
      break;
    case 'e':
      seed = atoi(optarg);
      break;
    case 'r':
      messages = atoi(optarg) + 1;
      
      break;
    case 'l':
      maxsleep = atoi(optarg); /* hundredths of a second */
      break;
    default:
    case 'h':
      print_help(argv[0]);
      return 0;
    }
  }
  
  srand((unsigned int)seed);
  if (verbose > 1)
    printf("info: using random seed %d", seed);
  
  if (!messages)
    endless = 1;

  burrow_st *burrow;
  
  burrow = burrow_create(NULL, "http");
  if (!burrow)
    FATAL("burrow creation failed");
    
  burrow_set_backend_option(burrow, "server", server);
  burrow_set_backend_option(burrow, "port", port);
  
  burrow_add_options(burrow, BURROW_OPT_AUTOPROCESS);
  
  burrow_set_log_fn(burrow, &error_callback);
  burrow_set_message_fn(burrow, &message_callback);
  burrow_set_complete_fn(burrow, &complete_callback);
  
  burrow_set_context(burrow, &state);
  
  if (state.generator) {
    char buf[1024];
    char uuidbuf[36 + 1];
    uuid_t uuid;
    burrow_attributes_st *attr = burrow_attributes_create(NULL, burrow);
    
    if (!attr)
      FATAL("couldn't allocate attributes\n");
    burrow_attributes_set_ttl(attr, 5); /* short ttl */

    while (endless || messages--) {
      uuid_generate(uuid);
      uuid_unparse(uuid, uuidbuf);
      random_equation(buf, 1024);

      printf("Sending: %s\nExpected value: %f\n", buf, process_equation(buf));
      burrow_create_message(burrow, account, queue, uuidbuf, (void*)buf, strlen(buf), attr);
      
      if (state.error)
        FATAL("encountered error");
    
      if (maxsleep && (messages || endless)) {
        int sl = rand() % maxsleep;
        if (verbose)
          printf("info: sleeping for %d hundredths of a second\n", sl);
        usleep((useconds_t)sl * 10000);
      }
    }
    if (verbose)
      printf("info: done sending messages\n");
  } else { /* Consumer */
    burrow_filters_st *filters = burrow_filters_create(NULL, burrow);
    
    if (!filters)
      FATAL("couldn't create filters or attributes");
      
    burrow_filters_set_detail(filters, BURROW_DETAIL_ALL);
    
    while (endless || messages--) {
      if (state.last_msg_id[0])
        burrow_filters_set_marker(filters, state.last_msg_id);
      else
        burrow_filters_set_marker(filters, NULL);
      burrow_get_messages(burrow, account, queue, filters);

      if (state.error)
        FATAL("encountered error");

      if (maxsleep && (messages || endless)) {
        int sl = rand() % maxsleep;
        if (verbose)
          printf("info: sleeping for %d hundredths of a second\n", sl);
        usleep((useconds_t)sl * 10000);
      }
    }
    if (verbose)
      printf("info: done receiving messages\n");
  }
  
  burrow_destroy(burrow);
  return 0;
}
예제 #3
0
int main(int argc, char **argv)
{
  burrow_st *burrow;
  client_st client;
  msg_st *msg;
  int use_http = 0;

  argc--;
  argv++;

  if (strcmp(argv[0], "http") == 0) {
    use_http = 1;
    argc--;
    argv++;
  }

  if (argc < 4 || argc % 2 != 0)
    return -1;

  client.account = argv[0];
  client.queue = argv[1];
  argc -= 2;
  argv += 2;

  client.messages = NULL;
  client.message_count = 0;

  while (argc) {
    msg = malloc(sizeof(msg_st));
    if (!msg)
      return -2;

    msg->msg_id = argv[0];
    msg->body = (uint8_t *)argv[1];
    msg->body_size = strlen(argv[1]);
    msg->next = client.messages;
    client.messages = msg;
    client.message_count++;

    argc -= 2;
    argv += 2;
  }

  client.return_code = 0;
  client.current_message = client.messages;

  if (use_http == 0) {
    burrow = burrow_create(NULL, "dummy");
    printf("burrow = %p\n", burrow);
  } else {
    burrow = burrow_create(NULL, "http");
    printf("burrow = %p\n", burrow);
    burrow_backend_set_option(burrow, "server", "localhost");
    burrow_backend_set_option(burrow, "port", "8080");
  }

  burrow_set_context(burrow, &client);
  burrow_set_log_fn(burrow, &_log);
  burrow_set_message_fn(burrow, &_message);

  (void) _complete;
  /* Insert the first one here to kick the loop off. This only sets start state,
     it doesn't run the loop. */
  burrow_set_complete_fn(burrow, &_complete);
  msg = client.current_message;
  printf("Calling create_message(%s,%s,%s,\"%s\",..)\n\n", client.account,
	 client.queue, msg->msg_id, msg->body);
  burrow_create_message(burrow, client.account, client.queue,
  			msg->msg_id, msg->body, msg->body_size, NULL);

  /* This runs until there are no more tasks. */
  burrow_process(burrow);

  printf("Ok, now let us see what messages the server has\n");
  /* Now see what the server has */
  burrow_get_messages(burrow, client.account, client.queue, NULL);
  burrow_result_t result;
  do {
    result = burrow_process(burrow);
  } while (result != BURROW_OK);

  /* Now get the first message */
  {
    printf("Now we will get the first message\n");
    burrow_filters_st *filters = burrow_filters_create(0,0);

    burrow_filters_set_detail(filters, BURROW_DETAIL_ALL);
    burrow_get_message(burrow, client.account, client.queue, 
		       client.messages->msg_id,
		       filters
		       );
    burrow_process(burrow);
  }

  /*
  burrow_destroy(burrow);
  if (use_http == 0) {
    burrow = burrow_create(NULL, "dummy");
    printf("burrow = %p\n", burrow);
  } else {
    burrow = burrow_create(NULL, "http");
    printf("burrow = %p\n", burrow);
    burrow_backend_set_option(burrow, "server", "localhost");
    burrow_backend_set_option(burrow, "port", "8080");
  }
  */

  /* Now update the first message to hide for a couple seconds */
  uint32_t seconds = 3;
  printf("Now we will update the first message to hide it for %d seconds\n",seconds);
  burrow_filters_st *filters = burrow_filters_create(0,0);
  burrow_attributes_st *attributes = burrow_attributes_create(0,0);
  burrow_attributes_set_hide(attributes, seconds);
  burrow_filters_set_detail(filters, BURROW_DETAIL_ALL);
  burrow_update_message(burrow, client.account, client.queue, 
			client.messages->msg_id,
			attributes,
			filters
			);
  burrow_process(burrow);

  printf("Get all messages, one should be missing\n");
  burrow_get_messages(burrow, client.account, client.queue, NULL);
  burrow_process(burrow);
  printf("Now sleep until the messages should reappear\n");
  sleep(seconds + 1);

  printf("Now get all messages again\n");
  burrow_get_messages(burrow, client.account, client.queue, NULL);
  burrow_process(burrow);
  
  printf("Ok, now let us delete one message\n");
  burrow_filters_free(filters);
  filters = burrow_filters_create(0,0);
  burrow_filters_set_detail(filters, BURROW_DETAIL_ALL);
  burrow_delete_message(burrow, client.account, client.queue, client.messages->msg_id,
			NULL);
  burrow_process(burrow);

  printf("Get all messages, one should be missing\n");
  burrow_get_messages(burrow, client.account, client.queue, NULL);
  burrow_process(burrow);

  printf("Get list of accounts\n");
  burrow_set_account_fn(burrow, &_account);
  burrow_get_accounts(burrow, NULL);
  burrow_process(burrow);

  printf("finishing up\n");

  burrow_destroy(burrow);
  exit(0);

  return client.return_code;
}
예제 #4
0
int main(int argc, char **argv)
{
  burrow_st *burrow;
  client_st client;
  msg_st *msg;
  int use_http = 0;

  argc--;
  argv++;

  if (strcmp(argv[0], "http") == 0) {
    use_http = 1;
    argc--;
    argv++;
  }

  if (argc < 4 || argc % 2 != 0)
    return -1;

  client.account = argv[0];
  client.queue = argv[1];
  argc -= 2;
  argv += 2;

  client.messages = NULL;
  client.message_count = 0;

  while (argc) {
    msg = malloc(sizeof(msg_st));
    if (!msg)
      return -2;

    msg->msg_id = argv[0];
    msg->body = (uint8_t *)argv[1];
    msg->body_size = strlen(argv[1]);
    msg->next = client.messages;
    client.messages = msg;
    client.message_count++;

    argc -= 2;
    argv += 2;
  }

  client.return_code = 0;
  client.current_message = client.messages;

  if (use_http == 0) {
    burrow = burrow_create(NULL, "dummy");
    printf("burrow = %p\n", burrow);
  } else {
    burrow = burrow_create(NULL, "http");
    printf("burrow = %p\n", burrow);
    burrow_backend_set_option(burrow, "server", "localhost");
    burrow_backend_set_option(burrow, "port", "8080");
  }

  burrow_set_context(burrow, &client);
  burrow_set_complete_fn(burrow, &_complete);
  burrow_set_log_fn(burrow, &_log);

  /* Insert the first one here to kick the loop off. This only sets start state,
     it doesn't run the loop. */
  msg = client.current_message;
  burrow_create_message(burrow, client.account, client.queue,
    msg->msg_id, msg->body, msg->body_size, NULL);

  /* This runs until there are no more tasks. */
  burrow_process(burrow);
  burrow_destroy(burrow);

  return client.return_code;
}