You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 line
1.7KB

  1. from kafka import KafkaProducer, KafkaConsumer
  2. from kafka.errors import kafka_errors
  3. import traceback
  4. import json,time,random,string
  5. import utilsK
  6. from utilsK.modelEval import onlineModelProcess
  7. import multiprocessing
  8. from multiprocessing import Process,Queue
  9. def consumer_demo(par):
  10. consumer = KafkaConsumer(
  11. par['topic'],
  12. bootstrap_servers=par['server'],
  13. group_id=par['group_id'],
  14. auto_offset_reset='latest',
  15. enable_auto_commit=False
  16. )
  17. itest = 0
  18. '''
  19. for message in consumer:
  20. itest+=1
  21. if itest>1:break;
  22. print("receive value: {}, partition:{} offset:{}".format(
  23. json.loads(message.value.decode()), message.partition,message.offset
  24. )
  25. )
  26. consumer.commit()
  27. '''
  28. dataPar ={
  29. 'imgData':'',
  30. 'imgName':'testW',
  31. 'streamName':'THSA_HD5M'
  32. }
  33. dataPar['inSource'] = 'http://images.5gai.taauav.com/video/8bc32984dd893930dabb2856eb92b4d1.mp4';dataPar['outSource'] = None
  34. process_uid=''.join(random.sample(string.ascii_letters + string.digits, 16))
  35. parent_conn, child_conn = multiprocessing.Pipe();
  36. dataPar['callback']=child_conn
  37. gpuProcess=Process(target=onlineModelProcess,name='process:%s'%( process_uid ),args=(dataPar,))
  38. gpuProcess.start()
  39. child_return = parent_conn.recv()
  40. returnData={'bboxes': 9999};
  41. returnData['gpu']=str(child_return)
  42. returnData['pid']=gpuProcess.pid
  43. returnData['pidName']=gpuProcess.name
  44. print( '#####consumer main:',returnData )
  45. if __name__=='__main__':
  46. par={};
  47. par['server']='212.129.223.66:9092';par['topic']='thsw';par['group_id']='test';
  48. consumer_demo(par)