When I use auto-accept mode in my receiver, the sender says that all my 
messages are PN_STATUS_PENDING.

I can make the right thing happen when I use manual accept mode, a tracker, and 
have the receiver explicitly accept the messages -- but I assumed that 
PN_ACCEPT_MODE_AUTO would -- you know -- accept messages as they come in.

Is this a bug?  or a misunderstanding on my part ?





( start the receiver first, and then, in another window, the sender )

=========================================================
sender ==================================================
=========================================================

#include "proton/message.h"
#include "proton/messenger.h"

#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>


#define N_MESSAGES 5

int
main(int argc, char** argv)
{
  int i;
  char addr [ 1000 ];
  char * msgtext = "Hello, Proton!";
  pn_message_t   * message;
  pn_messenger_t * messenger;
  pn_data_t      * body;
  pn_tracker_t     tracker [ N_MESSAGES ];
  pn_status_t      status  [ N_MESSAGES ];
  int n_accepted;



  sprintf ( addr, "amqp://0.0.0.0:%s", argv[1] );


  message = pn_message();
  messenger = pn_messenger(NULL);
  pn_messenger_set_outgoing_window ( messenger, N_MESSAGES );
  pn_messenger_start(messenger);


  pn_message_set_address ( message, addr );
  body = pn_message_body(message);
  pn_data_put_string(body, pn_bytes(strlen(msgtext), msgtext));


  /*---------------------------------
    Stage the messages.
  ---------------------------------*/
  for ( i = 0; i < N_MESSAGES; ++ i )
  {
    pn_messenger_put(messenger, message);
    tracker [ i ] = pn_messenger_outgoing_tracker ( messenger );
  }


  /*----------------------------------
    Make sure the messages are sent.
  ----------------------------------*/
  fprintf ( stderr, "sending...\n" );
  pn_messenger_send(messenger);

  fprintf ( stderr, "done sending.  snoozing...\n" );
  sleep ( 5 );
  fprintf ( stderr, "Checking status...\n" );


  /*---------------------------------
    Print status for all messages.
  ----------------------------------*/
  for ( i = 0; i < N_MESSAGES; ++ i )
  {
    status [ i ] = pn_messenger_status ( messenger, tracker [ i ] );
    fprintf ( stderr, "status %d: %d\n", i, status [ i ] );
  }

  pn_messenger_stop(messenger);
  pn_messenger_free(messenger);
  pn_message_free(message);

  return 0;
}






===================================================
receiver ==========================================
===================================================
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

#include "proton/message.h"
#include "proton/messenger.h"



#define BUFSIZE    1024
#define N_MESSAGES 5



int
main(int argc, char** argv)
{
  int i;
  size_t bufsize = BUFSIZE;
  char buffer [ BUFSIZE ];
  char addr [ 1000 ];
  pn_message_t   * message;
  pn_messenger_t * messenger;
  pn_data_t      * body;
  int              incoming_window = -1;
  int              incoming = -1;
  pn_tracker_t     tracker;


  sprintf ( addr, "amqp://~0.0.0.0:%s", argv[1] );

  message = pn_message();
  messenger = pn_messenger ( NULL );
  pn_messenger_start(messenger);
  pn_messenger_subscribe ( messenger, addr );
  pn_messenger_set_incoming_window ( messenger, N_MESSAGES );
  pn_messenger_set_accept_mode ( messenger, PN_ACCEPT_MODE_AUTO );


  while ( incoming < N_MESSAGES )
  {
    incoming = pn_messenger_incoming ( messenger );
    pn_messenger_recv ( messenger, N_MESSAGES );
    fprintf ( stderr, "%d incoming.\n", incoming );
  }

  for ( i = 0; i < N_MESSAGES; ++ i )
  {
    pn_messenger_get ( messenger, message );
    body = pn_message_body ( message );
    pn_data_format ( body, buffer, & bufsize );
    printf("Content: %s\n", buffer);
  }

  fprintf ( stderr, "receiver exiting.\n" );
  pn_messenger_stop(messenger);
  pn_messenger_free(messenger);

  return 0;
}

Reply via email to