def __send_frame(self, command, headers={}, payload=''): """ Send a STOMP frame. \param command the frame command \param headers a map of headers (key-val pairs) \param payload the message payload """ if type(payload) == dict: headers["transformation"] = "jms-map-xml" payload = self.__convert_dict(payload) if payload: payload = encode(payload) if hasbyte(0, payload): headers.update({'content-length': len(payload)}) if self.__socket is not None: try: frame = [] if command is not None: frame.append(command + '\n') for key, val in headers.items(): frame.append('%s:%s\n' % (key, val)) frame.append('\n') if payload: frame.append(payload) if command is not None: # only send the terminator if we're sending a command (heartbeats have no term) frame.append(NULL) frame = pack(frame) self.__socket_semaphore.acquire() try: socksend(self.__socket, frame) log.debug("Sent frame: type=%s, headers=%r, body=%r" % (command, headers, payload)) finally: self.__socket_semaphore.release() except Exception: _, e, _ = sys.exc_info() log.error("Error sending frame: %s" % e) raise e else: raise exception.NotConnectedException()
def send(self, destination, body, content_type=None, headers={}, **keyword_headers): assert destination is not None, "'destination' is required" assert body is not None, "'body' is required" headers = utils.merge_headers([headers, keyword_headers]) headers[HDR_DESTINATION] = destination if content_type: headers[HDR_CONTENT_TYPE] = content_type body = encode(body) if HDR_CONTENT_LENGTH not in headers and hasbyte(0, body): headers[HDR_CONTENT_LENGTH] = len(body) self.__send_frame(CMD_SEND, headers, body)
def send(self, destination, body, content_type=None, headers={}, **keyword_headers): assert destination is not None, "'destination' is required" assert body is not None, "'body' is required" headers = utils.merge_headers([headers, keyword_headers]) headers[HDR_DESTINATION] = destination if content_type: headers[HDR_CONTENT_TYPE] = content_type body = encode(body) if HDR_CONTENT_LENGTH not in headers and hasbyte(0, body): headers[HDR_CONTENT_LENGTH] = len(body) self.send_frame(CMD_SEND, headers, body)
def __send_frame(self, command, headers={}, payload=''): """ Send a STOMP frame. \param command the frame command \param headers a map of headers (key-val pairs) \param payload the message payload """ if type(payload) == dict: headers["transformation"] = "jms-map-xml" payload = self.__convert_dict(payload) if payload: payload = encode(payload) if hasbyte(0, payload): headers.update({'content-length': len(payload)}) if self.__socket is not None: try: frame = [ ] if command is not None: frame.append(command + '\n') for key, val in headers.items(): frame.append('%s:%s\n' % (key, val)) frame.append('\n') if payload: frame.append(payload) if command is not None: # only send the terminator if we're sending a command (heartbeats have no term) frame.append(NULL) frame = pack(frame) self.__socket_semaphore.acquire() try: socksend(self.__socket, frame) log.debug("Sent frame: type=%s, headers=%r, body=%r" % (command, headers, payload)) finally: self.__socket_semaphore.release() except Exception: _, e, _ = sys.exc_info() log.error("Error sending frame: %s" % e) raise e else: raise exception.NotConnectedException()