On bluemix message hub, how do I exchange messages between a rest and mqlight client?
<p>according to the documentation <a href="https://console.ng.bluemix.net/docs/services/MessageHub/index.html#messagehub" rel="nofollow">https://console.ng.bluemix.net/docs/services/MessageHub/index.html#messagehub</a> it should be possible to submit a message to MessageHub via REST and receive it via a MQLight client. However the documentation is lacking an example and is somewhat ... opaque.</p>

<p>So, if I create the MQLight topic, and have a python client listening,</p>

<pre><code>    import json
    import logging
    import mqlight
    import time

    amqps = 'amqps://xxxxxxxxxxxxx.messagehub.services.us-south.bluemix.net:5671'
    options = {
        'user' : 'xxxxxxxxxxxxxxxx',
        'password' : 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    }

    def on_message(message_type, data, delivery):
        d = json.loads(data)
        print str(d)

    def on_started(err):
        client.subscribe('test', on_message = on_message)

    def on_stopped(err):
        logging.info('stopped')

    client = mqlight.Client(amqps, security_options = options, client_id = 'client', on_started=on_started)

    while True:
        logging.info(str(client.get_state()))
        time.sleep(5)
</code></pre>

<p>how would I post a message via curl. I have tried, where the value string is base64 encoded,</p>

<pre><code>    curl  -i                                                                                                      \
          -X POST                                                                                                 \
          -H "X-Auth-Token:${APIKEY}"                                                                             \
          -H "Content-Type: application/vnd.kafka.binary.v1+json"                                                 \
          --data '{"records":[{"value":"S2Fma2E="}]}'                                                             \
          "https://kafka-rest-prod01.messagehub.services.us-south.bluemix.net:443/topics/MQLight/test"
</code></pre>

<p>but that returns,</p>

<pre><code>    {"error_code":404,"message":"HTTP 404 Not Found"}
</code></pre>

<p>You're correct that the documentation here isn't particularly fleshed out. The only detail on this is in the small section <a href="https://new-console.ng.bluemix.net/docs/services/MessageHub/index.html#messagehub081" rel="nofollow">here</a> which is trying to explain that in order to inter-operate with an MQLight client from some other Kafka or REST client, you'd need to be able to encode/decode the AMQP 1.0 message format (see section 3 of the <a href="http://docs.oasis-open.org/amqp/core/v1.0/amqp-core-complete-v1.0.pdf" rel="nofollow">spec</a>).</p>

<p>You'd struggle to achieve this in curl scripts as you need access to an AMQP 1.0 library, and even Python isn't ideal as currently your only real option there is to pull in <a href="https://pypi.python.org/pypi/python-qpid-proton/0.14.0" rel="nofollow">python-qpid-proton</a> which is quite heavyweight as it wraps the proton-c native library and hence requires install-time compilation.</p>

<p>For example, in Java you could use a combination of the official Java <a href="https://kafka.apache.org" rel="nofollow">kafka-clients</a> and qpid <a href="https://qpid.apache.org/releases/qpid-proton-0.14.0/proton/java/api/index.html" rel="nofollow">proton-j</a> to provide the AMQP message encoding + decoding. Or if you <em>must</em> use the REST api, then pull in something like <a href="https://github.com/OpenFeign/feign" rel="nofollow">feign</a>.</p>

python rest ibm-bluemix message-hub