1

I'm currently trying to build a system to send images to multiple remote servers in order to do some Open_CV and tesseract on pictures.

On one server it's okay because I rename my image into the folder before to send (first image sended is automatically named Image_0)

And then rename them again on reception, same order so the name is corresponding for the same image (Image_0 first sended and first received so named Image_0 in both local and remote) to make reading names easier when receiving results.

I receive then at the end of traitment a .txt file on local with the results of images (MRZ areas) like "Image_0 results XXXXXXXX<<<

My Problem --->

I want now to use multiple remote servers and use WORKQUEUE with rabbitMQ in order to do a basic workflow orchestration and reduce process time for my images samples.

How can I send the name of an image with that image in base64 to have corresponding names at the end in my .txt result file because my current method won(t work with multiple remote servers ?

Thanks for your help !

Here is how I send my images currently:

for file in natsorted(os.listdir()):
    end_name=file[-4]+ file[-3]+ file[-2]+ file[-1]
    if (end_name != ".txt"):

        try:
            with open(file, "rb") as image:
                message = base64.b64encode(image.read())

            channel.basic_publish(exchange='topic_logs', 
            routing_key=routing_key, body=message)
            print(f"{file} || sended on topic %r \n" % (routing_key))

        except IndexError:
            print("No image given ! ")
            sys.exit(1)

        os.rename(file,"Image_"+str(ComptNames)+".png")
        ComptNames=ComptNames+1
Momor
  • 23
  • 6

2 Answers2

3

Use JSON as the message content type. One element of this JSON object would be the filename, the other the Base64 encoded image.

{
  "filename": "foo.jpg",
  "bytes": "..."
}

The consumer would have to parse this JSON message body.

  • 1
    Thanks for your answer, I've never used JSON with Python, I'll try it now to see if it can help me with my problem and RabbitMQ in general ! – Momor Aug 14 '19 at 11:56
1

You can use AMQP message headers to send the filename with the message data. You use the pika.spec.BasicProperties class to send the header as in this example. The headers will be available on the receiving side, of course.


NOTE: the RabbitMQ team monitors the rabbitmq-users mailing list and only sometimes answers questions on StackOverflow.

Luke Bakken
  • 8,993
  • 2
  • 20
  • 33
  • Hi Luke, Thanks for your precious help, I unfortunately didn't know these options in rabbitMQ, I tried the option with JSON and it works very well for the moment but I'll keep this option in a corner of my head. I will check the documentation more often now, if you have a link to it, I would be grateful! – Momor Aug 14 '19 at 15:09