def should_raise_nc_when_sending(self): mystomp = Stomp('localhost', 99999) try: mystomp.send({"body": "Vandelay Industries"}) except stompy.NotConnectedError, err: assert True # Should raise not connected return
class Stomp(object): conn = None def __init__(self): if not config.no_effect: self.conn = DistStomp(config.stomp.server, config.stomp.port) self.conn.connect() def __del__(self): if self.conn: self.conn.disconnect() # Let the STOMP library catch up time.sleep(1) def send(self, queue_key, body): if config.no_effect: log.info("not queueing message. " + json.dumps(body)) return self.conn.send(self.create_message(queue_key, body)) def create_message(self, queue_key, body): msg = { 'destination': config.stomp.queues[queue_key], 'persistent': 'true', } msg.update(Stomp.source_meta()) if 'gateway' in body and 'gateway_txn_id' in body: msg['correlation-id'] = '{gw}-{id}'.format(gw=body['gateway'], id=body['gateway_txn_id']) msg.update({'body': json.dumps(body)}) return msg @staticmethod def source_meta(): return { 'source_name': os.path.basename(sys.argv[0]), # FIXME: the controlling script should pass its own source_type 'source_type': 'audit', 'source_run_id': os.getpid(), 'source_version': process.version_stamp.source_revision(), 'source_enqueued_time': time.time(), 'source_host': socket.gethostname(), }
class WhenProducingMessages(DingusTestCase(Stomp)): def setup(self): super(WhenProducingMessages, self).setup() self.host = 'localhost' self.port = 61613 self.stomp = Stomp(self.host, self.port) self.frame = self.stomp.frame self.sock = self.stomp.sock self.stomp.connected = True self.headers = {'destination': '/queue/nose_test', 'body': 'test'} def should_build_frame_and_send(self): self.stomp.send(self.headers) built_frame = self.frame.calls('build_frame', DontCare).one() built_frame_args = built_frame.args[0] send_args = built_frame[3] assert built_frame_args['command'] == 'SEND' assert self.frame.calls('send_frame', send_args.as_string())
obj['svn_url'] = url obj['repository'] = 'scratch' now = pacific.localize(now0) timestamp1 = now.strftime("%Y%m%d%H%M%S") timestamp2 = now.strftime("%a %b %d %Y %H:%M:%S") timestamp2 = timestamp2 + " GMT-%s (%s)" % (offset, tzname) obj['job_id'] = "%s_%s" % (pkgname_bare, timestamp1) obj['time'] = timestamp2 obj['client_id'] = "single_package_builder_autobuild:%s:%s" % (issue_id, pkgname) json = json.dumps(obj) #print(json) try: stomp = Stomp("broker.bioconductor.org", 61613) # optional connect keyword args "username" and "password" like so: # stomp.connect(username="******", password="******") stomp.connect() except: print("Cannot connect") raise this_frame = stomp.send({'destination': "/topic/buildjobs", 'body': json, 'persistent': 'true'}) print("Receipt: %s" % this_frame.headers.get('receipt-id')) sys.stdout.flush()