Subscribes to the 'example' node and prints the message bodies received.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
typedef char str[1024];
typedef struct app_data_t {
str address;
str container_id;
int message_count;
int received;
bool finished;
} app_data_t;
static const int BATCH = 100;
static int exit_code = 0;
exit_code = 1;
}
}
#define MAX_SIZE 1024
static char buffer[MAX_SIZE];
ssize_t len;
if (len > 0) {
pn_string_t *s = pn_string(NULL);
printf("%s\n", pn_string_get(s));
pn_free(s);
}
}
}
}
static void handle(app_data_t* app,
pn_event_t* event) {
pn_link_flow(l, app->message_count ? app->message_count : BATCH);
} break;
decode_message(dlv);
if (app->message_count == 0) {
}
} else if (++app->received >= app->message_count) {
printf("%d messages received\n", app->received);
}
}
} break;
break;
break;
break;
break;
app->finished = true;
break;
default: break;
}
}
static void usage(const char *arg0) {
fprintf(stderr, "Usage: %s [-a url] [-m message-count]\n", arg0);
exit(1);
}
int main(int argc, char **argv) {
app_data_t app = {{0}};
app.message_count = 100;
const char* urlstr = NULL;
int opt;
while((opt = getopt(argc, argv, "a:m:")) != -1) {
switch(opt) {
case 'a': urlstr = optarg; break;
case 'm': app.message_count = atoi(optarg); break;
default: usage(argv[0]); break;
}
}
if (optind < argc)
usage(argv[0]);
snprintf(app.container_id, sizeof(app.container_id), "%s:%d", argv[0], getpid());
const char *host = url ? pn_url_get_host(url) : NULL;
const char *port = url ? pn_url_get_port(url) : "amqp";
strncpy(app.address, (url && pn_url_get_path(url)) ? pn_url_get_path(url) : "example", sizeof(app.address));
do {
handle(&app, e);
}
} while(!app.finished);
free(app.message_buffer.start);
return exit_code;
}
void pn_delivery_settle(pn_delivery_t *delivery)
Settle a delivery.
void pn_proactor_done(pn_proactor_t *proactor, pn_event_batch_t *events)
Call when done handling a batch of events.
pn_condition_t * pn_connection_remote_condition(pn_connection_t *connection)
Get the remote condition associated with the connection endpoint.
void pn_link_open(pn_link_t *link)
Open a link.
pn_event_batch_t * pn_proactor_wait(pn_proactor_t *proactor)
Wait for events to handle.
pn_link_t * pn_receiver(pn_session_t *session, const char *name)
Construct a new receiver on a session.
struct pn_event_t pn_event_t
Notification of a state change in the protocol engine.
Definition: event.h:75
int pn_terminus_set_address(pn_terminus_t *terminus, const char *address)
Set the address of a terminus object.
void pn_message_free(pn_message_t *msg)
Free a previously constructed pn_message_t.
A delivery has been created or updated.
Definition: event.h:254
The remote endpoint has closed the link.
Definition: event.h:223
pn_session_t * pn_link_session(pn_link_t *link)
Get the parent session for a link object.
const char * pn_condition_get_name(pn_condition_t *condition)
Returns the name associated with the exceptional condition, or NULL if there is no conditional inform...
The proactor becaome inactive: all listeners and connections are closed and their events processed,...
Definition: event.h:353
void pn_session_open(pn_session_t *session)
Open a session.
pn_condition_t * pn_link_remote_condition(pn_link_t *link)
Get the remote condition associated with a link endpoint.
pn_session_t * pn_session(pn_connection_t *connection)
Factory for creating a new session on a given connection object.
struct pn_message_t pn_message_t
An AMQP Message object.
Definition: message.h:51
const char * pn_condition_get_description(pn_condition_t *condition)
Gets the description associated with the exceptional condition.
void pn_delivery_update(pn_delivery_t *delivery, uint64_t state)
Update the disposition of a delivery.
struct pn_url_t pn_url_t
A parsed URL.
Definition: url.h:42
pn_message_t * pn_message(void)
Construct a new pn_message_t.
A non-const byte buffer.
Definition: types.h:225
void pn_session_close(pn_session_t *session)
Close a session.
struct pn_proactor_t pn_proactor_t
The proactor, see pn_proactor()
Definition: proactor.h:63
pn_delivery_t * pn_event_delivery(pn_event_t *event)
Get the delivery associated with an event.
The connection has been created.
Definition: event.h:113
pn_proactor_t * pn_proactor(void)
Create a proactor.
struct pn_delivery_t pn_delivery_t
An AMQP Delivery object.
Definition: types.h:395
pn_event_t * pn_event_batch_next(pn_event_batch_t *batch)
Experimental - Remove the next event from the batch and return it.
void pn_link_flow(pn_link_t *receiver, int credit)
Grant credit for incoming deliveries on a receiver.
struct pn_condition_t pn_condition_t
An AMQP Condition object.
Definition: condition.h:64
struct pn_event_batch_t pn_event_batch_t
Experimental - A batch of events to handle.
Definition: event.h:544
The remote endpoint has detached the link.
Definition: event.h:235
int pn_proactor_connect(pn_proactor_t *proactor, pn_connection_t *connection, const char *host, const char *port)
Connect connection to host/port.
void pn_proactor_free(pn_proactor_t *proactor)
Free the proactor.
#define PN_OK
No error.
Definition: error.h:46
pn_connection_t * pn_event_connection(pn_event_t *event)
Get the connection associated with an event.
The remote endpoint has closed the connection.
Definition: event.h:149
int pn_message_decode(pn_message_t *msg, const char *bytes, size_t size)
Decode/load message content from AMQP formatted binary data.
bool pn_condition_is_set(pn_condition_t *condition)
Returns true if the condition object is holding some information, i.e.
struct pn_connection_t pn_connection_t
An AMQP Connection object.
Definition: types.h:275
The remote endpoint has closed the session.
Definition: event.h:186
void pn_connection_close(pn_connection_t *connection)
Close a connection.
pn_session_t * pn_event_session(pn_event_t *event)
Get the session associated with an event.
ssize_t pn_link_recv(pn_link_t *receiver, char *bytes, size_t n)
Receive message data for the current delivery on a link.
bool pn_delivery_partial(pn_delivery_t *delivery)
Check if a delivery only has partial message data.
void pn_connection_open(pn_connection_t *connection)
Open a connection.
struct pn_link_t pn_link_t
An AMQP Link object.
Definition: types.h:305
#define PN_ACCEPTED
The PN_ACCEPTED delivery state is a terminal state indicating that the delivery was successfully proc...
Definition: disposition.h:64
pn_link_t * pn_delivery_link(pn_delivery_t *delivery)
Get the parent link for a delivery object.
void pn_connection_set_container(pn_connection_t *connection, const char *container)
Set the AMQP Container name advertised by a connection object.
bool pn_delivery_readable(pn_delivery_t *delivery)
Check if a delivery is readable.
pn_condition_t * pn_session_remote_condition(pn_session_t *session)
Get the remote condition associated with the session endpoint.
struct pn_session_t pn_session_t
An AMQP Session object.
Definition: types.h:286
void pn_url_free(pn_url_t *url)
Free a URL.
pn_url_t * pn_url_parse(const char *url)
Parse a string URL as a pn_url_t.
pn_connection_t * pn_connection(void)
Factory to construct a new Connection.
Indicates that a transport error has occurred.
Definition: event.h:275
pn_data_t * pn_message_body(pn_message_t *msg)
Get/set the body of a message.
pn_condition_t * pn_transport_condition(pn_transport_t *transport)
Get additional information about the condition of the transport.
pn_event_type_t pn_event_type(pn_event_t *event)
Get the type of an event.
const char * pn_event_type_name(pn_event_type_t type)
Get a human readable name for an event type.
size_t pn_delivery_pending(pn_delivery_t *delivery)
Get the amount of pending message data for a delivery.
pn_connection_t * pn_session_connection(pn_session_t *session)
Get the parent connection for a session object.
int pn_link_credit(pn_link_t *link)
Get the credit balance for a link.
void pn_link_close(pn_link_t *link)
Close a link.
pn_transport_t * pn_event_transport(pn_event_t *event)
Get the transport associated with an event.
pn_link_t * pn_event_link(pn_event_t *event)
Get the link associated with an event.
pn_terminus_t * pn_link_source(pn_link_t *link)
Access the locally defined source definition for a link.
bool pn_link_advance(pn_link_t *link)
Advance the current delivery of a link to the next delivery on the link.