Skip to main content

A Slack Message Queue system

Project description

SlackMQ

Slack can do the heavy lifting of a simple Message Queue. When a message is received, it is "locked" while being processed. This keeps other worker bots from processing the message simultaneously.

SlackMQ is suited to high latency message queuing applications due to rate limiting. For a minimalist architecture, leverage the power of SlackMQ and a Slack bot becomes highly available out of the box.

To install:

pip install slackmq

The Slack API allows pins to be added once per message per channel. Also, reactions and stars can be added to a message once per bot. For example, a person or bot cannot pin a message that has already been pinned. A user or bot cannot give a post a thumbs up twice. In the UI, if you try, the action is revoked. In the API, an exception is thrown.

SlackMQ workflow

Slack can be made to behave like a basic Message Queuing system by using pins to acknowledge (lock) and unacknowledge a message, as demonstrated in the diagram above. Using pins is ideal as this allows "unlimited" bot workers. The Slack RTM API also allows a bot to connect multiple times. With this account concurrency, this method limits the bot to 16 concurrent workers. You may find using a combination of pins, stars and reactions more reliable for low latency messages.

To use SlackMQ, wrap the post acknowledgement around a bot action. Below is an example of how a bot (using the slackbot library) uses SlackMQ to pull from the "queue", i.e, the channel.

from slackmq import slackmq
from slackbot.bot import listen_to
import socket

API_TOKEN = 'SLACK-BOT-API-TOKEN'


@listen_to('hello')
def helloworld(message):
    post = slackmq(API_TOKEN,
                   message.body['channel'], 
                   message.body['ts'])
    if post.ack():
        message.send('Hello from {}.'.format(socket.gethostname()))
        post.unack()

Implementation Examples

Troupe, which is a group of Slack bots working together to control and operate a smart home implements SlackMQ.

Another implementation of SlackMQ is to perform DevOps manoeuvres, such as Remote Management, Continuous Delivery, Canary Deployments and Rolling Updates. In the Troupe example, a Federation of Slack bots can self-update with zero downtime using the SlackMQ library. Watch The Travelling DevOps Troupe in action:

The Travelling DevOps Troupe

Project details


Download files

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

Source Distribution

slackmq-0.1.2.tar.gz (3.1 kB view hashes)

Uploaded Source

Built Distribution

slackmq-0.1.2-py2.py3-none-any.whl (3.8 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page