def connected(self, msg): """Once I've connected I want to subscribe to my the message queue. """ super(MyStomp, self).connected(msg) self.log.info("receiverId <%s> connected: session %s" % (self.receiverId, msg['headers']['session'])) f = stomper.Frame() f.unpack(stomper.subscribe(DESTINATION)) return f.pack()
def subscribe(self, handler, destination, headers=None, ack="client", receipt=None): # Setting receipt to none here because we know it will be fired when we send it now # unless something goes bad now..but what are the chances of that? self.factory._subscriptions.append( {"handler": handler, "destination": destination, "headers": headers, "ack": ack, "receipt": None} ) if receipt: receiptId = receiptId = "subscribe-" + global_state.make_ref() headers = _updateOrCreateDict(headers, {"receipt": receiptId}) self.receipts[receiptId] = receipt self.factory.mqClient.sendMessage(stomper.subscribe(destination, ack=ack, headers=headers))
def __init__(self, factory): self.factory = factory self.receipts = {} for subscription in self.factory._subscriptions: if subscription["receipt"]: receiptId = "subscribe-" + global_state.make_ref() self.receipts[receiptId] = subscription["receipt"] headers = _updateOrCreateDict(subscription["headers"], {"receipt": receiptId}) # We only want to call this the first time it happens, that way reconnects # are invisible to the user subscription["receipt"] = None else: headers = subscription["headers"] self.factory.mqClient.sendMessage( stomper.subscribe(subscription["destination"], ack=subscription["ack"], headers=headers) ) for send in self.factory._sends: self.send(send["destination"], send["body"], send["headers"], send["receipt"]) # Once we have sent these remove them self.factory._sends = []