W/o Durability
#include <stdlib.h> #include "apr_general.h" #include "stomp.h" void main() { apr_initialize(); 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, "/topic/SampleTopic"); 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); stomp_disconnect(&connection); apr_pool_destroy(pool); apr_terminate(); }
W/ Durability
#include "apr_general.h" #include "stomp.h" #include <stdlib.h> void main() { apr_initialize(); 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 = apr_hash_make(pool); apr_hash_set(connect_frame.headers, "client-id", APR_HASH_KEY_STRING, "SampleClient"); 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, "activemq.subscriptionName", APR_HASH_KEY_STRING, "SampleSubscription"); apr_hash_set(subscribe_frame.headers, "destination", APR_HASH_KEY_STRING, "/topic/SampleTopic"); 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); stomp_disconnect(&connection); apr_pool_destroy(pool); apr_terminate(); }
Leave a comment