Quickstart Guide
This guide will take you through a basic setup of starting a Pubkeeper server, and using a single brewer (publisher) sending the byte-string data
and a single patron (subscriber) receiving data
and printing it out to the console.
Installation
First you will need to install the following pacakages:
pubkeeper.server.core
pubkeeper.client
pubkeeper.brew.zmq
pubkeeper.protocol.v1
pubkeeper.protocol.legacy
Server Setup
First, create a file pubkeeper.conf
in your directory with the following contents:
[pubkeeper_server]
;
; Networking
;
; Static server address, used when you have a specific address
;ip_address = x.x.x.x
; Port to run server on
;port = 9898
; Not used with above, will grab and announce the bound address on the interface
interface = lo0
; Heartbeat timer for connection to clients
;websocket_ping_interval = 10
; If provided, will enable SSL
;server_cert = /path/to/cert.pem
;server_key = /path/to/key.pem
[auth]
provider = pubkeeper.server.core.auth.internal.InternalAuthProvider
token = some-super-secret-key-that-clients-authenticate-with
Brewer Setup
Create a brewer.py
file with the contents:
from pubkeeper.client import PubkeeperClient
from pubkeeper.brewer import Brewer
from pubkeeper.brew.zmq.brew import ZMQBrew
import time
config = {
'host': 'localhost',
'port': 9898,
'secure': False
'token': 'your-pk-token',
'bridge_mode': False
}
client = PubkeeperClient(config)
zmq_brew = ZMQBrew()
zmq_brew.configure({})
client.add_brew(zmq_brew)
client.start()
brewer = client.add_brewer('test.topic.data')
try:
while True:
brewer.brew(b'data')
time.sleep(1)
except KeyboardInterrupt:
client.shutdown()
Patron Setup
Create a patron.py
file with the contents:
from pubkeeper.client import PubkeeperClient
from pubkeeper.patron import Patron
from pubkeeper.brew.zmq.brew import ZMQBrew
import time
config = {
'host': 'localhost',
'port': 9898,
'secure': False
'token': 'your-pk-token',
'bridge_mode': False
}
client = PubkeeperClient(config)
zmq_brew = ZMQBrew()
zmq_brew.configure({})
client.add_brew(zmq_brew)
client.start()
def on_message(data):
print("{}".format(data))
patron = client.add_patron('test.*.data', callback=on_message)
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
client.shutdown()
This patron adds the same brew for ZMQ, subscribes to any topic containing test.[anything].data
, and sends received data to a callback which prints to the console.
Putting It Together
Start the Pubkeeper server, in the same directory you made the pubkeeper.conf
run:
pk_server
In another window, start the brewer:
python3 brewer.py
In a final window, start the patron:
python3 patron.py
You should immediately begin to see the data that was sent out from the brewer and received by the patron printed out to the console.