new AMQPClient(policyopt, policyOverridesopt)
AMQPClient is the top-level class for interacting with node-amqp10. Instantiate this class, connect, and then send/receive
as needed and behind the scenes it will do the appropriate work to setup and teardown connections, sessions, and links and manage flow.
The code does its best to avoid exposing AMQP-specific types and attempts to convert them where possible, but on the off-chance you
need to speak AMQP-specific (e.g. to set a filter to a described-type), you can use node-amqp-encoder and the
translator adapter to convert it to our internal types. See simple_eventhub_test.js for an example.
Configuring AMQPClient is done through fa Policy class. By default, DefaultPolicy will be used - it assumes AMQP defaults wherever
possible, and for values with no spec-defined defaults it tries to assume something reasonable (e.g. timeout, max message size).
To define a new policy, you can merge your values into an existing one by calling AMQPClient.policies.merge(yourPolicy, existingPolicy).
This does a deep-merge, allowing you to only replace values you need. For instance, if you wanted the default sender settle policy to be auto-settle instead of mixed,
you could just use
var AMQP = require('amqp10'); var client = new AMQP.Client(AMQP.Policy.merge({ senderLink: { attach: { sndSettleMode: AMQP.Constants.senderSettleMode.settled } } });
Obviously, setting some of these options requires some in-depth knowledge of AMQP, so I've tried to define specific policies where I can.
For instance, for Azure EventHub connections, you can use the pre-build EventHubPolicy.
Also, within the policy, see the encoder and decoder defined in the send/receive policies. These define what to do with the message
sent/received, and by default do a simple pass-through, leaving the encoding to/decoding from AMQP-specific types up to the library which
does a best-effort job. See EventHubPolicy for a more complicated example, turning objects into UTF8-encoded buffers of JSON-strings.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
policy |
Policy |
<optional> |
Policy to use for connection, sessions, links, etc. Defaults to DefaultPolicy. |
policyOverrides |
Obeject |
<optional> |
Additional overrides for the provided policy |
Fires:
Extends
- EventEmitter
Methods
connect(url, policyOverridesopt) → {Promise}
Connects to a given AMQP server endpoint. Sets the default queue, so e.g.
amqp://my-activemq-host/my-queue-name would set the default queue to
my-queue-name for future send/receive calls.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
url |
string | URI to connect to - right now only supports |
|
policyOverrides |
object |
<optional> |
Policy overrides used for creating this connection |
Returns:
- Type
- Promise
createReceiver(address, policyOverridesopt) → {Promise.<ReceiverLink>}
Creates a receiver link for the given address, with optional link policy. The
promise returned resolves to a link that is an EventEmitter, which can be
used to listen for 'message' events.
Parameters:
Name | Type | Attributes | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
address |
string | An address to connect this link to. If not provided will use default queue from connection uri. |
|||||||||
policyOverrides |
object |
<optional> |
Policy overrides used for creating this receiver link Properties
|
Returns:
- Type
- Promise.<ReceiverLink>
createReceiverStream(address, policyOverridesopt) → {Promise.<ReceiverStream>}
Creates a receiver link wrapped as a Readable stream
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
address |
string | Address used for link creation |
|
policyOverrides |
object |
<optional> |
Policy overrides used for creating the receiver link |
Returns:
- Type
- Promise.<ReceiverStream>
createSender(address, policyOverridesopt) → {Promise.<SenderLink>}
Creates a sender link for the given address, with optional link policy
Parameters:
Name | Type | Attributes | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
address |
string | An address to connect this link to. If not provided will use default queue from connection uri. |
|||||||||
policyOverrides |
object |
<optional> |
Policy overrides used for creating this sender link Properties
|
Returns:
- Type
- Promise.<SenderLink>
createSenderStream(address, policyOverridesopt) → {Promise.<SenderStream>}
Creates a sender link wrapped as a Writable stream
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
address |
string | Address used for link creation |
|
policyOverrides |
object |
<optional> |
Policy overrides used for creating this sender link |
Returns:
- Type
- Promise.<SenderStream>
disconnect() → {Promise}
Disconnect tears down any existing connection with appropriate Close
performatives and TCP socket teardowns.
Returns:
- Type
- Promise
Events
client:errorReceived
Error received events
Type:
- object
Properties:
Name | Type | Description |
---|---|---|
the |
object | error received |
connection:closed
Connection closed event.
connection:opened
Connection opened event.