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 details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 2Python 3

File details

Details for the file slackmq-0.1.2.tar.gz.

File metadata

  • Download URL: slackmq-0.1.2.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.5.3

File hashes

Hashes for slackmq-0.1.2.tar.gz
Algorithm Hash digest
SHA256 df722fdf357a3464950eea9739aedb52055834d2234d1d99a6e94f948403022c
MD5 7341976339fe9e00f35c544336272ab1
BLAKE2b-256 176e31bf4133366d523aff6950460aa0673bd4820f904c4bec6d55aeeb427b0a

See more details on using hashes here.

File details

Details for the file slackmq-0.1.2-py2.py3-none-any.whl.

File metadata

  • Download URL: slackmq-0.1.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.5.3

File hashes

Hashes for slackmq-0.1.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 a48181bdfb558d54fd9448c1df5ac496f168daa561dfeab6b5764e7938d53cac
MD5 38a8649df8cf08638d7b49af461ae0c7
BLAKE2b-256 f62419c9214a3048064b0c16b23e26d18ca40f09451a4387c124e23557a4d3b4

See more details on using hashes here.

Supported by

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