I am trying to write an AMQP 1.0 client using Qpid Proton in C. I do not want to use messenger. I want to use the proton-c engine. I am having a little trouble figuring out how to do this. My main sticking point is setting the endpoint for the connection. The only example of a C client using the proton-c engine I can find is here.
https://github.com/apache/qpid-proton/blob/master/examples/engine/c/psend.c
However, it uses structs that are not part of the Qpid Proton C API 0.12.0. Specifically, I don’t see pn_driver_t or pn_connector_t as part of the 0.12.0 API.
I am trying to follow the general workflow defined in the AMQP 1.0 spec 1) create a connection, 2) create a session, 3) create a sender link. I am not very experienced with C and this is my first time using the non-messenger part of the Qpid Proton library so forgive me if I missed something obvious. Here is my current code. I have been trying different options and searching for days.
#include <stdio.h> #include <unistd.h> #include <string.h> #include "proton/message.h" #include "proton/messenger.h" #include "proton/connection.h" #include "proton/session.h" #include "proton/link.h" #include "proton/delivery.h" #include "proton/event.h" #include "proton/engine.h" //State integer values are defined in Connection macros //https://qpid.apache.org/releases/qpid-proton-0.12.0/proton/c/api/group__connection.html void print_state(char * name, pn_state_t state) { printf("[%s] local: %i, remote: %i\n", name, PN_LOCAL_MASK & state, PN_REMOTE_MASK & state); } //Reference https://github.com/apache/qpid-proton/blob/master/examples/engine/c/psend.c void send_engine() { struct pn_connection_t * connection; connection = pn_connection(); //STACKOVERFLOW - I have a feeling this is not right, but cannot find an alternative to set protocol (amqp or ws) the hostname and port. I see a way to set the hostname only pn_connection_set_container(connection, "amqp://amqpserver:port"); print_state("Connection Initialized", pn_connection_state(connection)); pn_transport_t * transport; transport = pn_transport(); int r = pn_transport_bind(transport, connection); if (r != 0) { printf("transport bind error: %i\n", r); } pn_connection_open(connection); print_state("Connection Opened", pn_connection_state(connection)); pn_session_t * sess; sess = pn_session(connection); print_state("Session Initialized", pn_session_state(sess)); pn_session_open(sess); print_state("Session Opened", pn_session_state(sess)); pn_link_t * sender; sender = pn_sender(sess, "c-client"); //the queue name in "toserver" pn_terminus_set_address(pn_link_target(sender), "toserver"); print_state("Sender Link Initialized", pn_link_state(sender)); pn_link_open(sender); print_state("Sender Link Opened", pn_link_state(sender)); pn_delivery_t *delivery; char *tagID = "uid"; delivery = pn_delivery(sender, pn_dtag(tagID, strlen(tagID))); char *msg = "abc"; printf("%zd\n", pn_link_send(sender, msg, strlen(msg))); pn_delivery_settle(delivery); printf("Delivery stettled %d\n", pn_delivery_settled(delivery)); print_state("Connection End", pn_connection_state(connection)); print_state("Session End", pn_session_state(sess)); print_state("Sender Link End", pn_link_state(sender)); //TODO free everything } int main (int argc, char *argv[]) { send_engine(); printf("done\n"); return 0; }
On my AMQP server I have enable frame level tracing and do not see any communication from the client. This is not a problem with the server. It works with many other clients, including a C client using the messenger API. What am I missing in this sample? Thank you!
Note: I have tried to solve this exhaustively and provided as much context as possible.
0 comments:
Post a Comment