@lskjs/rabbit-cli
TypeScript icon, indicating that this package has built-in type declarations

3.18.0 • Public • Published

LSK.js – rabbit-cli

@lskjs/rabbit-cli – CLI for quick post json's to RabbitMQ

LSK logo NPM version NPM downloads NPM Dependency count Have TypeScript types Have tree shaking NPM Package size Package size Ask us in Telegram


Table of contents

⌨️ Install

# yarn
yarn i @lskjs/rabbit-cli 

# npm
npm i @lskjs/rabbit-cli 

Global install

npm i -g @lskjs/rabbit-cli

Basic commands

Lskrabbit understands the following commands:

  • pub - publish messages to an exchange or queues.
  • pipe - pipe messages to an exchange or queues.

See the examples section for further information.

Broker URI specification

The specification of the RabbitMQ broker URI follows the AMQP URI specification as implemented by the go RabbitMQ client library.

Examples

  • amqp://guest:guest@localhost:5672/
  • amqps://guest:guest@my-broker.dev:5671/
  • amqps://guest:guest@my-broker.dev:5671/vhost

Note that according to RFC3986 it might be necessary to escape certain characters like e.g. ? (%3F) or # (%23) as otherwise parsing of the URI may fail with an error.

Format specification pub and pipe command

Format has the following effect on the output:

FORMAT Format on console Format of saved messages
raw Pretty-printed metadata + raw Message body Metadata as JSON-File + Body as-is
json Pretty-printed JSON Pretty-printed JSON

Environment variables

Use environment variables to specify standard values for variables.

Default RabbitMQ broker

The URI of the RabbitMQ broker can be set with the environment variable AMQP_URI. Example:

export AMQP_URI=amqp://guest:guest@localhost:5672/

Default RabbitMQ config

The default QUEUE, EXCHANGE, etc can be set using the environment variables. Example:

export AMQP_QUEUE=lsk_queue
export AMQP_EXCHANGE=lsk_exchange
export AMQP_KEY=lsk_key
export AMQP_PREFETCH=10
export AMQP_MAX_PRIORITY=10
echo "Hello" | lskrabbit pub

Publish messages

The pub command is used to publish messages to an exchange. The messages to be published are either read from json/txt file or stream. The general form of the pub command is:

cat [SOURCE] | lskrabbit pub 
             [--uri=URI]
             [--queue=QUEUE]
             [--exchange=EXCHANGE]
             [--key=KEY]
             [--prefetch=PREFETCH]
             [--concurrency=CONCORRENCY]
             [--extract=EXTRACT]
             [--parse=PARSE]

Command params

Key (short) Key Description
-u --uri URI RabbiqMQ
-q --queue Queue RabbitMq
-e --exchange Exchange
-k --key Routing key
-p --prefetch Prefetch
-c --concurrency Concurrency
-x --extract Extract callback
-r --parse str => json

Message routing is either specified with a routing key and the --key option. --extract options allows you to convert data to the desired format. Option is a callback-function. You can also parse the data using callback-function in --parse option.

JSON Message has many configurable parameters. Description in the table:

Message params

Key Description
_q queue
_e exchange
_k key
_p priority
_exp expiration
_pr persistent

Examples messages

tests/messages.json

{ "_id": 111, "_q": "lsk_queue" }
{ "_id": 222, "_q": "lsk_queue", "_p": 10 }
{ "_id": 333, "_q": "lsk_queue", "_exp": 60000 }
{ "_id": 444, "_q": "lsk_queue", "_p": 11 }
{ "_id": 555, "_q": "lsk_queue_2" }
{ "_id": 666, "_e": "lsk_exchange" }
{ "_id": 777, "_e": "lsk_exchange", "_k": "lsk_key" }
{ "_id": 888, "_e": "lsk_exchange", "_k": "lsk_key_2" }

tests/messages.txt

{ "test": 123 }
{ "test": 546 }

Examples command

  • echo "hello" | rabtap pub --exchange lsk_exchange - publish "hello" to exchange lsk_exchange

  • echo '{ "_id":"123" }' | lskrabbit pub - publish JSONEachRow

  • cat tests/messages.json | lskrabbit pub - publish messages from JSON file

  • cat tests/messages.json | docker run --rm -i lskjs/rabbit-cli pub - publish messages from JSON file with docker image

  • cat tests/messages.json | DEBUG=lsk lskrabbit pub - publish from JSON file with DEBUG

  • cat tests/messages.txt | lskrabbit pub --queue lsk_queue - publish messages to queue from txt file

  • cat tests/messages.json | lskrabbit pub -x "row => ({...row, test: row, _e: 'lsk_exchange' })" - publish messages with extract from JSON-each-ROW

  • cat tests/messages.txt | lskrabbit pub --parse "_id => ({ _id, _e: 'lsk_exchange' })" - publish messages with extract from txt file String-each-row

Publish messages from MongoDb

Install mongoexport

With brew:

brew install mongodb/brew/mongodb-database-tools

Or other MacOs, Linux, Windows.

How to usage

mongoexport [--uri=MONGO_URI] [--collection=MONGO_COLLECTION] | lskrabbit pub
            [--uri=URI]
            [--queue=QUEUE]
            [--exchange=EXCHANGE]
            [--key=KEY]
            [--prefetch=PREFETCH]
            [--concurrency=CONCORRENCY]
            [--extract=EXTRACT]
            [--parse=PARSE]

Examples command

  • mongoexport --uri=mongodb://localhost:27017/ --collection=lsk_test | lskrabbit pub --uri amqp://localhost --queue lsk_queue - publish messages from mongoDb collection

Publish messages from Clickhouse

Install clickhouse-client

Before you start, need to install clickhouse-client.

How to usage

clickhouse-client
            [--host=CLHOST]
            [--port=PORT]
            [--database=CLDB]
            [--password=CLPASSWORD]
            [--multiquery=MULTIQUERY] | lskrabbit pub
            [--uri=URI]
            [--queue=QUEUE]
            [--exchange=EXCHANGE]
            [--key=KEY]
            [--prefetch=PREFETCH]
            [--concurrency=CONCORRENCY]
            [--extract=EXTRACT]
            [--parse=PARSE]

Examples command

  • clickhouse-client -h localhost --port 9000 -d default --password qwerty --multiquery < clickhouse.sql | lskrabbit pub - publish messages from clickhouse

📖 License

This project is licensed under the MIT License - see the LICENSE file for details

👥 Contributors


Igor Suvorov

💻 🎨 🤔

👏 Contributing

  1. Fork it (https://github.com/yourname/yourproject/fork)
  2. Create your feature branch (git checkout -b features/fooBar)
  3. Commit your changes (git commit -am 'feat(image): Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request

📮 Any questions? Always welcome :)

Readme

Keywords

Package Sidebar

Install

npm i @lskjs/rabbit-cli

Weekly Downloads

3

Version

3.18.0

License

MIT

Unpacked Size

108 kB

Total Files

46

Last publish

Collaborators

  • lskjsru
  • maxxborer
  • isuvorov
  • yukioru
  • andru_xa
  • natavts
  • blacklightburn
  • ga2mer
  • kafkae
  • sophiyabezruk
  • vladik_deniska
  • finalgetname