def handle_event(self, config, event, conn_name): log.debug("Handling event: %s" % (event, )) # To avoid circular import. from go.vumitools.routing import RoutingMetadata endpoint = RoutingMetadata(event).next_router_endpoint() if endpoint is not None: self.publish_event(event, endpoint=endpoint)
def _add_go_routing_metadata(self, msg, hops, outbound_hops): rmeta = RoutingMetadata(msg) if hops is not None: rmeta.set_hops(hops) if outbound_hops is not None: rmeta.set_outbound_hops(outbound_hops)
def with_md(self, msg, user_account=None, conv=None, router=None, endpoint=None, tag=None, hops=None, outbound_hops_from=None, is_paid=False, is_reply_to_unroutable=False): msg.payload.setdefault('helper_metadata', {}) md = MessageMetadataHelper(self.vumi_helper.get_vumi_api(), msg) if user_account is not None: md.set_user_account(user_account) if conv is not None: conv_type, conv_key = conv md.set_conversation_info(conv_type, conv_key) md.set_user_account(self.user_account_key) if router is not None: router_type, router_key = router md.set_router_info(router_type, router_key) md.set_user_account(self.user_account_key) if endpoint is None: endpoint = msg.get_routing_endpoint() msg.set_routing_endpoint(endpoint) if tag is not None: md.set_tag(tag) if is_paid: md.set_paid() if hops is not None: rmeta = RoutingMetadata(msg) for src, dst in zip(hops[:-1], hops[1:]): rmeta.push_hop(src, dst) if outbound_hops_from is not None: rmeta = RoutingMetadata(msg) outbound_rmeta = RoutingMetadata(outbound_hops_from) rmeta.set_outbound_hops(outbound_rmeta.get_hops()) if is_reply_to_unroutable: rmeta = RoutingMetadata(msg) rmeta.set_unroutable_reply() return msg
def set_event_hops(self, event, outbound_hops, num_inbound_hops=1): rmeta = RoutingMetadata(event) rmeta.set_outbound_hops(outbound_hops) rev_hops = reversed(outbound_hops[-num_inbound_hops:]) for outbound_src, outbound_dst in rev_hops: rmeta.push_hop(outbound_dst, outbound_src)