示例#1
0
import sqlite3

from stompclient import PublishSubscribeClient

logging.basicConfig(level=logging.INFO)



def frame_received(frame):
  mid = frame.headers["message-id"]
  logging.info(mid)
  body = frame.body
  db = sqlite3.connect("stomp-records.sqlite")
  db.execute("INSERT INTO input_kills (timestamp, messageid, json) VALUES (datetime('now'), ?, ?)", (mid, body))
  db.commit()
  db.close()
  logging.info("Inserted")

logging.info("Starting")
client = PublishSubscribeClient('eve-kill.net', 61613)
listener = threading.Thread(target=client.listen_forever)
listener.start()

# For our example, we want to wait until the server is actually listening
client.listening_event.wait()

client.connect('guest', 'guest')
client.subscribe("/topic/kills", frame_received)
while True:
  time.sleep(200)
示例#2
0
"""
An example demonstrating running stompclient in subscribe-only mode.

stompclient can be used without a separate listener thread if you only want to 
subscribe to incoming messages (and don't need to get fancy in how you handle
the received frames).
"""
import logging
import pickle

logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
from stompclient import PublishSubscribeClient

def frame_received(frame):
    # Do something with the frame!
    payload = pickle.loads(frame.body)
    logger.info("Received data: {0!r}".format(payload))

client = PublishSubscribeClient('127.0.0.1', 61613)
client.connect()
client.subscribe("/queue/example", frame_received)
client.listen_forever()