Top

forestbus.cbor-test-send module

import json
import socket
import os, sys
sys.path.insert(0, os.path.abspath("."))
import cbor_rpc
import forest

sock = socket.socket()
sock.connect(("localhost", 5001))

client = cbor_rpc.Client (sock)

msgs = bytes(json.dumps ({"test_msg": "Python Hello World"}))
result = client.Call('RPCHandler.SendMessages', {'Topic': 'test', 'WaitForCommit': True, 'SentMessages': [msgs]})  # = > 3
print (result)

client.Close()

print ("Attempting client connection.")

client = forest.Client ("testcluster", ["localhost:5000","localhost:5001", "localhost:5002"])

try:
	result = client.GetMessages ("test-wrong", 1, 1, True)
	print (result)
except Exception, e:
	print ("Error during get: " + str (e))

try:
	result = client.GetMessages ("test", 1, 1, True)
	print (result)

	maxIndex = client.GetTopicMaxAvailableIndex("test")
	print ("Maximum index for test: " + str (maxIndex))

	ids = client.SendMessages("test", [msgs], True)
	print ("Resulting IDs: " + str (ids))

	ids = client.SendMessages("test", [msgs], True)
	print ("Resulting IDs: " + str (ids))


except Exception, e:
	print ("Error during get again: " + str (e))


print ("Requesting close")
client.Close()

print ("Close done")

Module variables

var e

var ids

var maxIndex

var msgs

var result