How to Receive a Message from an Apache ActiveMQ Queue with C/C++

#include <stdlib.h>

#include "apr_general.h"
#include "stomp.h"

void main() {

  apr_pool_t *pool;

  apr_pool_create(&pool, NULL);

  stomp_connection *connection;

  stomp_connect(&connection, "localhost", 61613, pool);

  stomp_frame connect_frame;

  connect_frame.command = "CONNECT";

  connect_frame.headers = NULL;

  stomp_write(connection, &connect_frame, pool);

  stomp_frame *connected_frame; // Skip the CONNECTED frame

  stomp_read(connection, &connected_frame, pool);

  stomp_frame subscribe_frame;

  subscribe_frame.command = "SUBSCRIBE";

  subscribe_frame.headers = apr_hash_make(pool);

  apr_hash_set(subscribe_frame.headers, "destination", APR_HASH_KEY_STRING, "SampleQueue");

  stomp_write(connection, &subscribe_frame, pool);

  stomp_frame *message_frame;

  stomp_read(connection, &message_frame, pool);

  printf("%s\n", message_frame->body);

  stomp_frame disconnect_frame;

  disconnect_frame.command = "DISCONNECT";

  disconnect_frame.headers = NULL;

  stomp_write(connection, &disconnect_frame, pool);




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s