我有测试环境:[REST API]-> [RabbitMQ]并尝试将文件(包含多个部分)发送到REST API并直接从RabbitMQ读取:
* bytes expectedPayload = read('flask.png')
And multipart file file = { read: 'flask.png', contentType: 'application/json' }
And multipart field message = { messageFlowName: 'TestMSGFlow', moduleInstanceId: 5 }
When method POST
Then status 200
...
* bytes receivedPayload = amqpConnection.getMessagePayload('test.rabbitmq.queue', 'testChannel')
And match receivedPayload == read('flask.png')
amqpConnection.getMessagePayload方法:
public byte[] getMessagePayload(String queueName, Channel channel) {
byte[] message = null;
try {
GetResponse response = channel.basicGet(queueName, true);
if (response == null) {
System.out.println("DEBUG: No message found.");
} else {
AMQP.BasicProperties props = response.getProps();
return response.getBody();
}
} catch (IOException e) {
e.printStackTrace();
}
return message;
}
我得到结果:
actual: [B@64b70919, expected: [B@4e31c3ec, reason: actual and expected byte-arrays are not equal
我尝试使用* .json代替* .png(作为测试文件),并且效果很好。如何使其也与* .png兼容?
答案 0 :(得分:1)
它应该工作,所以看起来您在例程中从通道/消息中提取字节数组时出错。
也许涉及一些编码/解码? https://stackoverflow.com/a/47469363/143475
您可以做一个简单的测试:
* bytes temp = read('flask.png')
* match temp == read('flask.png')