Skip to content

Instantly share code, notes, and snippets.

@elialbert
Created April 19, 2012 17:33
Show Gist options
  • Save elialbert/2422485 to your computer and use it in GitHub Desktop.
Save elialbert/2422485 to your computer and use it in GitHub Desktop.
Working capability listener for python with xcom and avro
# a test listener for a new xcom capability
@csrf_exempt
def listener(request,message):
logging.info("INCOMING XCOM MESSAGE: %s"%message)
logging.info("INCOMING XCOM HEADERS: %s"%str(request.META))
logging.info("INCOMING XCOM REQUEST: %s"%request.POST.copy().__dict__)
logging.info("INCOMING XCOM REQUEST params: %s"%request.POST.copy())
logging.info("INCOMING RAW DATA: %s"%request.raw_post_data)
authorization = request.META.get('HTTP_AUTHORIZATION')
if authorization != settings.XCOM_RECEIVER_FABRIC_CREDENTIALS:
return HttpResponse("Incorrect authorization!",status=403)
params = request.raw_post_data
schema_header = request.META.get('HTTP_X_XC_SCHEMA_URI')
logging.info("schema header is %s"%schema_header)
resp = requests.get(schema_header)
logging.info("schema resp is %s"%resp.content)
schema_body = schema.parse(resp.content)
# this part is for parsing binary avro data
logging.info("schema body is %s"%schema_body)
reader = io.DatumReader(schema_body,schema_body)
read_io = StringIO(params)
decoder = io.BinaryDecoder(read_io)
result = reader.read(decoder)
logging.info("data result is %s"%result)
return HttpResponse("success")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment