Code Monkey home page Code Monkey logo

c-stomp's Introduction

c-stomp

A STOMP client written in c, STOMP is the Simple (or Streaming) Text Orientated Messaging Protocol.

Table of Contents

Introduction

c-stomp is a C library to write STOMP protocol in order to working with ActiveMQ, RabbitMQ, HornetQ, ActiveMQ Apollo and other messaging protocol which support stomp.

Example

    /*For Connecting to Stomp */
    cstmp_session_t *consuming_sess = cstmp_connect_t(HOST, PORT, 500/*send_timeout*/, 500/*recv_timeout*/);
    if (consuming_sess) {
        cstmp_frame_t *consume_fr = cstmp_new_frame();
        consume_fr->cmd = "CONNECT";
        cstmp_add_header(consume_fr, "login", "guest");
        cstmp_add_header(consume_fr, "passcode", "guest");
        cstmp_add_header(consume_fr, "version", "1.2");

        if (cstmp_send(consuming_sess, consume_fr, 0) && cstmp_recv(consuming_sess, consume_fr, 0)) {
            cstmp_dump_frame_pretty(consume_fr);
        }
    }
    /* For Sending to */
    cstmp_reset_frame(fr);
    fr->cmd = "SEND";
    cstmp_add_header(fr, "destination", QUEUE_NAME);
    cstmp_add_header(fr, "persistent", "false");
    cstmp_add_header(fr, "content-type", "text/plain");
    cstmp_add_body_content(fr, "{\"my_key\":\"akjdlkajdklj2ljladasjldjasljdl@ASD2\"}");

    if (! cstmp_send(sess, fr, 1)) {
        assert(0 && "Unable to send frame");
        break;
    }
    /* For Reading Response */
    if(cstmp_recv(sess, fr, 2 /*conn retry 2 times*/)) {
        cstmp_dump_frame_raw(fr); /*For Raw message display, good for debugging purpose*/ 
    }
    /** To create a hooker to consume the message and callback handler **/

    /*** remember to reset frame before prepare the new command ***/
    cstmp_reset_frame(consume_fr);

    consume_fr->cmd = "SUBSCRIBE";
    cstmp_add_header(consume_fr, "destination", QUEUE_NAME);
    cstmp_add_header(consume_fr, "ack", "auto");
    cstmp_add_header(consume_fr, "id", "0");
    cstmp_add_header(consume_fr, "durable", "false");
    cstmp_send(consuming_sess, consume_fr, 3);

    void (*consume_handler)(cstmp_frame_t* consume_fr) =
    ({
        void __fn__ (cstmp_frame_t* consume_fr) {
            assert( strlen(cstmp_get_cmd(consume_fr)) > 0 && "Error, no command found");
            cstmp_dump_frame_pretty(consume_fr);
        }
        __fn__;
    });

    /** Keep hooking until consuming = false / 0 **/
    cstmp_consume(consuming_sess, (cstmp_frame_t*) consume_fr, consume_handler, &consuming);

Back to TOC

Installation

For non sharing connection
cd $project_root_dir
mkdir build
cd build
cmake ..
make -j2
./run-test
sudo make install
For sharing the connection
cd $project_root_dir
mkdir build
cd build
cmake -DSHARED_CONNECTION=1 ..
make -j2
./run-test2
sudo make install

Back to TOC

Uninstall

cd $project_root_dir/build
sudo make uninstall

Support

Please do not hesitate to contact [email protected]/[email protected] for any queries.

Back to TOC

Copyright & License

MIT License

Copyright (c) 2018, Taymindis Woon [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

c-stomp's People

Contributors

cdgwoon avatar taymindis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

satarsa

c-stomp's Issues

Time out connection failed

Too few minutes its getting time out. how i can fix this issue. when ever i want to send the data i have to connect than send.

Error, Invalid frame IO reading

I change the IP and PORT to my own activeMQ,I add some print

Starting stomp connection, sending and consuming /amq/queue/stompqueue
i == 12,failed here
Error, Invalid frame IO reading
i == 12,failed here
Error, Invalid frame IO reading
disconnecting Stomp
Test Passed

How to handle the mistake?
// port is not correct

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.