A modification of the original example, using the lower level connection engine for message exchange. It is an outdated example.
#include <stdlib.h>
int die(
int exitCode,
const char *message, apr_status_t reason)
{
char msgbuf[80];
apr_strerror(reason, msgbuf, sizeof (msgbuf));
fprintf(stderr, "%s: %s (%d)\n", message, msgbuf, reason);
exit(exitCode);
return reason;
}
static void terminate()
{
apr_terminate();
}
static void check_status(apr_status_t rc, const char *message) {
if (rc != APR_SUCCESS) {
}
}
int main(
int argc,
char *argv[])
{
apr_status_t rc;
setbuf(stdout, NULL);
rc = apr_initialize();
check_status(rc, "Could not initialize");
atexit(terminate);
rc = apr_pool_create(&pool, NULL);
check_status(rc, "Could not allocate pool");
fprintf(stdout, "Connecting......");
rc = stomp_engine_connect(&connection, "localhost", 61613, pool);
check_status(rc, "Could not connect");
fprintf(stdout, "OK\n");
fprintf(stdout, "Sending connect message.");
{
frame.
headers = apr_hash_make(pool);
rc = stomp_write(connection, &frame, pool);
check_status(rc, "Could not send frame");
}
fprintf(stdout, "OK\n");
fprintf(stdout, "Reading Response.");
{
rc = stomp_read(connection, &frame, pool);
check_status(rc, "Could not read frame");
fprintf(stdout,
"Response: %s, %s\n", frame->
command, frame->
body);
}
fprintf(stdout, "OK\n");
fprintf(stdout, "Sending Subscribe.");
{
frame.
headers = apr_hash_make(pool);
apr_hash_set(frame.
headers,
"destination", APR_HASH_KEY_STRING,
"/queue/FOO.BAR");
rc = stomp_write(connection, &frame, pool);
check_status(rc, "Could not send frame");
}
fprintf(stdout, "OK\n");
fprintf(stdout, "Reading Response.");
{
rc = stomp_read(connection, &frame, pool);
check_status(rc, "Could not read frame");
fprintf(stdout,
"Response: %s, %s\n", frame->
command, frame->
body);
fprintf(stdout,
"Body: %s", frame->
body);
}
fprintf(stdout, "OK\n");
fprintf(stdout, "Sending Disconnect.");
{
rc = stomp_write(connection, &frame, pool);
check_status(rc, "Could not send frame");
}
fprintf(stdout, "OK\n");
fprintf(stdout, "Disconnecting...");
rc = stomp_engine_disconnect(&connection);
check_status(rc, "Could not disconnect");
fprintf(stdout, "OK\n");
apr_pool_destroy(pool);
return 0;
}