xmq is an Erlang library that provides cross message system utilities.
Features:
- AMQP to 0MQ bridge
The (a)MQP to (z)eroMQ bridge lets 0MQ clients participate in an AMQP routing scheme.
It works like this:
- Bridge connects to AMQP broker and binds a number of topics to a queue
- Bridge provides a ROUTER 0MQ socket
- Clients routinely publish expirable routes
- Clients send messages destined to AMQP
- Clients receive messages routed by bridge from AMQP
- Bridge routinely unbinds topics as routes expire
The bridge will support these client operations:
bind | Specify client bindings |
send | Send an AMQP message |
The bind message will be a ZMQ multi-part message:
[<<”bind”>>, DirectBinding | TopicBindings]
For example:
[<<”bind”>>, <<”my-direct-queue”>>, <<”test.#”>>]
The send message:
[<<”send”>>, Exchange, Key, binary(#amqp_msg{})]
NOTE: The message here is an binary encoded amqp_msg Erlang record. This ties clients to Erlang for the time being. If we need to support other clients, we’d need to support an independent encoding scheme such as JSON, msgpack, etc.
Options = [{direct_binding, {<<"amq.direct">>, <<"my-queue">>}},
{topic_bindings, {<<"amq.topic">>, [<<"test.#">>]}},
{amqp_host, "localhost"},
{amqp_creds, {<<"guest">>, <<"guest">>}},
{router_endpoint, "tcp://*:5555"}],
xmq_az_bridge:start_link(Bindings, Options)
This bridge will connect to the local AMQP broker using the specified user name and password.
It will bind a router socket to the local interface at port 5555. 0MQ clients can use this to routinely publish their bindings, send messages, and receive messages by way of the AMQP broker according to their bindings.
The module xmq_routes provides these functions:
add_direct(Key, Dest, Expires) | Adds a direct route |
get_direct(Key) | Gets a direct consumer |
add_topic(Key, Dest, Expires) | Adds a topic route |
get_topic(Key) | Gets topic consumers |
Routes expire if they’re not routinely updated. Clients are expected to update their routing information in regular periods to ensure they receive messages. If a client doesn’t update its routes, the routes will eventually expire.