npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@lskjs/rabbit-cli

v3.18.0

Published

CLI for quick post json's to RabbitMQ

Downloads

51

Readme

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

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

👏 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 :)