30-04-2021



If you are using a Mac, RabbitMQ can be installed using Homebrew (opens new window) by typing brew install rabbitmq. This installs the management plug-in automatically. Once installed, type brew services start rabbitmq and accept the prompts to enable network ports. # To install RabbitMQ manually: Install Erlang using the installer (opens new. RabbitMQ installations running production workloads may need system limits and kernel parameters tuning in order to handle a decent number of concurrent connections and queues. The main setting that needs adjustment is the max number of open files, also known as ulimit -n. $ brew install rabbitmq After you’ve installed RabbitMQ with brew you need to add the following to your path to be able to start and stop the broker: add it to the start-up file for your shell (e.g.,.bashprofile or.profile ). Mac + RabbitMQ 安装.

  1. Brew Rabbitmq-server Command Not Found
  2. Brew Rabbitmq Config
  3. Brew Rabbitmq Stop
  4. Brew Rabbitmq Location
  5. Brew Rabbitmq-plugins
  6. Brew Install Rabbitmq
Latest version

Released:

A Chat Server based on AMQP using RabbitMQ message broker implementing AMQP, websocket, sockjs, sockjs-tornado, tornado, and amqp python client library, Pika

Project description

rabbitChat
A Chat-Server/Chat-System based on AMQP protocol(RabbitMQ Message Broker)
Documentation
--------------
**Link :** http://rabbitchat.readthedocs.io/en/latest/index.html
Details
--------
:Author: Anirban Roy Das
:Email: anirban.nick@gmail.com
:Copyright(C): 2016, Anirban Roy Das <anirban.nick@gmail.com>
Check ``rabbitChat/LICENSE`` file for full Copyright notice.
Overview
---------
rabbitChat is a very simple Chat Server which can be set up locally to chat in your LAN. It supports both **Public Chat** among all participants connected simultaneously at a particular time and also **Private Chat** betweent those individual participants.
It uses the `AMQP <https://www.amqp.org/>`_ protocol to implement the real time message passing system. **AMQP** is implemented in many languages and in many softwares, once of such is `RabbitMQ <https://www.rabbitmq.com/>`_ , which is a message broker implementing the `AMQP <https://www.amqp.org/>`_ protocol.
The connection is created using the `sockjs <https://github.com/sockjs/sockjs-client>`_ protocol. **SockJS** is implemented in many languages, primarily in Javascript to talk to the servers in real time, which tries to create a duplex bi-directional connection between the **Client(browser)** and the **Server**. Ther server should also implement the **sockjs** protocol. Thus using the `sockjs-tornado <https://github.com/MrJoes/sockjs-tornado>`_ library which exposes the **sockjs** protocol in `Tornado <http://www.tornadoweb.org/>`_ server.
It first tries to create a `Websocket <https://en.wikipedia.org/wiki/WebSocket>`_ connection, and if it fails then it fallbacks to other transport mechanisms, such as **Ajax**, **long polling**, etc. After the connection is established, the tornado server**(sockjs-tornado)** connects to **rabbitMQ** via AMQP protocol using the **AMQP Python Client Library**, `Pika <https://pypi.python.org/pypi/pika>`_.
Thus the connection is *web-browser* to *tornado* to *rabbitMQ* and vice versa.
Technical Specs
----------------
:sockjs-client: Advanced Websocket Javascript Client
:Tornado: Async Python Web Library + Web Server
:sockjs-tornado: SockJS websocket server implementation for Tornado
:AMQP: Advance Message Queuing Protocol used in Message Oriented Middleware
:pika: AMQP Python Client Library
:RabbitMQ: A Message Broker implementing AMQP
Features
---------
* Public chat
* Shows who joined and who left
* Shows number of people online
* Shows who is typing and who is not
* Join/Leave chat room features
Installation
------------
Prerequisites
~~~~~~~~~~~~~
1. python 2.7+
2. tornado
3. sockjs-tornado
4. sockjs-client
5. pika
6. rabbitMQ
Install
~~~~~~~
::
$ pip install rabbitChat
If above dependencies do not get installed by the above command, then use the below steps to install them one by one.
**Step 1 - Install pip**
Follow the below methods for installing pip. One of them may help you to install pip in your system.
* **Method 1 -** https://pip.pypa.io/en/stable/installing/
* **Method 2 -** http://ask.xmodulo.com/install-pip-linux.html
* **Method 3 -** If you installed python on MAC OS X via ``brew install python``, then **pip** is already installed along with python.
**Step 2 - Install tornado**
::
$ pip install tornado
**Step 3 - Install sockjs-tornado**
::
$ pip install sockjs-tornado
**Step 4 - Install pika**
::
$ pip install pika
**Step 5 - Install RabbitMQ**
* *For* ``Mac`` *Users*
1. Brew Install RabbitMQ
::
$ brew install rabbitmq
2. Configure RabbitMq, follow this `link <https://www.rabbitmq.com/install-homebrew.html>`_, this `one <https://www.rabbitmq.com/install-standalone-mac.html>`_ and `this <https://www.rabbitmq.com/configure.html>`_.
* *For* ``Ubuntu/Linux`` *Users*
1. Enable RabbitMQ application repository
::
$ echo 'deb http://www.rabbitmq.com/debian/ testing main' >> /etc/apt/sources.list
2. Add the verification key for the package
::
$ wget -o http://www.rabbitmq.com/rabbitmq-signing-key-public.asc | sudo apt-key add -
3. Update the sources with our new addition from above
::
$ apt-get update
4. And finally, download and install RabbitMQ
::
$ sudo apt-get install rabbitmq-server
5. Configure RabbitMQ, follow this `link <http://www.rabbitmq.com/install-debian.html>`_, this `one <https://www.rabbitmq.com/configure.html>`_ and `this <https://www.digitalocean.com/community/tutorials/how-to-install-and-manage-rabbitmq>`_.
Usage
-----
After having installed rabbitChat, just the run the following commands to use it:
* **RabbitMQ Server**
1. *For* ``Mac`` *Users*
::
# start normally
$ rabbitmq-server
# If you want to run in background
$ rabbitmq-server --detached
# start using brew rervices (doesn't work with tmux)
$ brew services rabbitmq start
2. *For* ``Ubuntu/LInux`` *Users*
::
# start normally
$ rabbitmq-server
# If you want to run in background
$ rabbitmq-server --detached
# To start using service
$ service rabbitmq-server start
# To stop using service
$ service rabbitmq-server stop
# To restart using service
$ service rabbitmq-server restart
# To check the status
$ service rabbitmq-server status
* **Start rabbitChat Server**
::
$ rabbitChat [options]
- **Options**
:--port: Port number where the chat server will start
- **Example**
::
$ rabbitChat --port=9191
* **Stop rabbitChat Server**
Click ``Ctrl+C`` to stop the server.
Todo
-----
1. Add Private Chat functionality.
2. Manage Presence Management, sent, delivered acknowledgements.
3. Message Persistence and delivery of messages to offline clinets.
4. Add Blog post regarding this topic.

Release historyRelease notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for rabbitChat, version 1.0.0
Filename, sizeFile typePython versionUpload dateHashes
Filename, size rabbitChat-1.0.0-py2-none-any.whl (35.5 kB) File type Wheel Python version py2 Upload dateHashes
Filename, size rabbitChat-1.0.0.tar.gz (1.2 MB) File type Source Python version None Upload dateHashes
CloseBrew rabbitmq logs

Hashes for rabbitChat-1.0.0-py2-none-any.whl

Hashes for rabbitChat-1.0.0-py2-none-any.whl
AlgorithmHash digest
SHA256c05cfe775f9998da2c332fb04d56b3c1d2805caabb5297c7606774c2b43d9da9
MD5ad015fefd877624e3ede6146af58834b
BLAKE2-2562f62ba89bbfcc0006b4e605f12365b0ae3b7d4541e000cbb34b4b6dad0fffadc
Close

Hashes for rabbitChat-1.0.0.tar.gz

Hashes for rabbitChat-1.0.0.tar.gz
AlgorithmHash digest
SHA25647d969ff536f1fb752c7ec0e7edaf445452a7f75eed7f28cabecb6de540886ed
MD5999d920fb03d9d4b8c5e0ac80d47b626
BLAKE2-256d2e114334ae23d1716227615ad68c85010236aaf5dfb2ac524cf1621a5c89d95

Celery is an asynchronous task queue based on distributed message passing. Task queues are used as a strategy todistribute the workload between threads/machines. In this tutorial I will explain how to install and setup Celery +RabbitMQ to execute asynchronous in a Django application.

To work with Celery, we also need to install RabbitMQ because Celery requires an external solution to send and receivemessages. Those solutions are called message brokers. Currently, Celery supports RabbitMQ, Redis, and Amazon SQSas message broker solutions.

Table of Contents
  • Installation

Why Should I Use Celery?

Brew Rabbitmq-server Command Not Found

Web applications works with request and response cycles. When the user access a certain URL of your application theWeb browser send a request to your server. Django receive this request and do something with it. Usually itinvolves executing queries in the database, processing data. While Django does his thing and process the request, theuser have to wait. When Django finalize its job processing the request, it sends back a response to the user whofinally will see something.

Ideally this request and response cycle should be fast, otherwise we would leave the user waiting for way too long.And even worse, our Web server can only serve a certain number of users at a time. So, if this process is slow, it canlimit the amount of pages your application can serve at a time.

For the most part we can work around this issue using cache, optimizing database queries, and so on. But there are somecases that theres no other option: the heavy work have to be done. A report page, export of big amount of data,video/image processing are a few examples of cases where you may want to use Celery.

We don’t use Celery through the whole project, but only for specific tasks that are time-consuming. The idea here is torespond to the user as quick as possible, and pass the time-consuming tasks to the queue so to be executed in thebackground, and always keep the server ready to respond to new requests.

Installation

The easiest way to install Celery is using pip:

Now we have to install RabbitMQ.

Installing RabbitMQ on Ubuntu 16.04

To install it on a newer Ubuntu version is very straightforward:

Then enable and start the RabbitMQ service:

Brew Rabbitmq Config

Check the status to make sure everything is running smooth:

Installing RabbitMQ on Mac

Homebrew is the most straightforward option:

The RabbitMQ scripts are installed into /usr/local/sbin. You can add it to your .bash_profile or .profile.

Then add it to the bottom of the file:

Restart the terminal to make sure the changes are in effect.

Now you can start the RabbitMQ server using the following command:

Installing RabbitMQ on Windows and Other OSs

Unfortunately I don’t have access to a Windows computer to try things out, but you can find theinstallation guide for Windows on RabbitMQ’s Website.

For other operating systems, check theDownloading and Installing RabbitMQ on their Website.

Celery Basic Setup

Brew Rabbitmq Stop

First, consider the following Django project named mysite with an app named core:

Add the CELERY_BROKER_URL configuration to the settings.py file:

settings.py

Rabbitmq

Alongside with the settings.py and urls.py files, let’s create a new file named celery.py.

celery.py

Now edit the __init__.py file in the project root:

__init__.py

This will make sure our Celery app is important every time Django starts.

Creating Our First Celery Task

We can create a file named tasks.py inside a Django app and put all our Celery tasks into this file. The Celery appwe created in the project root will collect all tasks defined across all Django apps listed in the INSTALLED_APPSconfiguration.

Just for testing purpose, let’s create a Celery task that generates a number of random User accounts.

core/tasks.py

The important bits here are:

Then I defined a form and a view to process my Celery task:

forms.py

Brew

This form expects a positive integer field between 50 and 500. It looks like this:

Then my view:

views.py

The important bit is here:

Instead of calling the create_random_user_accounts directly, I’m calling create_random_user_accounts.delay(). Thisway we are instructing Celery to execute this function in the background.

Then Django keep processing my view GenerateRandomUserView and returns smoothly to the user.

But before you try it, check the next section to learn how to start the Celery worker process.

Starting The Worker Process

Open a new terminal tab, and run the following command:

Change mysite to the name of your project. The result is something like this:

Now we can test it. I submitted 500 in my form to create 500 random users.

The response is immediate:

Meanwhile, checking the Celery Worker Process:

Then after a few seconds, if we refresh the page, the users are there:

If we check the Celery Worker Process again, we can see it completed the execution:

Managing The Worker Process in Production with Supervisord

If you are deploying your application to a VPS like DigitalOceanyou will want to run the worker process in the background. In my tutorials I like to use Supervisord to manage theGunicorn workers, so it’s usually a nice fit with Celery.

First install it (on Ubuntu):

Then create a file named mysite-celery.conf in the folder: /etc/supervisor/conf.d/mysite-celery.conf:

In the example below, I’m considering my Django project is inside a virtual environment. The path to my virtualenvironment is /home/mysite/.

Brew Rabbitmq Location

Now reread the configuration and add the new process:

If you are not familiar with deploying Django to a production server and working with Supervisord, maybe this partwill make more sense if you check this post from the blog:How to Deploy a Django Application to Digital Ocean.

Further Reading

Brew Rabbitmq-plugins

Those are the basic steps. I hope this helped you to get started with Celery. I will leave here a few useful referencesto keep learning about Celery:

Brew Install Rabbitmq

And as usual, the code examples used in this tutorial is available on GitHub:

Referral Link

If you want to try this setup in a Ubuntu cloud server, you can use this referral link to get a$10 free credit from Digital Ocean.