[midgard-dev] Should we have a ZeroMQ API for Midgard?

Henri Bergius henri.bergius at iki.fi
Tue Mar 1 10:39:13 CET 2011


As part of the IKS work last week we ended up writing some simple
triple synchronization stuff with NodeJS. When that needed
persistence, I obviously wanted to use Midgard, but unfortunately we
don't have that available for NodeJS yet. So I just made a crude Redis
triplestore implementation instead.

But on longer term, Midgard2 (or MidgardCR!) would provide a lot more
power and flexibility. How could we, then, make it available to
environments without GObject Introspection? This includes not only
NodeJS, but also potentially QML.

One option is of course direct bindings. NodeJS has a C++ extension
API: https://www.cloudkick.com/blog/2010/aug/23/writing-nodejs-native-extensions/

But as we have learned, maintaining bindings is quite a lot of work.
And I'm not sure if a binding can be made particularly easy to install
("Native extensions are more tricky to do this way because you need to
automate their build system." says

So, as an alternative idea: what if we had a "Midgard Server" process
that provided a ZeroMQ API? This would be accessible either locally or
even via network from quite a bunch of languages:

ZeroMQ is reasonably similar to D-Bus in concept, but is network
transparent and doesn't impose a particular transport payload. So we
could use something simple, like JSON. Here is a pretty good
introduction to the subject: http://nichol.as/zeromq-an-introduction

The "Midgard Server" could easily be sketched out in either Python or
PHP and AiP, and if performance or ease of installation later
requires, could be ported to Vala. For applications nothing would
change, as they would still be talking to a ZeroMQ endpoint.

Here is a quick sketch of how the API could look like.

Write request:
update: {
    '@': 'urn:uuid:GUID',
    a: 'mgd:midgard_article',
    title: 'Foo'
context: {
    login: 'admin',
    password: 'password',
    workspace: '/live/drafts'

status: {
    code: 1,
    error: MGD_ERR_OK

Query request:
query: {
    'a': 'mgd:midgard_article',
    constraints: [
    order: [
            'metadata:created': 'desc'
context: {
     workspace: '/live'

response: [
        '@': 'urn:uuid:GUID',
        a: 'mgd:midgard_article',
        title: 'Foo'

Signal handling:

Connecting to a signal:
sub: {
    'a': 'midgard_article',
    'guid': null, // Any article object
    'signal': 'action-created'

Henri Bergius
Motorcycle Adventures and Free Software

Skype: henribergius
Jabber: henri.bergius at gmail.com
Microblog: http://www.qaiku.com/home/bergie/

More information about the dev mailing list