{"id":13624947,"url":"https://github.com/squaremo/node-amqp","last_synced_at":"2025-04-16T01:33:04.058Z","repository":{"id":65552297,"uuid":"957322","full_name":"squaremo/node-amqp","owner":"squaremo","description":"An obsolete fork of node-amqp. Please see squaremo/amqp.node for a better RabbitMQ client.","archived":false,"fork":true,"pushed_at":"2012-03-27T14:37:04.000Z","size":342,"stargazers_count":38,"open_issues_count":0,"forks_count":6,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-08-01T22:03:08.575Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"postwait/node-amqp","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/squaremo.png","metadata":{"files":{"readme":"README.md","changelog":"History.md","contributing":null,"funding":null,"license":"LICENSE-MIT","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2010-10-02T21:36:12.000Z","updated_at":"2019-07-08T15:01:09.000Z","dependencies_parsed_at":"2023-01-29T01:05:10.453Z","dependency_job_id":null,"html_url":"https://github.com/squaremo/node-amqp","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/squaremo%2Fnode-amqp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/squaremo%2Fnode-amqp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/squaremo%2Fnode-amqp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/squaremo%2Fnode-amqp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/squaremo","download_url":"https://codeload.github.com/squaremo/node-amqp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223691933,"owners_count":17186894,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T21:01:48.531Z","updated_at":"2025-04-16T01:33:04.036Z","avatar_url":"https://github.com/squaremo.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# node-amqp\n\nIMPORTANT: This module only works with node v0.4.0 and later.\n\nThis is a client for RabbitMQ (and maybe other servers?). It partially\nimplements the 0.9.1 version of the AMQP protocol.\n\n## Installation\n\n    npm install amqp\n\n## Synopsis\n\nAn example of connecting to a server and listening on a queue.\n\n    var sys = require('sys');\n    var amqp = require('amqp');\n\n    var connection = amqp.createConnection({ host: 'dev.rabbitmq.com' });\n\n    // Wait for connection to become established.\n    connection.on('ready', function () {\n      // Create a queue and bind to all messages.\n      // Use the default 'amq.topic' exchange\n      var q = connection.queue('my-queue');\n      // Catch all messages\n      q.bind('#');\n\n      // Receive messages\n      q.subscribe(function (message) {\n        // Print messages to stdout\n        sys.p(message);\n      });\n    });\n\n\n## Connection\n\n`new amqp.Connection()` Instantiates a new connection. Use\n`connection.connect()` to connect to a server.\n\n`amqp.createConnection()` returns an instance of `amqp.Connection`, which is\na subclass of `net.Stream`. All the event and methods which work on\n`net.Stream` can also be used on an `amqp.Connection` instance. (e.g., the\nevents `'connected'` and `'closed'`.)\n\n### Connection options and URL\n\n`amqp.createConnection([options, [implOptions]])` takes two options\nobjects as parameters.  The first options object has these defaults:\n\n    { host: 'localhost'\n    , port: 5672\n    , login: 'guest'\n    , password: 'guest'\n    , vhost: '/'\n    }\n\nAll of these can be passed in a single URL of the form\n\n    amqp[s]://[user:password@]hostname[:port][/vhost]\n\nNote that the vhost must be URL-encoded and appear as the only segment\nof the path, i.e., the only unencoded slash is that leading; leaving\nthe path entirely empty indicates that the vhost `/`, as\nabove, should be used (it could also be supplied as the path `/%2f`).\n\nThis URL is supplied as the field `url` in the options; for example\n\n    var conn =\n      amqp.createConnection({url: \"amqp://guest:guest@localhost:5672\"});\n\nOptions provided as individual fields will override values given in\nthe URL.\n\nThe second options are specific to the node AMQP implementation. It has\nthe default values:\n\n    { defaultExchangeName: '' }\n\nThe defaultExchangeName is the default exchange to which\nconnection.publish will publish. In the past, the default exchange was\n`amq.topic`, which is not ideal.  To emulate this behaviour, one can\ncreate a connection like:\n\n    var conn =\n      amqp.createConnection({url: \"amqp://guest:guest@localhost:5672\"},\n                            {defaultExchangeName: \"amq.topic\"});\n\nAfter a connection is established the `'connect'` event is fired as it is\nwith any `net.Connection` instance. AMQP requires a 7-way handshake which\nmust be completed before any communication can begin. `net.Connection` does\nthe handshake automatically and emits the `'ready'` event when the handshaking\nis complete.\n\nFor backward compatability, two additional options are available. Older\nversions of this library placed the routingKey and deliveryTag for incoming\nmessages into the JSON payload received. This module was changed to\nleave inbound JSON payloads pristine.  Some applications may need the\nold behaviour. If the key 'routingKeyInPayload' is set to true in the\nconnection options, the messages resulting from a subscribe call will\ninclude a 'routingKey' key in the JSON payload.  If the key\n'devliryTagInPayload' is set to true in the connection options, the\ndeliveryTag of the incoming message will be placed in the JSON payload.\n\n\n### connection.publish(queueName, body)\n\nPublishes a message to the default exchange; if the defaultExchange is\nleft as `''`, this effectively publishes the message to the queue\nnamed.\n\n### connection.end()\n\n`amqp.Connection` is derived from `net.Stream` and has all the same methods.\nSo use `connection.end()` to terminate a connection gracefully.\n\n\n\n\n## Queue\n\nEvents: A queue will call the callback given to the `connection.queue()`\nmethod once it is usable. For example:\n\n    var q = connection.queue('my-queue', function (queue) {\n      puts('Queue ' + queue.name + ' is open');\n    });\n\nDeclaring a queue with an empty name will make the server generate a\nrandom name.\n\n### connection.queue(name, options, openCallback)\n\nReturns a reference to a queue. The options are\n\n- `passive`: boolean, default false.\n    If set, the server will not create the queue.  The client can use\n    this to check whether a queue exists without modifying the server\n    state.\n- `durable`: boolean, default false.\n    Durable queues remain active when a server restarts.\n    Non-durable queues (transient queues) are purged if/when a\n    server restarts.  Note that durable queues do not necessarily\n    hold persistent messages, although it does not make sense to\n    send persistent messages to a transient queue.\n- `exclusive`: boolean, default false.\n    Exclusive queues may only be consumed from by the current connection.\n    Setting the 'exclusive' flag always implies 'autoDelete'.\n- `autoDelete`: boolean, default true.\n    If set, the queue is deleted when all consumers have finished\n    using it. Last consumer can be cancelled either explicitly or because\n    its channel is closed. If there was no consumer ever on the queue, it\n    won't be deleted.\n\n### queue.subscribe([options,] listener)\n\nAn easy subscription command. It works like this\n\n    q.subscribe(function (message, headers, deliveryInfo) {\n      puts('Got a message with routing key ' + deliveryInfo.routingKey);\n    });\n\nIt will automatically acknowledge receipt of each message.\n\nThere are several options available.  Setting the options argument to\n`{ ack: true }` (which defaults to false) will make it so that the AMQP\nserver only delivers a single message at a time. When you want the next\nmessage, call `q.shift()`. When `ack` is false then you will receive\nmessages as fast as they come in. \n\nYou can also use the prefetchCount option to increase the window of how\nmany messages the server will send you before you need to ack (quality of service).\n'{ ack: true, prefetchCount: 1 }' is the default and will only send you one\nmessage before you ack. Setting prefetchCount to 0 will make that window unlimited.\n\nThe 'routingKeyInPayload' and 'deliveryKeyInPayload' options determine\nif the reception process will inject the routingKey and deliveryKey,\nrespectively, into the JSON payload received.  These default to unset\nthus adopting the parent connection's values (which default to false).\nSetting these to true provide backward compability for older\napplications.\n\nThis method will emit `'basicQosOk'` when ready.\n\n\n### queue.subscribeRaw([options,] listener)\n\nSubscribes to a queue. The `listener` argument should be a function which\nreceives a message. This is a low-level interface - the message that the\nlistener receives will be a stream of binary data. You probably want to use\n`subscribe` instead. For now this low-level interface is left undocumented.\nLook at the source code if you need to do this.\n\nThis method will emit `'basicConsumeOk'` when ready.\n\n### queue.unsubscribe(consumerTag)\n\nUnsubscribe from a queue, given the consumer tag. The consumer tag is\nsupplied to the *promise callback* of `Queue.subscribeRaw` or\n`Queue.subscribe`:\n\n    connection.queue('foo', function(queue) {\n      var ctag;\n      queue.subscribe(function(msg) {...})\n        .addCallback(function(ok) { ctag = ok.consumerTag; });\n      // ... and in some other callback\n      queue.unsubscribe(ctag);\n    });\n\nNote that `Queue.unsubscribe` will not requeue messages that have not\nbeen acknowledged. You need to close the queue or connection for that\nto happen. You may also receive messages after calling `unsubscribe`;\nyou will **not** receive messages from the queue after the unsubscribe\npromise callback has been invoked, however.\n\n### queue.shift()\n\nFor use with `subscribe({ack: true}, fn)`. Acknowledges the last\nmessage.\n\n\n### queue.bind([exchange,] routing)\n\nThis method binds a queue to an exchange.  Until a queue is\nbound it will not receive any messages, unless they are sent through\nthe unnamed exchange (see `defaultExchangeName` above).\n\nIf the `exchange` argument is left out `'amq.topic'` will be used.\n\nThis method will emit `'queueBindOk'` when ready.\n\n### queue.bind_headers([exchange,] routing)\n\nThis method binds a queue to an exchange.  Until a queue is\nbound it will not receive any messages.\n\nThis method is to be used on an \"headers\"-type exchange. The routing\nargument must contain the routing keys and the `x-match` value (`all` or `any`).\n\nIf the `exchange` argument is left out `'amq.headers'` will be used.\n\n### queue.destroy(options)\n\nDelete the queue. Without options, the queue will be deleted even if it has\npending messages or attached consumers. If +options.ifUnused+ is true, then\nthe queue will only be deleted if there are no consumers. If\n+options.ifEmpty+ is true, the queue will only be deleted if it has no\nmessages.\n\n\n\n\n## Exchange\n\nEvents: An exchange will call the callback given to the `connection.exchange()`\nmethod once it is usable. For example:\n\n    var exc = connection.exchange('my-exchange', function (exchange) {\n      puts('Exchange ' + exchange.name + ' is open');\n    });\n\n\n### exchange.on('open', callback)\n\nThe open event is emitted when the exchange is declared and ready to\nbe used. This interface is considered deprecated.\n\n\n### connection.exchange()\n### connection.exchange(name, options={}, openCallback)\n\nAn exchange can be created using `connection.exchange()`. The method returns\nan `amqp.Exchange` object.\n\nWithout any arguments, this method returns the default exchange.\nOtherwise a string, `name`, is given as the first argument and an `options`\nobject for the second. The options are\n\n- `type`: the type of exchange `'direct'`, `'fanout'`, or `'topic'` (default).\n- `passive`: boolean, default false.\n    If set, the server will not create the exchange.  The client can use\n    this to check whether an exchange exists without modifying the server\n    state.\n- `durable`: boolean, default false.\n    If set when creating a new exchange, the exchange will be marked as\n    durable.  Durable exchanges remain active when a server restarts.\n    Non-durable exchanges (transient exchanges) are purged if/when a\n    server restarts.\n- `autoDelete`: boolean, default true.\n    If set, the exchange is deleted when there are no longer queues\n    bound to it.\n\nAn exchange will emit the `'open'` event when it is finally declared.\n\n\n### exchange.publish(routingKey, message, options)\n\nPublishes a message to the exchange. The `routingKey` argument is a string\nwhich helps routing in `topic` and `direct` exchanges. The `message` can be\neither a Buffer or Object. A Buffer is used for sending raw bytes; an Object\nis converted to JSON.\n\n`options` is an object with any of the following\n\n- `mandatory`: boolean, default false.\n    This flag tells the server how to react if the message cannot be\n    routed to a queue.  If this flag is set, the server will return an\n    unroutable message with a Return method.  If this flag is false, the\n    server silently drops the message.\n- `immediate`: boolean, default false.\n    This flag tells the server how to react if the message cannot be\n    routed to a queue consumer immediately.  If this flag is set, the\n    server will return an undeliverable message with a Return method.\n    If this flag is false, the server will queue the message, but with\n    no guarantee that it will ever be consumed.\n- `contentType`: default `'application/octet-stream'`\n- `contentEncoding`: default null.\n- `headers`: default `{}`. Arbitrary application-specific message headers.\n- `deliveryMode`: Non-persistent (1) or persistent (2)\n- `priority`: The message priority, 0 to 9.\n- `replyTo`: Usually used to name a reply queue for a request message.\n\n### exchange.destroy(ifUnused = true)\n\nDeletes an exchange.\nIf the optional boolean second argument is set, the server will only\ndelete the exchange if it has no queue bindings. If the exchange has queue\nbindings the server does not delete it but raises a channel exception\ninstead.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsquaremo%2Fnode-amqp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsquaremo%2Fnode-amqp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsquaremo%2Fnode-amqp/lists"}