Chapter 4. Examples
This chapter demonstrates the use of AMQ JavaScript through example programs.
See the Rhea examples for more sample programs. Note that some of the sample programs there require the minimist package in order to parse command-line options.
4.1. Sending messages Copy linkLink copied to clipboard!
This client program connects to a server using <connection-url>
, creates a sender for target <address>
, sends a message containing <message-body>
, closes the connection, and exits.
Example: Sending messages
Running the example
To run the example program, copy it to a local file and invoke it using the node
command.
node send.js amqp://localhost queue1 hello
$ node send.js amqp://localhost queue1 hello
4.2. Receiving messages Copy linkLink copied to clipboard!
This client program connects to a server using <connection-url>
, creates a receiver for source <address>
, and receives messages until it is terminated or it reaches <count>
messages.
Example: Receiving messages
Running the example
To run the example program, copy it to a local file and invoke it using the python
command.
node receive.js amqp://localhost queue1
$ node receive.js amqp://localhost queue1