0

I'm using pika in Python3 to send CSV files from one node to another and everything is fine here. The only thing I need here is to get the transferred file name in the receiving node (e.g: filename-2017-01-01.csv)

Are there any ways to do this?

This is the processing part while getting the file.

def callback(ch, method, properties, body):
    ch.basic_ack(delivery_tag=method.delivery_tag)
    with open('test.csv', 'wb') as write_csv:
        write_csv.write(body)
Narbeh
  • 28
  • 6

2 Answers2

2

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


Instead of storing the file name with the message, you can use this method to add a custom header with the file name.

Luke Bakken
  • 8,993
  • 2
  • 20
  • 33
0

I came up with this idea, for those who want to include the file name with the message:

I've concatenated the file name with the message. After sending the message, I did split on the message:

with open(file, 'rb') as csv_file:
    return file + csv_file.read().decode()

On the other side:

file_name = body.decode().split('.csv')[0]
message = body.decode().split('.csv')[1]
with open('{}.csv'.format(file_name), 'w') as write_csv:
    write_csv.write(message)
Narbeh
  • 28
  • 6