Last active
August 29, 2015 14:04
-
-
Save peoplemerge/39a6babea5bc4741f2cd to your computer and use it in GitHub Desktop.
A simple msgpack test for openstack-marconi using JSON input
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
python sample_json2msgpack.py | |
cat msg.pck |curl -i -X POST http://127.0.0.1:8888/v1.1/queues/samplequeue/messages -H "Content-type: application/x-msgpack" -H "Client-ID: 507b06b1-f6a6-4818-a241-cc19a312fac9" -H 'Accept: application/json, application/x-msgpack' --data-binary @- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
outputs: | |
HTTP/1.0 201 Created | |
Date: Sun, 20 Jul 2014 23:23:45 GMT | |
Server: WSGIServer/0.1 Python/2.7.8 | |
content-length: 79 | |
content-type: application/json; charset=utf-8 | |
location: /v1.1/queues/samplequeue/messages?ids=5c693a51 | |
{"partial": false, "resources": ["/v1.1/queues/samplequeue/messages/5c693a51"]} | |
log shows: | |
2014-07-20 16:23:45.676 12583 DEBUG marconi.queues.transport.wsgi.v1_1.messages [-] Messages collection POST - queue: samplequeue, project: None on_post /opt/stack/marconi/marconi/queues/transport/wsgi/v1_1/messages.py:143 | |
2014-07-20 16:23:45.676 12583 DEBUG marconi.queues.transport.wsgi.v1_1.messages [-] accepts msgpack?: True, content type: application/x-msgpack on_post /opt/stack/marconi/marconi/queues/transport/wsgi/v1_1/messages.py:158 | |
2014-07-20 16:23:45.676 12583 DEBUG marconi.queues.transport.wsgi.utils [-] None _filter_msgpack /opt/stack/marconi/marconi/queues/transport/wsgi/utils.py:86 | |
127.0.0.1 - - [20/Jul/2014 16:23:45] "POST /v1.1/queues/samplequeue/messages HTTP/1.1" 201 79 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import msgpack | |
import json | |
jsonobj = '[ { "ttl": 300, "body": { "event": "BackupStarted", "backup_id": "c378813c-3f0b-11e2-ad92-7823d2b0f3ce" } } ]' | |
pythonobj = json.loads(jsonobj) | |
msgpackobj = msgpack.Packer(use_bin_type=True).pack(pythonobj) | |
with open('msg.pck', 'wb') as f: | |
f.write(msgpackobj) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment